-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
118 lines (102 loc) · 2.69 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
116
117
118
const gulp = require('gulp')
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const jade = require('gulp-jade')
const copy = require('gulp-copy')
const rimrafPromise = require('rimraf-promise')
const ghPages = require('gulp-gh-pages')
const fs = require('fs')
const connect = require('gulp-connect')
const generatePdf = require('./generate_pdf')
gulp.task('resume-sass', () => {
gulp
.src('src/scss/resume.scss')
.pipe(sass().on('error', sass.logError))
.pipe(
autoprefixer({
browsers: ['last 4 versions'],
cascade: false
})
)
.pipe(gulp.dest('dist/css/'))
.pipe(connect.reload())
})
gulp.task('icon-sass', () => {
gulp
.src('src/scss/iconfont.scss')
.pipe(sass().on('error', sass.logError))
.pipe(
autoprefixer({
browsers: ['last 4 versions'],
cascade: false
})
)
.pipe(gulp.dest('dist/iconfont/'))
.pipe(connect.reload())
})
gulp.task('sass:watch', () => {
gulp.watch('./src/scss/resume.scss', ['resume-sass'])
gulp.watch('./src/scss/iconfont.scss', ['icon-sass'])
gulp.watch('./src/scss/components/*.scss', ['resume-sass'])
})
gulp.task('json2jade', () => {
const info = JSON.parse(fs.readFileSync('./info.json', 'utf-8'))
const locals = highlight(info)
gulp
.src('./src/jade/index.jade')
.pipe(
jade({
locals
})
)
.pipe(gulp.dest('./dist/'))
.pipe(connect.reload())
})
gulp.task('json2jade:watch', () => {
gulp.watch('./info.json', ['json2jade'])
})
function src2dist(dir) {
return gulp.src(`./src/${dir}/*.*`).pipe(gulp.dest(`./dist/${dir}/`))
}
function highlight(locals) {
var locals = JSON.stringify(locals)
const re = /`(.+?)`/g
locals = locals.replace(re, '<strong>$1</strong>')
return JSON.parse(locals)
}
gulp.task('copy', () => {
src2dist('iconfont')
src2dist('img')
src2dist('pdf')
gulp.src('./CNAME').pipe(gulp.dest('./dist'))
})
gulp.task('clean', () => {
rimrafPromise('./dist/')
})
gulp.task('deploy', () =>
gulp.src('./dist/**/*').pipe(
ghPages({
remoteUrl: '[email protected]:tybleo/LeoTianResumeDist.git',
branch: 'master'
})
)
)
let port = 9000
// 避免打印时,同时运行开发服务报错
gulp.task('set-pdf-port', () => {
port = 9001
})
gulp.task('webserver', () => {
connect.server({
root: './dist',
livereload: true,
port
})
})
gulp.task('dev', ['default', 'json2jade:watch', 'sass:watch', 'webserver'])
gulp.task('default', ['icon-sass', 'resume-sass', 'json2jade', 'copy'])
gulp.task('pdf', ['set-pdf-port', 'default', 'webserver'], async () => {
await generatePdf('http://localhost:9001')
connect.serverClose()
process.exit(0)
})