-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
64 lines (57 loc) · 1.43 KB
/
gulpfile.js
File metadata and controls
64 lines (57 loc) · 1.43 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
const { src, dest, series } = require("gulp");
const through = require("through2");
const fs = require("fs");
const reg1 =
/<link[^>]*?href\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?data-href\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>/gi;
/**
* 清理输出目录
*/
function clean(cb) {
fs.rmSync("docs", { recursive: true, force: true });
cb();
}
/**
* 复制并处理 HTML 文件
*/
function copyHtml() {
return src(["packages/**/*.html"])
.pipe(
through.obj(function (file, enc, cb) {
let content = file.contents.toString();
content = content.replace(reg1, `<link rel="stylesheet" href="$2" />`);
file.contents = Buffer.from(content);
cb(null, file);
}),
)
.pipe(dest("docs"));
}
/**
* 复制 README.md 到 docs 目录, 并替换里面的 README.md 为 index.html
*/
function copyIndex() {
return src("README.md")
.pipe(
through.obj(function (file, enc, cb) {
let content = file.contents.toString();
// README.md 替换为 index.html
content = content.replace(
/README.md/g,
"index.html",
);
// packages/ 替换为空
content = content.replace(
/packages\//g,
"",
);
file.contents = Buffer.from(content);
cb(null, file);
}),
)
.pipe(dest("docs"));
}
module.exports = {
generateDoc: series(clean, copyHtml, copyIndex),
clean,
copyHtml,
copyIndex
};