init: gulp dev
This commit is contained in:
parent
f3044eb363
commit
018d4099e9
|
@ -0,0 +1,32 @@
|
||||||
|
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();
|
||||||
|
})
|
1
index.js
1
index.js
|
@ -9,7 +9,6 @@ fastify.register(require('@fastify/static'), {
|
||||||
prefix: '/'
|
prefix: '/'
|
||||||
});
|
});
|
||||||
|
|
||||||
// fastify.get('')
|
|
||||||
fastify.listen({ port: process.env.APP_PORT ?? 8000 }, (err, address) => {
|
fastify.listen({ port: process.env.APP_PORT ?? 8000 }, (err, address) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`Listening on ${address}`);
|
console.log(`Listening on ${address}`);
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/static": "^6.10.2",
|
"@fastify/static": "^6.10.2",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"fastify": "^4.18.0"
|
"fastify": "^4.18.0",
|
||||||
|
"gulp": "^4.0.2",
|
||||||
|
"sharp": "^0.32.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node index.js"
|
"dev": "gulp dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue