Reorganisation de tout le systéme de build + debuggage os loader au autre scripts

This commit is contained in:
Marc
2022-02-26 19:23:34 +01:00
parent fc41d4bec0
commit 24c03e8090
25 changed files with 188 additions and 107 deletions
+31 -2
View File
@@ -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 }