Skip to content

Commit

Permalink
build - use rollup watcher API
Browse files Browse the repository at this point in the history
  • Loading branch information
chmln committed Feb 16, 2019
1 parent 39255f3 commit dd1e561
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
30 changes: 12 additions & 18 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ function logErr(e: Error | string) {
console.trace();
}

function startRollup() {
return execCommand(`npm run rollup:start`);
}

function resolveGlob(g: string) {
return new Promise<string[]>((resolve, reject) => {
glob(
Expand Down Expand Up @@ -80,7 +76,6 @@ async function buildScripts() {
await buildFlatpickrJs();
const transpiled = await fs.readFile("./dist/flatpickr.js");
fs.writeFile("./dist/flatpickr.min.js", uglify(transpiled.toString()));
console.log("done.");
} catch (e) {
logErr(e);
}
Expand Down Expand Up @@ -115,8 +110,6 @@ function buildExtras(folder: "plugins" | "l10n") {
}),
...(css_paths.map(p => fs.copy(p, p.replace("src", "dist"))) as any),
]);

console.log("done.");
};
}

Expand Down Expand Up @@ -206,26 +199,27 @@ function watch(path: string, cb: (path: string) => void) {
function start() {
const devMode = process.argv.indexOf("--dev") > -1;
if (devMode) {
const proc = startRollup();
const write = (s: string) => process.stdout.write(`rollup: ${s}`)
const watcher = rollup.watch([rollupConfig])

function exit(signal: string) {
!proc.killed && proc.kill(signal);
watcher.on("event", logEvent);

function exit() {
watcher.close();
watchers.forEach(w => w.close());
}

function log(data: string) {
process.stdout.write(`rollup: ${data}`);
interface RollupWatchEvent { code: string, input?: string, output?: string, result?: string }
function logEvent(e: RollupWatchEvent) {
write([e.code, e.input && `${e.input} -> ${e.output!}`, "\n"].filter(x => x).join(" "))
}

proc.stdout.on("data", log);
proc.stderr.on("data", log);

//catches ctrl+c event
process.on("SIGINT", exit.bind(null, "SIGKILL"));
process.on("SIGINT", exit);

// catches "kill pid" (for example: nodemon restart)
process.on("SIGUSR1", exit.bind(null, "SIGKILL"));
process.on("SIGUSR2", exit.bind(null, "SIGKILL"));
process.on("SIGUSR1", exit);
process.on("SIGUSR2", exit);

setupWatchers();
return;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"build:post": "sh ./emitDeclarations.sh",
"fmt": "prettier --write --trailing-comma es5 --write",
"start": "npm run build:build -- --dev",
"rollup:start": "rollup -w -c",
"test": "run-s test:typecheck test:unit",
"test:typecheck": "tsc -p src --noEmit",
"test:unit": "jest --config config/jest.json",
Expand Down

0 comments on commit dd1e561

Please sign in to comment.