-
Notifications
You must be signed in to change notification settings - Fork 13
/
bootstrap.js
85 lines (72 loc) · 2.18 KB
/
bootstrap.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
// const ignore = "koot-@(cli|boilerplate|boilerplate-*)"
const individualPackages = ['create-koot-app', 'koot-cli'];
const ignore =
'@(' +
[
...[
'boilerplate',
'boilerplate-legacy',
'boilerplate-system',
'boilerplate-web',
].map((name) => `koot-${name}`),
...individualPackages,
].join('|') +
')';
const runCmd = async (msg, cmd, options = {}) => {
if (!cmd || typeof cmd === 'object') return await runCmd(cmd, cmd, options);
// print name
console.log('\n');
console.log(`\x1b[43m \x1b[0m\x1b[33m ` + msg + `\x1b[0m`);
console.log('');
// spawn
const chunks = cmd.split(' ');
await new Promise((resolve) => {
const child = require('child_process').spawn(chunks.shift(), chunks, {
stdio: 'inherit',
shell: true,
...options,
});
child.on('close', () => {
resolve();
});
});
};
async function prepareIndividualPackage(pName) {
const cwd = path.resolve(__dirname, './packages', pName);
if (!fs.existsSync(cwd)) return;
await runCmd(`Install deps for ${pName}`, `npm install --no-package-lock`, {
cwd,
});
}
const run = async () => {
// 检查 `lerna` 是否安装到本地依赖
const lernaInstalled = fs.existsSync(
path.resolve(__dirname, 'node_modules/lerna')
);
if (lernaInstalled) {
await runCmd(
`Run: lerna clean`,
`lerna clean --yes --ignore "${ignore}"`
);
}
await runCmd(
`Install deps for root directory`,
'npm install --no-package-lock --force'
);
await runCmd(
`Run: lerna bootstrap`,
`lerna bootstrap --hoist --ignore "${ignore}"`
);
for (const pName of individualPackages) {
await prepareIndividualPackage(pName);
}
await runCmd(`Install deps for test projects`, `node test/pre-test.js"`);
//
console.log('\n');
console.log(`\x1b[42m \x1b[0m\x1b[32m Bootstrap complete\x1b[0m`);
console.log('');
};
run().catch((err) => console.error(err));