-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.ts
70 lines (56 loc) · 1.67 KB
/
gulpfile.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
59
60
61
62
63
64
65
66
67
68
import { series } from 'gulp';
import path from 'path';
import fse from 'fs-extra';
import chalk from 'chalk';
import conventionalChangelog from 'conventional-changelog';
import { buildByRollup } from './script/gulp/build-by-rollup-up';
import { clearLibFile } from './script/gulp/clear-lib';
import { generateDts } from './script/gulp/generate-dts';
type TaskFunc = (cb: Function) => void;
const log = {
progress: (text: string) => {
console.log(chalk.green(text));
},
error: (text: string) => {
console.log(chalk.red(text));
},
};
const paths = {
root: path.join(__dirname, '/'),
lib: path.join(__dirname, '/lib'),
};
const complete: TaskFunc = (cb) => {
log.progress('---- end ----');
cb();
};
// 构建过程
// 1. 删除 lib 文件夹
// 2. rollup 打包
// 3. api-extractor 生成统一的声明文件, 删除多余的声明文件
// 4. 完成
export const build = series(
clearLibFile,
buildByRollup,
generateDts,
complete,
);
// 自定义生成 changelog
export async function changelog(cb: Function) {
const changelogPath: string = path.join(paths.root, 'CHANGELOG.md');
// 对命令 conventional-changelog -p angular -i CHANGELOG.md -w -r 0
const changelogPipe = await conventionalChangelog({
preset: 'angular',
releaseCount: 0,
});
changelogPipe.setEncoding('utf8');
const resultArray = ['# 工具库更新日志\n\n'];
changelogPipe.on('data', (chunk) => {
// 原来的 commits 路径是进入提交列表
chunk = chunk.replace(/\/commits\//g, '/commit/');
resultArray.push(chunk);
});
changelogPipe.on('end', async () => {
await fse.createWriteStream(changelogPath).write(resultArray.join(''));
cb();
});
}