Created
January 23, 2019 11:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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