diff --git a/bin/create-elm-app-cli.js b/bin/create-elm-app-cli.js old mode 100644 new mode 100755 diff --git a/bin/global-cli.js b/bin/global-cli.js old mode 100644 new mode 100755 index 214cdbcf..c0150a09 --- a/bin/global-cli.js +++ b/bin/global-cli.js @@ -8,11 +8,12 @@ const executablePaths = require('elm/platform').executablePaths; const version = require('../package.json').version; const elmPlatformVersion = require('../node_modules/elm/package.json').version; const paths = require('../config/paths'); +const chokidar = require('chokidar'); function help (version) { console.log('\nUsage: elm-app \n'); console.log('where is one of:'); - console.log(' create, build, start, package, reactor, make, repl\n'); + console.log(' create, build, start, package, reactor, make, repl, test\n'); console.log('\nElm ' + elmPlatformVersion + '\n'); console.log('create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')); } @@ -24,6 +25,14 @@ if (commands.length === 0) { var script = commands[ 0 ]; +function runTests() { + spawn.sync( + path.resolve(__dirname, '..', 'node_modules/elm-test/bin/elm-test'), + [ '--compiler', path.normalize(executablePaths['elm-make']) ], + { stdio: 'inherit' } + ); +} + switch (script) { case 'create': spawn.sync( @@ -57,11 +66,23 @@ switch (script) { break; case 'test': - spawn.sync( - path.resolve(__dirname, '..', 'node_modules/elm-test/bin/elm-test'), - [ '--compiler', path.normalize(executablePaths['elm-make']) ], - { stdio: 'inherit' } - ); + if (argv.w === true || argv.watch === true) { + const watcher = chokidar.watch(argv.watchGlob || '**/*.elm', { + ignored: /elm-stuff/, + awaitWriteFinish: { + stabilityThreshold: 150, + } + }); + + console.log('Watching your files for changes before running any tests.'); + + watcher.on('change', function(path) { + console.log('File', path, 'changed, rerunning tests.'); + runTests(); + }); + } else { + runTests(); + } break; default: diff --git a/package.json b/package.json index 11e7f279..d83f5bb4 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "autoprefixer": "^6.5.2", "bluebird": "^3.4.6", "chalk": "^1.1.3", + "chokidar": "1.6.1", "clean-webpack-plugin": "^0.1.14", "cli-table": "0.3.1", "cross-spawn": "^5.0.1",