Skip to content

Commit

Permalink
update livereload script
Browse files Browse the repository at this point in the history
  • Loading branch information
shirakaba committed Apr 23, 2021
1 parent d9b9bbb commit 1ce01eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
29 changes: 29 additions & 0 deletions demo/livereload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node
const { spawn } = require("child_process");
const { normalize } = require("path");

// 'disconnect' is not needed as it will only be raised, when either the child process or this process calss disconnect explicitly.
// We are abel to ensure, that this will never happen, as we do not need communication with the spawned subprocess
const terminationSignals = ["close", "exit"];

function startSubprocess() {
return new Promise((res, rej) => {
const [command, ...args] = process.argv.slice(2);
const proc = spawn(normalize(command), args, {
// use parents stdio
stdio: "inherit",
shell:
process.platform === "win32" ||
/^(msys|cygwin)$/.test(process.env.OSTYPE),
});
terminationSignals.forEach((event) => proc.on(event, res));
proc.on("error", rej);
});
}

async function loop() {
let code = 64;
while (code === 64) code = await startSubprocess();
}

loop();
7 changes: 0 additions & 7 deletions demo/livereload.sh

This file was deleted.

2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "webpack --mode production",
"dev": "webpack --mode=development",
"start": "./livereload.sh node_modules/.bin/qode ./dist/index.js",
"start": "node livereload.js node_modules/.bin/qode ./dist/index.js",
"debug": "qode --inspect ./dist/index.js"
},
"dependencies": {
Expand Down

0 comments on commit 1ce01eb

Please sign in to comment.