-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
115 lines (100 loc) · 3.44 KB
/
gulpfile.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const gulp = require('gulp');
const del = require('del');
const rename = require('gulp-rename')
const gulpReplace = require('gulp-replace')
// 删除之前生成的dist目录
gulp.task('clean:_docs', function (cb) {
return del([
'_docs/**',
// @TODO 这样覆盖有用吗???
'!_docs/.vuepress',
'_docs/.vuepress/dist/**',
'_docs/.vuepress/public/**',
], cb);
});
gulp.task('clean:_ppt', function (cb) {
return del([
'_ppt/**'
], cb);
});
// 搬运静态资源
gulp.task('copy:static', function () {
return gulp.src([
`static/**/*.*`,
])
.pipe(gulp.dest(`_docs/.vuepress/public/static`))
})
gulp.task('copy:ppt:static', function () {
return gulp.src([
`static/**/*.*`,
]).pipe(gulp.dest(`_ppt/static`))
})
// 搬运Markdown
const appendixFolder = [
".vuepress", ".nodeppt", "_docs", "_ppt",
".idea", ".git", "node_modules", ".vscode", "static", "public",
// 附录
// 'appendix',
'activity', 'book', 'code', 'dying', 'ext', 'planB', 'regret'
]
gulp.task('copy:markdown', function () {
return gulp.src([
`**/*{README,@nice}*.md`,
// @TODO 好像不支持这种格式 {a,b}/**.md
...appendixFolder.map(item => `!${item}/**/*.md`)
])
// 替换链接 空格开头
.pipe(gulpReplace(/ ((((ht|f)tps?:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)#?[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/ig, function(match, prefix, content) {
// console.log(match, prefix, content)
return ' ['+ match.trimLeft() +']('+ match.trimLeft() +')';
}))
.pipe(rename(function (path) {
// @TODO 正则优化一波
// eg. [9-1]xxxx-yyyy
if (path.dirname.includes('[') && path.dirname.includes(']')) {
path.dirname = path.dirname.replace(/\[/, 'nav.').replace(/\]/, ".")
}
}))
.pipe(gulp.dest(`_docs`))
})
gulp.task('copy:ppt:markdown', function () {
return gulp.src([
`**/*@ppt*.md`,
...appendixFolder.map(item => `!${item}/**/*.md`)
])
// 替换链接 空格开头
.pipe(gulpReplace(/ ((((ht|f)tps?:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)#?[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/ig, function(match, prefix, content) {
// console.log(match, prefix, content)
return '['+ match +']('+ match +')';
}))
.pipe(rename(function (path) {
// 都移到组外层
path.dirname = ""
// 来个随机数
path.basename = path.basename + '-' + Math.random().toString().slice(2, 7)
}))
.pipe(gulp.dest(`_ppt`))
})
// vuepress打包文件路径替换
const publicPath = 'note'
gulp.task('path:replace', function() {
return gulp
.src([
'_docs/.vuepress/dist/**/*.{html,js}',
])
// 理解一波 ??
.pipe(gulpReplace(/(?<!note\/)static\/images/g, 'note/static/images'))
.pipe(gulp.dest('_docs/.vuepress/dist'));
});
// 清理所有
gulp.task('clean', gulp.series('clean:_docs', function (done) {
done();
}));
gulp.task('copy', gulp.series('clean:_docs', gulp.parallel('copy:static', 'copy:markdown'), function (done) {
done();
}));
gulp.task('copy:ppt', gulp.series('clean:_ppt', gulp.parallel('copy:ppt:static', 'copy:ppt:markdown'), function (done) {
done();
}));
// gulp4调整了default写法
gulp.task('default', gulp.series('copy:static'));