forked from sahat/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
287 lines (252 loc) · 7.24 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
'use strict';
// Install: you must install gulp both globally *and* locally.
// Make sure you `$ npm install -g gulp`
/**
* Dependencies
*/
var $ = require('gulp-load-plugins')({ lazy: true });
var psi = require('psi');
var del = require('del');
var gulp = require('gulp');
var pngquant = require('imagemin-pngquant');
var terminus = require('terminus');
var runSequence = require('run-sequence');
/**
* Banner
*/
var pkg = require('./package.json');
var banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.licenses[0].type %>',
' */',
''
].join('\n');
/**
* Paths
*/
var paths = {
clean: [
'public/js/**/*.js',
'public/js/**/*.map',
'public/js/**/*.min.js',
'public/css/**/*.css',
'public/css/**/*.min.css',
'!public/js/main.js', // ! not
'!public/js/socket.io-1.0.6.js' // ! not
],
js: [
// ============= Bootstrap ================
// Enable/disable as needed but only turn on
// .js that is needed on *every* page. No bloat!
// =========================================
'public/lib/bootstrap/js/transition.js',
'public/lib/bootstrap/js/alert.js',
// 'public/lib/bootstrap/js/button.js',
// 'public/lib/bootstrap/js/carousel.js',
'public/lib/bootstrap/js/collapse.js',
'public/lib/bootstrap/js/dropdown.js',
// 'public/lib/bootstrap/js/modal.js',
// 'public/lib/bootstrap/js/tooltip.js',
// 'public/lib/bootstrap/js/popover.js',
// 'public/lib/bootstrap/js/scrollspy.js',
// 'public/lib/bootstrap/js/tab.js',
// 'public/lib/bootstrap/js/affix.js'
// =========================================
'public/lib/fastclick/lib/fastclick.js',
'public/js/main.js'
],
lint: [
'config/**/*.js',
'test/**/*.js',
'controllers/**/*.js',
'models/**/*.js',
'app.js',
'app_cluster.js',
'gulpfile.js'
],
less: [
'less/main.less',
'less/page-api.less',
'less/page-colors.less',
'less/page-dashboard.less',
'less/page-privacy.less',
'less/page-react.less'
]
};
/**
* Clean
*/
// Return the stream so that gulp knows the task is asynchronous
// and waits for it to terminate before starting dependent tasks.
// gulp.task('clean', function () {
// return gulp.src(paths.clean, { read: false })
// .pipe($.rimraf());
// });
gulp.task('clean', function (cb) {
del(paths.clean, cb);
});
/**
* Process CSS
*/
gulp.task('styles', function () {
return gulp.src(paths.less) // Read in Less files
.pipe($.less({ strictMath: true })) // Compile Less files
.pipe($.autoprefixer({ // Autoprefix for target browsers
browsers: ['last 2 versions'],
cascade: true
}))
.pipe($.csscomb()) // Coding style formatter for CSS
.pipe($.csslint('.csslintrc')) // Lint CSS
.pipe($.csslint.reporter()) // Report issues
.pipe($.rename({ suffix: '.min' })) // Add .min suffix
.pipe($.csso()) // Minify CSS
.pipe($.header(banner, { pkg : pkg })) // Add banner
.pipe($.size({ title: 'CSS:' })) // What size are we at?
.pipe(gulp.dest('./public/css')) // Save minified CSS
.pipe($.livereload()); // Initiate a reload
});
/**
* Process Scripts
*/
gulp.task('scripts', function () {
return gulp.src(paths.js) // Read .js files
.pipe($.concat(pkg.name + '.js')) // Concatenate .js files
.pipe(gulp.dest('./public/js')) // Save main.js here
.pipe($.rename({ suffix: '.min' })) // Add .min suffix
.pipe($.uglify({ outSourceMap: true })) // Minify the .js
.pipe($.header(banner, { pkg : pkg })) // Add banner
.pipe($.size({ title: 'JS:' })) // What size are we at?
.pipe(gulp.dest('./public/js')) // Save minified .js
.pipe($.livereload()); // Initiate a reload
});
/**
* Process Images
*/
gulp.task('images', function () {
return gulp.src('images/**/*') // Read images
.pipe($.changed('./public/img')) // Only process new/changed
.pipe($.imagemin({ // Compress images
progressive: true,
optimizationLevel: 3,
interlaced: true,
svgoPlugins: [{ removeViewBox: false }],
use: [pngquant()]
}))
.pipe(gulp.dest('./public/img')); // Write processed images
});
/**
* JSHint Files
*/
gulp.task('lint', function () {
return gulp.src(paths.lint) // Read .js files
.pipe($.jshint()) // lint .js files
.pipe($.jshint.reporter('jshint-stylish'));
});
/**
* JSCS Files
*/
gulp.task('jscs', function () {
return gulp.src(paths.lint) // Read .js files
.pipe($.jscs()) // jscs .js files
.on('error', function (e) {
$.util.log(e.message);
$.jscs().end();
})
.pipe(terminus.devnull({ objectMode: true }));
});
/**
* Build Task
* - Build all the things...
*/
gulp.task('build', function (cb) {
runSequence(
'clean', // first clean
['lint', 'jscs'], // then lint and jscs in parallel
['styles', 'scripts', 'images'], // etc.
cb);
});
/**
* Nodemon Task
*/
gulp.task('nodemon', ['build'], function (cb) {
$.livereload.listen();
var called = false;
$.nodemon({
script: 'app.js',
verbose: false,
env: { 'NODE_ENV': 'development', 'DEBUG': 'skeleton' },
// nodeArgs: ['--debug']
ext: 'js',
ignore: [
'gulpfile.js',
'public/',
'views/',
'less/',
'node_modules/'
]
})
.on('start', function () {
setTimeout(function () {
if (!called) {
called = true;
cb();
}
}, 3000); // wait for start
})
.on('restart', function () {
setTimeout(function () {
$.livereload.changed('/');
}, 3000); // wait for restart
});
});
/**
* Open the browser
*/
gulp.task('open', ['nodemon'], function () {
var options = {
url: 'http://localhost:3000/'
};
// A file must be specified or gulp will skip the task
// Doesn't matter which file since we set the URL above
// Weird, I know...
gulp.src('./public/humans.txt')
.pipe($.open('', options));
});
/**
* Default Task
*/
gulp.task('default', ['open'], function () {
gulp.watch(paths.less, ['styles']);
gulp.watch(paths.js, ['scripts']);
gulp.watch(paths.lint, ['lint', 'jscs']);
gulp.watch('views/**/*.jade').on('change', $.livereload.changed);
});
/**
* Run PageSpeed Insights
*/
var site = 'https://skeleton-app.jit.su';
// var key = '';
// Please feel free to use the `nokey` option to try out PageSpeed
// Insights as part of your build process. For more frequent use
// please register your own API key. For more info:
// https://developers.google.com/speed/docs/insights/v1/getting_started
gulp.task('mobile', function (cb) {
psi({
// key: key
nokey: 'true',
url: site,
strategy: 'mobile',
}, cb);
});
gulp.task('desktop', ['mobile'], function (cb) {
psi({
// key: key,
nokey: 'true',
url: site,
strategy: 'desktop',
}, cb);
});
gulp.task('pagespeed', ['desktop']);