diff --git a/index.js b/index.js index 83d99f47065c057fc52337474cc799d10361de02..8078644acd74477f03f4c4a6f158eb5292343705 100755 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const { spawnSync, spawn } = require('child_process') +const { spawn } = require('child_process') const config = require('./sitegin/config') function runBabel({ onExit, opts = [] }) { @@ -13,13 +13,23 @@ function runBabel({ onExit, opts = [] }) { function runBabelWatch() { runBabel({ - onExit: () => { - setTimeout(() => runBabelWatch(), 500) - }, + onExit: () => setTimeout(runBabelWatch(), 500), opts: ['--skip-initial-build', '--watch'], }) } +function runNodemon({ onExit }) { + const babel = spawn( + './node_modules/.bin/nodemon', + ['--ignore', 'build-debug', 'sitegin/index.js'], + { stdio: 'inherit', cwd: __dirname }, + ) + if (onExit) babel.on('exit', onExit) +} +function runNodemonWatch() { + runNodemon({ onExit: () => setTimeout(runNodemonWatch, 500) }) +} + ;(async () => { const opts = await config() await new Promise(res => @@ -28,17 +38,7 @@ function runBabelWatch() { const watch = !opts.config.options.nowatch if (watch) { runBabelWatch() - spawnSync( - process.argv[0], - [ - './node_modules/.bin/nodemon', - '--ignore', - 'build-debug', - 'sitegin/index.js', - ...process.argv.slice(2), - ], - { stdio: ['inherit', 'inherit', 'inherit'] }, - ) + runNodemonWatch() } else { require('./sitegin/index.js') }