forked from apache/echarts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
137 lines (125 loc) · 3.59 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var jade = require('gulp-jade');
var uglify = require('gulp-uglify');
var copy = require('gulp-copy');
var rename = require('gulp-rename');
var yargs = require('yargs');
var config = require('./config/env');
// Usage: gulp build --env-cn
var lang = 'en';
for (var envArg of Object.keys(yargs.argv)) {
if (envArg.indexOf('env-') === 0) {
lang = envArg.replace('env-', '');
}
}
/**
* Launch the Server
*/
gulp.task('browser-sync', ['sass'], function() {
gulp.run('jade');
browserSync({
server: {
baseDir: '.'
}
});
});
/**
* Build files for release
*/
gulp.task('build', function() {
gulp.run('jade');
gulp.run('sass');
});
/**
* Compile files from _scss into css
*/
gulp.task('sass', function () {
return gulp.src('public/stylesheets/scss/main.scss')
.pipe(sass({
includePaths: ['scss'],
onError: function(e) {
browserSync.notify();
process.stdout.write(e + '\n');
},
outputStyle: 'compressed'
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('public/stylesheets'));
});
/**
* Generate site using Jade
*/
gulp.task('jade', function() {
return gulp.src(['views/view.jade', 'views/editor.jade', 'views/index.jade'])
.pipe(jade({
data: {
buildVersion: +new Date(),
lang: lang,
host: config.host
}
}))
.pipe(gulp.dest('public/'))
.pipe(browserSync.reload({stream:true}));
});
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function() {
gulp.watch('public/stylesheets/scss/*.scss', ['sass']);
});
/**
* Use fecs to test code style
*/
// gulp.task('fecs', function() {
// return gulp.src(['public/javascript/*'])
// .pipe(fecs.check())
// .pipe(fecs.reporter('baidu', {
// color: true,
// rule: true,
// sort: true
// }))
// .pipe(fecs.format())
// .pipe(gulp.dest('fecs'));;
// });
/**
* Build files into release directory
*/
gulp.task('release-copy', ['release-jade'], function() {
// copy source files
return gulp.src(['public/data/**', 'public/fonts/**', 'public/images/**',
'public/stylesheets/*.css',
'public/vendors/**', 'public/javascripts/chart-list.js',
'public/javascripts/editor.js','public/javascripts/view.js', 'public/javascripts/hm.js', 'public/*.html'])
.pipe(copy('release'));
});
gulp.task('release-jade', function() {
var env = {
buildVersion: +new Date()
};
gulp.src('views/explore.jade')
.pipe(jade({
data: env
}))
.pipe(rename('index.html'))
.pipe(gulp.dest('public'));
return gulp.src('views/editor.jade')
.pipe(jade({
data: env
}))
.pipe(gulp.dest('public'));
});
gulp.task('release', ['release-copy'], function() {
return gulp.src(['release/public/javascripts/*.js'])
.pipe(uglify())
.pipe(gulp.dest('release/public/javascripts'));
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);