Reorganisation de tout le systéme de build + debuggage os loader au autre scripts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//@ts-check
|
||||
const { exec, fork } = require('child_process');
|
||||
const { exec, fork, spawn } = require('child_process');
|
||||
/**
|
||||
* @param {string} path
|
||||
* @deprecated
|
||||
@@ -20,4 +20,33 @@ async function fHook(path) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { hookTo, fHook }
|
||||
/**
|
||||
* @param { string } cmd
|
||||
* @param { import('child_process').SpawnOptionsWithoutStdio } [option]
|
||||
*/
|
||||
async function spawnAndWait(cmd, option) {
|
||||
const child = spawn(cmd, option)
|
||||
|
||||
child.stdout.pipe(process.stdout)
|
||||
child.stderr.pipe(process.stderr)
|
||||
process.stdin.pipe(child.stdin)
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
child.on('exit', () => {
|
||||
res()
|
||||
})
|
||||
})
|
||||
process.stdin.unpipe(child.stdin)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } path
|
||||
* @param { string[] } [args]
|
||||
* @param { import('child_process').SpawnOptionsWithoutStdio } [options]
|
||||
*/
|
||||
async function startjs(path, args = [], options = {}) {
|
||||
const arguments = args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')
|
||||
return spawnAndWait(`/usr/local/bin/node ${path} ${arguments}`, options)
|
||||
}
|
||||
|
||||
module.exports = { hookTo, fHook, spawnAndWait, startjs }
|
||||
Reference in New Issue
Block a user