-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.js
50 lines (41 loc) · 1.32 KB
/
build.js
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
import chalk from 'chalk';
import ChildProcess from 'child_process';
import util from 'util';
const exec = util.promisify(ChildProcess.exec);
// list all templates (those are the folders in packages/)
let templates = ChildProcess.execSync(`ls ./packages`).toString().split('\n');
// remove the last element of the array, which is an empty string
templates.pop();
const success = '✔';
const fail = '×';
async function buildAll() {
try {
console.log(chalk.cyan('\nInitializing build...'));
console.log(chalk.italic('\nInstall dependencies...'));
for (let i = 0; i < templates.length; i++) {
try {
await exec(`cd ./packages/${templates[i]} && npm install`);
console.log(chalk.green(`${success} ${templates[i]}`));
} catch {
console.log(chalk.red(`${fail} ${templates[i]}`));
process.exit(1);
}
}
console.log(chalk.italic('\nBuild all templates...'));
for (let i = 0; i < templates.length; i++) {
try {
await exec(`cd packages/${templates[i]} && npm run build`);
console.log(chalk.green(`${success} ${templates[i]}`));
} catch {
console.log(chalk.red(`${fail} ${templates[i]}`));
process.exit(1);
}
}
// success
console.log(chalk.green('\nBuild completed successfully.'));
} catch (err) {
console.log(chalk.red('build error: ' + err));
process.exit(1);
}
}
buildAll();