-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.ts
More file actions
86 lines (78 loc) · 2.42 KB
/
Copy pathgulpfile.ts
File metadata and controls
86 lines (78 loc) · 2.42 KB
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
86
const fs = require("fs");
const conventionalChangelog = require("conventional-changelog");
const chalkLog = require("chalk");
const gulp = require("gulp");
const gulpSass = require("gulp-sass");
const dartSass = require("sass");
const autoprefixer = require("gulp-autoprefixer");
const cleanCSS = require("gulp-clean-css");
const rename = require("gulp-rename");
const path = require("path");
const noCompPrefixFile = /(index|base)/;
const sass = gulpSass(dartSass);
const distFolder = "./lib/styles";
/**
* compile styles scss & minify & copy css to lib/styles
* not use sass.sync().on('error', sass.logError) to throw exception
* @returns
*/
function compileAndCopyCssToLib() {
return gulp
.src("./packages/styles/src/*.scss")
.pipe(sass.sync())
.pipe(autoprefixer({ cascade: false }))
.pipe(
cleanCSS({}, (details) => {
console.log(
`${chalkLog.cyan(details.name)}: ${chalkLog.yellow(
details.stats.originalSize / 1000
)} KB -> ${chalkLog.green(details.stats.minifiedSize / 1000)} KB`
);
})
)
.pipe(
// eslint-disable-next-line no-shadow
rename((path) => {
if (!noCompPrefixFile.test(path.basename)) {
// eslint-disable-next-line no-param-reassign
path.basename = `h-${path.basename}`;
}
})
)
.pipe(gulp.dest(distFolder));
}
/**
* copy font to lib/fonts
* @returns
*/
function copyFontToLib() {
return gulp.src("./packages/styles/src/fonts/**").pipe(gulp.dest(`${distFolder}/fonts`));
}
/*
* changelog 自动生成
*/
async function changelog(cb) {
const changelogPath = path.resolve(__dirname, "CHANGELOG.md");
// 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 = ["# h-design更新日志\n\n"];
changelogPipe.on("data", (chunk) => {
// 原来的 commits 路径是进入提交列表
chunk = chunk.replace(/\/commits\//g, "/commit/");
resultArray.push(chunk);
});
changelogPipe.on("end", async () => {
await fs.createWriteStream(changelogPath).write(resultArray.join(""));
cb();
});
}
const build = gulp.series(compileAndCopyCssToLib, copyFontToLib);
const log = gulp.series(changelog);
exports.default = build;
exports.build = build;
exports.log = log;