forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
41 lines (36 loc) · 1.1 KB
/
build.mjs
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
30
31
32
33
34
35
36
37
38
39
40
41
import { spawn } from "cross-spawn";
const args = process.argv.slice(2);
const tsc = process.env.CI || args.includes("--tsc");
exec("pnpm", ["rollup", "-c"])
.then(() => tsc && exec("pnpm", ["--recursive", "tsc", "-b"]))
.then(() =>
exec("node", ["scripts/copy-build-to-dist.mjs", ...(tsc ? ["--tsc"] : [])])
)
.then(() => process.exit(0))
.catch((err) => {
console.error(err);
process.exit(1);
});
/**
* @param {string} command
* @param {string[]} [args]
*/
function exec(command, args) {
/** @type {(data: any) => any} */
let handleData = (data) => console.log(data.toString().trim());
/** @type {(data: Error) => any} */
let handleError = (data) => console.error(data.toString().trim());
return new Promise((resolve, reject) => {
let ls = spawn(command, args, { cwd: process.cwd() });
ls.stdout.on("data", handleData);
ls.stderr.on("data", handleData);
ls.on("error", handleError);
ls.on("close", (code) => {
if (code === 0) {
resolve(void 0);
} else {
reject(new Error(`${command} exited with code ${code}`));
}
});
});
}