-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepack.cjs
59 lines (51 loc) · 1.88 KB
/
prepack.cjs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const rimraf = require("rimraf");
const child_process = require("child_process");
const readline = require("readline");
async function spawn(prefix, cmd, args) {
console.log(`[${prefix}] Process started`);
const cp = child_process.spawn(cmd, args, {
shell: true,
stdio: "pipe",
env: { ...process.env, FORCE_COLOR: "1" },
});
readline.createInterface({ input: cp.stdout }).on("line", (line) => {
console.log(`[${prefix}] ${line}`);
});
readline.createInterface({ input: cp.stderr }).on("line", (line) => {
console.error(`[${prefix}] ${line}`);
});
return new Promise((resolve, reject) => {
cp.once("error", reject);
cp.once("close", (code) => {
console.log(`[${prefix}] Process ended with status code ${code}`);
if (!code) return resolve();
reject(new Error(`Process ${prefix} exited with code ${code}`));
});
});
}
function clean() {
return new Promise((resolve, reject) =>
rimraf("lib", (err) => {
if (!err) return resolve();
reject(new Error(`Error during clean: ${err.stack || err}`));
})
);
}
async function build() {
// Start cleaning and linting
const cleanPromise = clean();
const lintPromise = spawn("Lint", "yarn", ["lint"]);
// Start compiling CJS and EMS after cleaning is done
const cjsPromise = cleanPromise.then(() => spawn("CJS", "yarn", ["compile"]));
const esmPromise = cleanPromise.then(() => spawn("ESM", "yarn", ["compile:esm"]));
// Start API after CJS is done (which also outputs types)
const apiPromise = cjsPromise.then(() => spawn("API", "yarn", ["api"]));
// Start testing after CJS and EMS are done
const testPromise = Promise.all([cjsPromise, esmPromise]).then(() => spawn("Test", "yarn", ["test"]));
// Wait for all unlinked promises to finish
await Promise.all([lintPromise, apiPromise, testPromise]);
}
build().catch((err) => {
console.error(err);
process.exit(1);
});