-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (97 loc) · 2.46 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
var path = require('path');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var eventStream = require('event-stream');
var runSequence = require('run-sequence');
var config = require('./config/gulp.config.js');
var val = require('./config/var.js');
var puerfConfig = require('./config/puerf/puerf.config.js');
var os = require('os');
var child_process = require('child_process');
var rimraf = require('rimraf');
var _PLATFORM = os.platform();
/**
* [task serve]
* development environment
*/
gulp.task('dev',function(cb){
runSequence(
'clean:dev',
'tpl:copy:dev',
'tplreplace',
'js:serve',
'puerf',
'watch',
cb);
});
gulp.task('build', function(cb){
runSequence(
'clean',
'tpl:copy',
cb);
});
gulp.task('clean',function(cb){
rimraf(config.del.build,{},cb);
});
gulp.task('clean:dev',function(cb){
rimraf(config.del.dev,{},cb);
});
gulp.task('watch', function(){
gulp.watch(config.watch.templates,['tplreplace']);
});
/**
* [task puerf]
* use puerf to render freemarker templates
*/
gulp.task('puerf', function() {
var puerf = require('puer-freemarker');
puerf.start(puerfConfig);
});
/**
* [task js:serve]
* use child_process to launch a server with webpack-dev-server
*/
gulp.task('js:serve',function(){
return child_process.spawn('node',['server.js'],{ stdio: 'inherit'});
});
/**
* [task tpl:copy]
* copy templates to tpl without pages
*/
gulp.task('tpl:copy:dev',function(){
var _config = config.tplCopy.dev;
return gulp.src(_config.src)
.pipe(gulp.dest(_config.dest));
});
/**
* [task tpl:copy]
* copy templates to tpl without pages
*/
gulp.task('tpl:copy',function(){
var _config = config.tplCopy.build;
return gulp.src(_config.src)
.pipe(gulp.dest(_config.dest));
});
/**
* [task tplreplace]
* insert script tag into html,
* changed this script src to 'http://localhost:8010/devbuild*'
*/
gulp.task('tplreplace',function(cb){
var _config = config.tplreplace,
_platform = os.platform;
console.log(_config);
var tasks = val.pagesToPath('dev').map(function(page){
var _dest = page.ftl.slice(0,page.ftl.lastIndexOf(_PLATFORM === 'win32' ? '\\': '/'));
return gulp.src(page.templates)
.pipe($.htmlReplace({
'js': {
src: _config.options.pre + page.name,
tpl:'<script src="%s.js"></script>'
}
}))
.pipe(gulp.dest(_dest))
.on('error', $.util.log);
});
eventStream.merge(tasks).on('end', cb);
});