const gulp = require('gulp'); const log = require('gulplog'); const { spawn } = require('child_process'); const package = require('./package.json'); gulp.task('dev', (cb) => { log.info('Running in development mode'); /** @type {import('child_process').ChildProcessWithoutNullStreams} */ let node = null; async function spawnNode(cb){ log.info('Spawning node'); if (node !== null) { node.kill(9); console.log('----- END PROCESS LOG -----') // grace period await new Promise(r => {setTimeout(r, 100)}); } log.info(`Command: \x1b[35mnode "${package.main}"`); console.log('----- BEGIN PROCESS LOG -----'); node = spawn('node', [ package.main ], { stdio: 'inherit' }); if (typeof cb == 'function') cb(); } gulp.watch('**', { events: 'all' }, spawnNode); spawnNode(); // cb(); })