forked from tsoding/multiplayer-game-prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
29 lines (27 loc) · 1.09 KB
/
serve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// @ts-check
// Do not run this file directly. Run it via `npm run watch`. See package.json for more info.
const { spawn } = require('child_process');
/**
*
* @param {string} program
* @param {string[]} args
* @returns {ReturnType<typeof spawn>}
*/
function cmd(program, args = []) {
const spawnOptions = { "shell": true };
console.log('CMD:', program, args.flat(), spawnOptions);
const p = spawn(program, args.flat(), spawnOptions); // NOTE: flattening the args array enables you to group related arguments for better self-documentation of the running command
// @ts-ignore [stdout may be null?]
p.stdout.on('data', (data) => process.stdout.write(data));
// @ts-ignore [stderr may be null?]
p.stderr.on('data', (data) => process.stderr.write(data));
p.on('close', (code) => {
if (code !== 0) {
console.error(program, args, 'exited with', code);
}
});
return p;
}
cmd('node', ['server.mjs'])
// TODO: prod mode where we are listening to address 0.0.0.0
cmd('http-server', ['-p', '6969', '-a', '127.0.0.1', '-s', '-c-1', '-d', 'false'])