forked from joyeecheung/resume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (86 loc) · 3.06 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var path = require('path');
var gls = require('gulp-live-server');
var server = gls.static('dist', 8000);
/**************** Utility **********************/
function highlight(str) {
return str.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/`(.+?)`/g, '<strong>$1</strong>');
}
/******************* Jade to html ***********/
function getLocals() {
var resumeData = require('./resume.json');
var localePath = './i18n/' + resumeData.data_lang + '/dict.js';
var locals = require(localePath);
// remove cache
delete require.cache[require.resolve('./resume.json')];
delete require.cache[require.resolve(localePath)];
// integrate the context
for (var item in resumeData) {
locals[item] = resumeData[item];
}
locals.highlight = highlight;
return locals;
}
gulp.task('jade', function() {
return gulp.src('./src/jade/index.jade')
.pipe(plugins.jade({ locals: getLocals(),pretty: true}))
.pipe(gulp.dest('./dist/'));
});
/************* less to css ********************/
var lessPath = [path.join(__dirname, 'src', 'less', 'includes'),
path.join(__dirname, 'src', 'less', 'components')];
function less2css(srcPath, destPath, debug) {
if(!debug) {
return gulp.src(srcPath)
.pipe(plugins.less({ paths: lessPath }))
.pipe(plugins.minifyCss({ compatibility: 'ie9' }))
.pipe(gulp.dest(destPath));
} else {
return gulp.src(srcPath)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.less({ paths: lessPath }))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(destPath));
}
}
gulp.task('less', function() {
less2css('./src/less/questions.less', './dist/questions/');
less2css('./src/less/index.less', './dist/');
});
gulp.task('less-debug', function() {
less2css('./src/less/questions.less', './dist/questions/', true);
less2css('./src/less/index.less', './dist/', true);
});
/************** Static assets **************/
gulp.task('static', function() {
return gulp.src('./static/**/*', { base: 'static' })
.pipe(gulp.dest('./dist/static/'));
});
/****************** Watch ****************/
gulp.task('watch', ['server'], function() {
gulp.watch(['./src/**/*.jade', './resume.json', './i18n/**/*.js'],
['jade']);
gulp.watch('./static/**/*', ['static']);
gulp.watch('./src/**/*.less', ['less-debug']);
gulp.watch('./dist/**/*', function() {
server.notify.apply(server, arguments);
});
});
/****************** Build ****************/
gulp.task('build', ['jade', 'less-debug', 'static']);
gulp.task('build-for-deploy', ['jade', 'less', 'static']);
/****************** Server ****************/
gulp.task('serve', function () {
server.start();
});
gulp.task('server', ['build', 'serve']);
gulp.task('preview', ['build-for-deploy', 'serve']);
/****************** Deploy ****************/
gulp.task('deploy', ['build-for-deploy'], function() {
return gulp.src('./dist/**/*')
.pipe(plugins.ghPages());
});
/****************** Default ****************/
gulp.task('default', ['server', 'watch']);