-
Notifications
You must be signed in to change notification settings - Fork 49
/
gulpfile.js
183 lines (145 loc) · 4.5 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var gulp = require('gulp');
var args = require('yargs').argv;
var del = require('del');
var $ = require('gulp-load-plugins')({lazy: true});
var config = require('./gulp.config')();
// var jshint = require('gulp-jshint');
// var jscs = require('gulp-jscs');
// var util = require('gulp-util');
// var gulpIf = require('gulp-if');
// var gulpPrint = require('gulp-print');
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
gulp.task('fonts', ['clean-fonts'], function(){
log('copy fonts');
gulp.src(config.fonts)
.pipe(gulp.dest(config.build + "fonts"));
});
gulp.task('images', ['clean-images'], function(){
log('copy images');
gulp.src(config.images)
.pipe($.imagemin({optimizationLevel: 3}))
.pipe(gulp.dest(config.build + "images"));
});
gulp.task('optimazed', ['inject'], function(){
log('optimazed the code');
var cssFilter = $.filter('**/*.css', {restore: true});
var jsFilter = $.filter('**/*.js', {restore: true});
gulp.src(config.index)
.pipe($.useref())
.pipe(jsFilter)
.pipe($.uglify())
.pipe($.rev())
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe($.csso())
.pipe($.rev())
.pipe(cssFilter.restore)
.pipe($.revReplace())
// .pipe($.if('*.js', $.uglify()))
// .pipe($.if('*.css', $.csso()))
.pipe(gulp.dest(config.build))
.pipe($.rev.manifest())
.pipe(gulp.dest(config.build));
});
gulp.task('vet', function(){
log('Analyzing source with jshint and jscs');
return gulp.src(config.alljs)
.pipe($.if(args.verbose, $.print()))
.pipe($.jscs())
//.pipe(jscs.reporter())
//.pipe(jscs.reporter('fail'))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($.jshint.reporter('fail'));
});
gulp.task('style', ['clean-style'], function(){
log('Compile less -> css')
return gulp.src(config.less)
.pipe($.plumber())
.pipe($.less())
//.on('error', errorLogger)
.pipe($.autoprefixer({browsers:['last 2 version', '> 5%']}))
.pipe(gulp.dest(config.temp));
});
gulp.task('clean-style', function(){
var files = config.temp + '**/*';
clean(files);
});
gulp.task('clean-fonts', function(){
var files = config.build + 'fonts/**/*';
clean(files);
});
gulp.task('clean-images', function(){
var files = config.build + 'images/**/*';
clean(files);
});
gulp.task('clean-code', function(){
var files = [].concat(
config.build + '**/*.js',
config.build + '**/*.css',
config.build + '**/*.html')
clean(files);
});
gulp.task('less-watcher', function(){
gulp.watch([config.less], ['style']);
});
gulp.task('wiredep', function(){
log('Write up bower css js and our app js into html');
var options = config.getWiredepDefaultOptions();
var wiredep = require('wiredep').stream;
return gulp.src(config.index)
.pipe(wiredep(options))
.pipe($.inject(gulp.src(config.js), {relative: true}))
.pipe(gulp.dest(config.src));
});
gulp.task('inject', ['style', 'wiredep'], function(){
log('Write up app css into html and call wiredep');
return gulp.src(config.index)
.pipe($.inject(gulp.src(config.css),{relative: true}))
.pipe(gulp.dest(config.src));
});
// gulp.task('serve-dev', ['inject'], function(){
// /*
// config.nodeServer : express app.js
// config.server: express dir
// */
// var isDev = true;
// var nodeOptions = {
// script: 'config.nodeServer',
// env: {
// 'PORT': port,
// 'NODE_ENV': isDev ? 'dev' : 'build'
// },
// watch: [config.server]
// }
// return $.nodemon(nodeOptions)
// .on('restart', ['vet'], function(){
// log('server restart');
// })
// .on('start',function(){
// log('server start');
// })
// .on('crash', function(){
// log('server crash');
// })
// .on('exit', function(){
// log('server exit');
// });
// });
/////////////////
//use gulp-plumber to repalce the error handle function
// function errorLogger(error) {
// log('*** Start of Error ***');
// console.log(error);
// log('*** End of Error ***');
// //tell gulp finished
// this.emit('end');
// }
function clean(path) {
log('Clean: ' + path)
del(path);
}
function log(msg) {
$.util.log($.util.colors.blue(msg));
}