-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (94 loc) · 2.33 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
const gulp = require('gulp')
const babel = require('gulp-babel')
const concat = require('gulp-concat')
const plumber = require('gulp-plumber')
const pug = require('gulp-pug')
const lang = require('./docs/lang/en.json')
const stylus = require('gulp-stylus')
const header = require('gulp-header')
const { exec } = require('child_process')
const pkg = require('./package.json')
const banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @date <%= date %>',
' */',
''
].join('\n')
function js(cb) {
return gulp
.src(['node_modules/babel-polyfill/dist/polyfill.js', 'src/js/*.js'])
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(
babel({
presets: [
[
'@babel/preset-env',
{
modules: false
}
]
]
})
)
.pipe(header(banner, { pkg, date: new Date() }))
.pipe(gulp.dest('docs/js'))
}
gulp.task('js', js)
const locals = {
_m: lang,
_t: function (s, m) {
m = m || {}
return m[s] || s
}
}
function html() {
return gulp
.src(['./src/pug/layouts/*.pug'])
.pipe(
pug({
pretty: true,
locals
})
)
.pipe(gulp.dest('docs/_layouts/'))
}
gulp.task('html-layouts', html)
function html2() {
return gulp
.src(['./src/pug/*.pug'])
.pipe(
pug({
pretty: true,
locals
})
)
.pipe(gulp.dest('docs/'))
}
gulp.task('html-pages', html2)
function css() {
return gulp
.src('./src/styles/main.styl')
.pipe(
stylus({
compress: true
})
)
.pipe(header(banner, { pkg, date: new Date() }))
.pipe(gulp.dest('docs/css/'))
}
gulp.task('css', css)
function touch() {
try {
exec('npm run css', (error, stdout, stderr) => {})
} catch (e) {}
}
gulp.task('touch', touch)
exports.default = function () {
gulp.watch('src/pug/**/*.pug', gulp.series(html, html2))
gulp.watch('src/js/*.js', js)
gulp.watch('src/styles/**/*.styl', touch)
}