-
Notifications
You must be signed in to change notification settings - Fork 404
/
Copy pathbuild.ts
58 lines (49 loc) · 1.52 KB
/
build.ts
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
import * as path from 'path';
import chalk from 'chalk';
import { command } from 'execa';
import * as fs from 'fs-extra';
import * as glob from 'glob';
import { run } from './fn/shell';
(async () => {
await run('yarn run clean');
{
const cmd = 'yarn tsc --build configs/ts/tsconfig.build.json';
console.log(`[RUN]: ${cmd}`);
const childProcess = command(cmd, {
stdio: 'pipe',
shell: true,
});
const tscErrorRegex = /error TS\d+:/;
childProcess.stdout!.on('data', (data) => {
const str = data.toString();
if (tscErrorRegex.test(str)) {
process.stdout.write('\n');
process.stdout.write(chalk.redBright(str));
process.stdout.write('\n');
setTimeout(() => {
childProcess.kill('SIGINT');
setTimeout(() => {
process.stdout.write(chalk.red('It seems that tsc has error, so we exit.\n'));
process.stdout.write('\n');
process.exit(1);
});
}, 100);
}
});
await childProcess;
}
const filePatten = '*/src/**/!(*.ts|*.tsx)';
console.log(`[COPY]: ${filePatten}`);
// 拷贝非 ts/js 文件
const cwd = path.join(__dirname, '../packages');
const files = glob.sync(filePatten, { cwd, nodir: true });
for (const file of files) {
const from = path.join(cwd, file);
const to = path.join(cwd, file.replace(/\/src\//, '/lib/'));
await fs.mkdirp(path.dirname(to));
await fs.copyFile(from, to);
}
})().catch((e) => {
console.trace(e);
process.exit(128);
});