Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions build/lib/spawn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { spawn } from 'child_process';

const spawns = new Set();

export function spawnAndCheck(cmd, args, options) {
const s = spawn(cmd, args, options);
spawns.add(s);
s.on('close', (code) => {
spawns.delete(s);
if (code !== 0) {
console.error(cmd, 'exited with code:', code);
[...spawns].forEach((s) => s.kill());
process.exit(code);
}
});
}
6 changes: 3 additions & 3 deletions build/tools/build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { spawn } from 'child_process';
import { mkdirSync } from 'fs';
import { spawnAndCheck } from '../lib/spawn.js';

mkdirSync('out', { recursive: true });

spawn('node', ['build/tools/copy.js'], {
spawnAndCheck('node', ['build/tools/copy.js'], {
shell: true,
stdio: 'inherit',
});

spawn('./node_modules/.bin/rollup', ['-c'], {
spawnAndCheck('./node_modules/.bin/rollup', ['-c'], {
shell: true,
stdio: 'inherit',
});
17 changes: 1 addition & 16 deletions build/tools/serve.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import { spawn } from 'child_process';
import { mkdirSync } from 'fs';
import { spawnAndCheck } from '../lib/spawn.js';

mkdirSync('out', { recursive: true });

const spawns = new Set();

function spawnAndCheck(cmd, args, options) {
const s = spawn(cmd, args, options);
spawns.add(s);
s.on('close', (code) => {
spawns.delete(s);
if (code !== 0) {
console.error(cmd, 'exited with code:', code);
[...spawns].forEach((s) => s.kill());
process.exit(code);
}
});
}

spawnAndCheck('npm', ['run', 'watch'], {
shell: true,
stdio: 'inherit',
Expand Down