Skip to content

Instantly share code, notes, and snippets.

@smucode
Created January 23, 2019 11:18
Show Gist options
  • Select an option

  • Save smucode/41b4e0e80404f0422d48023c8ab78a09 to your computer and use it in GitHub Desktop.

Select an option

Save smucode/41b4e0e80404f0422d48023c8ab78a09 to your computer and use it in GitHub Desktop.
Script that watches the console for elm crashes, and will delete elm-stuff and trigger a recompile by touching Main.elm
const pathToElmStuff = './packages/elm/elm-stuff'
const pathToMain = './packages/elm/src/elm/Main.elm'
const npmCmdToStartDevServer = 'start:frontend'
const { spawn, execSync } = require('child_process')
const proc = spawn('npm', ['run', npmCmdToStartDevServer])
const log = msg => {
const boom = Array.apply(null, { length: 5 })
.map(() => '💥')
.join('')
console.log('\n\n' + `${boom} ${msg} ${boom}` + '\n\n')
}
const rimraf = require('rimraf')
const cb = data => {
const str = data.toString()
console.log(data.toString())
if (
str.indexOf('elm: not enough bytes') !== -1 ||
str.indexOf('CORRUPT BINARY') !== -1 ||
str.indexOf('given key is not an element in the map') !== -1
) {
log('elm crashed! nuking elm-stuff')
rimraf(pathToElmStuff, () => {
execSync(`sleep 2 && touch ${pathToMain}`)
log('triggering recompile')
})
}
}
proc.stdout.on('data', cb)
proc.stderr.on('data', cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment