-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
441 lines (386 loc) · 13.4 KB
/
gulpfile.js
File metadata and controls
441 lines (386 loc) · 13.4 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jade = require('gulp-jade'),
less = require('gulp-less'),
path = require('path'),
livereload = require('gulp-livereload'), // Livereload plugin needed: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei
marked = require('marked'), // For :markdown filter in jade
path = require('path'),
changed = require('gulp-changed'),
prettify = require('gulp-html-prettify'),
w3cjs = require('gulp-w3cjs'),
rename = require('gulp-rename'),
flip = require('css-flip'),
through = require('through2'),
gutil = require('gulp-util'),
htmlify = require('gulp-angular-htmlify'),
minifyCSS = require('gulp-minify-css'),
gulpFilter = require('gulp-filter'),
expect = require('gulp-expect-file'),
gulpsync = require('gulp-sync')(gulp),
ngAnnotate = require('gulp-ng-annotate'),
sourcemaps = require('gulp-sourcemaps'),
replace = require('gulp-replace');
PluginError = gutil.PluginError;
// LiveReload port. Change it only if there's a conflict
var lvr_port = 35727;
var W3C_OPTIONS = {
// Set here your local validator if your using one. leave it empty if not
//uri: 'http://validator/check',
doctype: 'HTML5',
output: 'json',
// Remove some messages that angular will always display.
filter: function(message) {
if( /Element head is missing a required instance of child element title/.test(message) )
return false;
if( /Attribute .+ not allowed on element .+ at this point/.test(message) )
return false;
if( /Element .+ not allowed as child of element .+ in this context/.test(message) )
return false;
if(/Comments seen before doctype./.test(message))
return false;
}
};
// production mode (see build task)
var isProduction = false;
var useSourceMaps = false;
// ignore everything that begins with underscore
var hidden_files = '**/_*.*';
var ignored_files = '!'+hidden_files;
// VENDOR CONFIG
var vendor = {
// vendor scripts required to start the app
base: {
source: require('./vendor.base.json'),
dest: './assets/js',
name: 'base.js'
},
// vendor scripts to make to app work. Usually via lazy loading
app: {
source: require('./vendor.json'),
dest: './vendor'
}
};
// SOURCES CONFIG
var source = {
scripts: {
app: [ 'front-generator/extra-js/canvasjs.js',
'front-generator/js/app.init.js',
'front-generator/js/modules/*.js',
'front-generator/js/modules/controllers/*.js',
'front-generator/js/modules/directives/*.js',
'front-generator/js/modules/services/*.js',
'front-generator/js/modules/filters/*.js',
'front-generator/js/custom/**/*.js'
],
watch: ['front-generator/js/**/*.js']
},
/*templates: {
app: {
files : ['jade/index.jade'],
watch: ['jade/index.jade', hidden_files]
},
views: {
files : ['jade/views/*.jade', 'jade/views/**\/*.jade', ignored_files],
watch: ['jade/views/**\/*.jade']
},
pages: {
files : ['jade/pages/*.jade'],
watch: ['jade/pages/*.jade']
}
},*/
templates: {
app: {
files : ['front-generator/html/index.html'],
watch: ['front-generator/html/index.html', hidden_files]
},
views: {
files : ['front-generator/html/views/*.html', 'front-generator/html/views/**/*.html', ignored_files],
watch: ['front-generator/html/views/**/*.html']
},
pages: {
files : ['front-generator/html/pages/*.html'],
watch: ['front-generator/html/pages/*.html']
}
},
styles: {
app: {
main: ['front-generator/less/app.less', '!front-generator/less/themes/*.less'],
dir: 'front-generator/less',
watch: ['front-generator/less/*.less', 'front-generator/less/**/*.less', '!front-generator/less/themes/*.less']
},
themes: {
main: ['front-generator/less/themes/*.less', ignored_files],
dir: 'front-generator/less/themes',
watch: ['front-generator/less/themes/*.less']
},
},
bootstrap: {
main: 'front-generator/less/bootstrap/bootstrap.less',
dir: 'front-generator/less/bootstrap',
watch: ['front-generator/less/bootstrap/*.less']
}
};
// BUILD TARGET CONFIG
var build = {
scripts: {
app: {
main: 'app.js',
dir: 'assets/js'
}
},
styles: 'assets/css',
templates: {
app: '.',
views: 'assets/templates/views',
pages: 'assets/templates/pages'
}
};
//---------------
// TASKS
//---------------
// JS APP
gulp.task('scripts:app', function() {
var dte = new Date().getTime();
// Minify and copy all JavaScript (except vendor scripts)
return gulp.src(source.scripts.app)
.pipe( useSourceMaps ? sourcemaps.init() : gutil.noop())
.pipe(concat(build.scripts.app.main))
.pipe(ngAnnotate())
.on("error", handleError)
.pipe( isProduction ? uglify({preserveComments:'some'}) : gutil.noop() )
.on("error", handleError)
.pipe( useSourceMaps ? sourcemaps.write() : gutil.noop() )
.pipe(replace('{{{currentVersion}}}', dte))
.pipe(gulp.dest(build.scripts.app.dir));
});
// VENDOR BUILD
gulp.task('scripts:vendor', ['scripts:vendor:base', 'scripts:vendor:app']);
// This will be included vendor files statically
gulp.task('scripts:vendor:base', function() {
// Minify and copy all JavaScript (except vendor scripts)
return gulp.src(vendor.base.source)
.pipe(expect(vendor.base.source))
.pipe(uglify())
.pipe(concat(vendor.base.name))
.pipe(gulp.dest(vendor.base.dest))
;
});
// copy file from bower folder into the app vendor folder
gulp.task('scripts:vendor:app', function() {
var jsFilter = gulpFilter('**/*.js');
var cssFilter = gulpFilter('**/*.css');
return gulp.src(vendor.app.source, {base: 'bower_components'})
.pipe(expect(vendor.app.source))
.pipe(jsFilter)
.pipe(uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe(minifyCSS())
.pipe(cssFilter.restore())
.pipe( gulp.dest(vendor.app.dest) );
});
// APP LESS
gulp.task('styles:app', function() {
return gulp.src(source.styles.app.main)
.pipe( useSourceMaps ? sourcemaps.init() : gutil.noop())
.pipe(less({
paths: [source.styles.app.dir]
}))
.on("error", handleError)
.pipe( isProduction ? minifyCSS() : gutil.noop() )
.pipe( useSourceMaps ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest(build.styles));
});
// APP RTL
gulp.task('styles:app:rtl', function() {
return gulp.src(source.styles.app.main)
.pipe( useSourceMaps ? sourcemaps.init() : gutil.noop())
.pipe(less({
paths: [source.styles.app.dir]
}))
.on("error", handleError)
.pipe(flipcss())
.pipe( isProduction ? minifyCSS() : gutil.noop() )
.pipe( useSourceMaps ? sourcemaps.write() : gutil.noop())
.pipe(rename(function(path) {
path.basename += "-rtl";
return path;
}))
.pipe(gulp.dest(build.styles));
});
gulp.task('styles:style', function() {
console.log('-----------------------');
console.log(source.styles.app.main);
console.log(source.styles.app.dir);
console.log('#-----------------------#');
return gulp.src(source.styles.app.main)
.pipe( useSourceMaps ? sourcemaps.init() : gutil.noop())
.pipe(less({
paths: [source.styles.app.dir]
}))
.on("error", handleError)
.pipe(flipcss())
.pipe( isProduction ? minifyCSS() : gutil.noop() )
.pipe( useSourceMaps ? sourcemaps.write() : gutil.noop())
.pipe(rename(function(path) {
console.log('+-----------------------+');
console.log(path.basename);
path.basename += "-rtl";
console.log('_-----------------------_');
return path;
}))
.pipe(gulp.dest(build.styles));
});
// LESS THEMES
gulp.task('styles:themes', function() {
return gulp.src(source.styles.themes.main)
.pipe(less({
paths: [source.styles.themes.dir]
}))
.on("error", handleError)
.pipe(gulp.dest(build.styles));
});
// BOOSTRAP
gulp.task('bootstrap', function() {
return gulp.src(source.bootstrap.main)
.pipe(less({
paths: [source.bootstrap.dir]
}))
.on("error", handleError)
.pipe(gulp.dest(build.styles));
});
// JADE
gulp.task('templates:app', function() {
return gulp.src(source.templates.app.files)
//.pipe(changed(build.templates.app, { extension: '.html' }))
//.pipe(jade())
//.on("error", handleError)
//.pipe(prettify({
// indent_char: ' ',
// indent_size: 3,
// unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u']
//}))
// .pipe(htmlify({
// customPrefixes: ['ui-']
// }))
// .pipe(w3cjs( W3C_OPTIONS ))
.pipe(gulp.dest(build.templates.app))
;
});
// JADE
gulp.task('templates:pages', function() {
return gulp.src(source.templates.pages.files)
//.pipe(changed(build.templates.pages, { extension: '.html' }))
//.pipe(jade())
//.on("error", handleError)
//.pipe(prettify({
// indent_char: ' ',
// indent_size: 3,
// unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u']
//}))
// .pipe(htmlify({
// customPrefixes: ['ui-']
// }))
// .pipe(w3cjs( W3C_OPTIONS ))
.pipe(gulp.dest(build.templates.pages))
;
});
// JADE
gulp.task('templates:views', function() {
return gulp.src(source.templates.views.files)
//.pipe(changed(build.templates.views, { extension: '.html' }))
//.pipe(jade())
//.on("error", handleError)
//.pipe(prettify({
// indent_char: ' ',
// indent_size: 3,
// unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u']
//}))
// .pipe(htmlify({
// customPrefixes: ['ui-']
// }))
// .pipe(w3cjs( W3C_OPTIONS ))
.pipe(gulp.dest(build.templates.views))
;
});
gulp.task('version', function(){
var dte = new Date().getTime();
gutil.log(gutil.colors.cyan('*******Anurag-Pal*****'));
/* gulp.src([build.scripts.app.dir + '/' +build.scripts.app.main])
.pipe(replace('{{{currentVersion}}}', dte))
.pipe(gulp.dest(build.scripts.app.dir)); */
});
//---------------
// WATCH
//---------------
// Rerun the task when a file changes
gulp.task('watch', function() {
livereload.listen();
gulp.watch(source.scripts.watch, ['scripts:app', 'version']);
gulp.watch(source.styles.app.watch, ['styles:app', 'styles:app:rtl']);
gulp.watch(source.styles.themes.watch, ['styles:themes']);
gulp.watch(source.bootstrap.watch, ['styles:app']); //bootstrap
gulp.watch(source.templates.pages.watch, ['templates:pages']);
gulp.watch(source.templates.views.watch, ['templates:views']);
gulp.watch(source.templates.app.watch, ['templates:app']);
gulp.watch([
'assets/**'
]).on('change', function(event) {
livereload.changed( event.path );
});
});
//---------------
// DEFAULT TASK
//---------------
// build for production (minify)
gulp.task('build', ['prod', 'default']);
gulp.task('prod', function() { isProduction = true; });
// build with sourcemaps (no minify)
gulp.task('sourcemaps', ['usesources', 'default']);
gulp.task('usesources', function(){ useSourceMaps = true; });
// default (no minify)
gulp.task('default', gulpsync.sync([
'scripts:vendor',
'scripts:app',
'start',
'version'
]), function(){
gutil.log(gutil.colors.cyan('************'));
gutil.log(gutil.colors.cyan('* All Done *'), 'You can start editing your code, LiveReload will update your browser after any change..');
gutil.log(gutil.colors.cyan('************'));
});
gulp.task('start',[
'styles:app',
'styles:app:rtl',
'styles:themes',
'templates:app',
'templates:pages',
'templates:views',
'watch'
]);
gulp.task('done', function(){
console.log('All Done!! You can start editing your code, LiveReload will update your browser after any change..');
});
// Error handler
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
// Mini gulp plugin to flip css (rtl)
function flipcss(opt) {
if (!opt) opt = {};
// creating a stream through which each file will pass
var stream = through.obj(function(file, enc, cb) {
if(file.isNull()) return cb(null, file);
if(file.isStream()) {
console.log("todo: isStream!");
}
var flippedCss = flip(String(file.contents), opt);
file.contents = new Buffer(flippedCss);
cb(null, file);
});
// returning the file stream
return stream;
}