From 98b1d7e693d0cb32a659af65415430afd520f435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isabella=20Sko=C5=99epov=C3=A1?= <isabella@skorepova.info> Date: Sat, 11 Jan 2020 14:37:44 +0100 Subject: [PATCH] Do not block --- index.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 83d99f47..8078644a 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') } -- GitLab