This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
442 lines (362 loc) · 14.4 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
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
442
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var del = require('del');
var es = require('event-stream');
var print = require('gulp-print');
var less = require('gulp-less');
var Q = require('q');
var connect = require('gulp-connect');
var open = require('open');
var mainBowerFiles = require('main-bower-files');
const rev = require('gulp-rev');
//var revDel = require('rev-del');
//revDel({
// oldManifest: 'rev-manifest.json',
// newManifest: { /* a manifest */ },
// suppress: true,
// deleteMapExtensions: true
//});
// == PATH STRINGS ========
var paths = {
scripts: 'src/**/*.js',
appStyles: 'src/css/*.css',
dataDictionary: 'src/datadictionary/**/*',
//vendorStyles: '../bower_components/**/**/**/*.css',
less: 'src/less',
images: 'src/images/**/*',
fonts: ['src/fonts/**/*', 'bower_components/font-awesome/fonts/*'],
index: 'src/index.html',
partials: ['src/component/**/**/*.html', '!src/index.html'],
dev: 'dev',
dist: 'dist',
distScriptsProd: 'dist/scripts',
vendorLibs: 'bower_components'
};
// == PIPE SEGMENTS ========
var pipes = {};
pipes.orderedVendorScripts = function () {
return plugins.order(['jquery.js', 'angular.js', 'leaflet-src.js', 'esri-leaflet.js', 'angular-leaflet-directive.js', 'directives.module.js', 'service.module.js', 'RequestInfo.js', 'HTTPServiceBase.js', 'Delegate.js', 'RequestTransform.js', 'EventManager.js', 'EventArgs.js', 'wimLegend.js','moment.js', 'moment-timezone.js']);
};
//this angularFilesort plugin may not work because each file does not have a uniquely named module(needed, acc. to docs)
pipes.orderedAppScripts = function () {
return plugins.angularFilesort();
};
pipes.minifiedFileName = function () {
return plugins.rename(function (path) {
path.extname = '.min' + path.extname;
});
};
pipes.validatedAppScripts = function () {
return gulp.src(paths.scripts)
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'));
};
pipes.builtAppScriptsDev = function () {
return pipes.validatedAppScripts()
// Comment out line 64 when developing locally
.pipe(rev())
.pipe(gulp.dest(paths.dev));
};
///comments in function are artifacts of old partial scripting using the ng-html2js plugin, now stripped out
pipes.builtAppScriptsProd = function () {
return pipes.validatedAppScripts()
.pipe(pipes.orderedAppScripts())
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('app.min.js'))
.pipe(plugins.uglify({ mangle: false }))
.pipe(plugins.sourcemaps.write())
.pipe(rev())
.pipe(gulp.dest(paths.distScriptsProd));
};
//this actually takes everything listed in the "main" object in the package's bower.json file. not just scripts.
// pipes.builtVendorScriptsDev = function() {
// //return gulp.src(paths.vendorLibs + '/**/**/*')
// return mainBowerFiles().pipe(gulp.dest('dev/bower_components'));
// };
//this does not use the main-bower-files plugin - too messy in real world dev
// pipes.builtVendorScriptsDev = function() {
// return gulp.src(paths.vendorLibs + '/**/**/*')
// .pipe(gulp.dest('dev/bower_components'));
// };
pipes.builtVendorScriptsDev = function () {
return gulp.src(mainBowerFiles())
.pipe(gulp.dest('dev/bower_components'));
};
pipes.builtVendorImagesDev = function () {
//in parens below is filter statement for bowerFiles retrieval
return gulp.src(mainBowerFiles(['images/**', '**/images/**']))
.pipe(gulp.dest('dev/bower_components/images'));
};
pipes.builtVendorImagesProd = function () {
//in parens below is filter statement for bowerFiles retrieval
return gulp.src(mainBowerFiles(['images/**', '**/images/**']))
.pipe(gulp.dest(paths.dist + '/images/'));
};
pipes.builtVendorScriptsProd = function () {
return gulp.src(mainBowerFiles('**/*.js'))
.pipe(pipes.orderedVendorScripts())
//added
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('vendor.min.js'))
.pipe(plugins.uglify({ mangle: false }))
//added
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(paths.distScriptsProd));
};
//checked 5/5 BAD
pipes.validatedPartials = function () {
return gulp.src(paths.partials)
.pipe(plugins.htmlhint({ 'doctype-first': false }))
.pipe(plugins.htmlhint.reporter());
};
pipes.builtPartialsDev = function () {
return pipes.validatedPartials()
.pipe(gulp.dest(paths.dev + '/component'));
};
///adding as new task, to abandon the conversion to scripts
pipes.builtPartialsProd = function () {
return pipes.validatedPartials()
.pipe(gulp.dest(paths.dist + '/component'));
};
///////////////////////////////////////////////
///stripped this out for needless complication. may revisit.
//pipes.scriptedPartials = function() {
// return pipes.validatedPartials()
// .pipe(plugins.htmlhint.failReporter())
// .pipe(plugins.htmlmin({collapseWhitespace: true, removeComments: true}))
// .pipe(plugins.ngHtml2js({
// moduleName: "app",
// declareModule: false
// }));
//};
///stripped out sass compiler - sass not in use
pipes.builtAppStylesDev = function () {
return gulp.src(paths.appStyles)
// Comment out line 154 when developing locally
.pipe(rev())
.pipe(gulp.dest(paths.dev));
};
///updated css minification to use cssnano
pipes.builtAppStylesProd =
function () {
return gulp.src(paths.appStyles)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.cssnano())
.pipe(plugins.sourcemaps.write())
.pipe(pipes.minifiedFileName())
.pipe(rev())
.pipe(gulp.dest(paths.dist));
};
///////////////////////////////////////////////
pipes.builtVendorStylesProd = function () {
return gulp.src(mainBowerFiles('**/*.css'))
//.pipe(pipes.orderedVendorStyles())
.pipe(plugins.concat('vendor.min.css'))
.pipe(gulp.dest(paths.dist + '/css'));
};
////////////////////////////////////////////////////////
pipes.processedImagesDev = function () {
return gulp.src(paths.images)
.pipe(gulp.dest(paths.dev + '/images/'));
};
pipes.processedImagesProd = function () {
return gulp.src(paths.images)
.pipe(gulp.dest(paths.dist + '/images/'));
};
pipes.processedDataDictionaryDev = function () {
return gulp.src(paths.dataDictionary)
.pipe(gulp.dest(paths.dev + '/datadictionary/'));
};
pipes.processedDataDictionaryProd = function () {
return gulp.src(paths.dataDictionary)
.pipe(gulp.dest(paths.dist + '/datadictionary/'));
};
pipes.processedIconsDev = function () {
return gulp.src(paths.fonts)
.pipe(gulp.dest(paths.dev + '/fonts'))
}
pipes.processedIconsProd = function () {
return gulp.src(paths.fonts)
.pipe(gulp.dest(paths.dist + '/fonts'))
}
pipes.validatedIndex = function () {
return gulp.src(paths.index)
.pipe(plugins.htmlhint())
.pipe(plugins.htmlhint.reporter());
};
pipes.builtIndexDev = function () {
var orderedVendorScripts = pipes.builtVendorScriptsDev()
.pipe(pipes.orderedVendorScripts());
var orderedAppScripts = pipes.builtAppScriptsDev()
.pipe(pipes.orderedAppScripts());
//var orderedAppStyles = pipes.orderedAppStyles();
var appStyles = pipes.builtAppStylesDev();
return pipes.validatedIndex()
.pipe(gulp.dest(paths.dev)) // write first to get relative path for inject
.pipe(plugins.inject(orderedVendorScripts, { relative: true, name: 'bower' }))
.pipe(plugins.inject(orderedAppScripts, { relative: true }))
//.pipe(plugins.inject(orderedAppStyles, {relative:true}))
.pipe(plugins.inject(appStyles, { relative: true }))
.pipe(plugins.htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(gulp.dest(paths.dev));
};
pipes.builtIndexProd = function () {
var vendorScripts = pipes.builtVendorScriptsProd();
var appScripts = pipes.builtAppScriptsProd();
var appStyles = pipes.builtAppStylesProd();
var vendorStyles = pipes.builtVendorStylesProd();
return pipes.validatedIndex()
.pipe(gulp.dest(paths.dist)) // write first to get relative path for inject
.pipe(plugins.inject(vendorScripts, { relative: true, name: 'bower' }))
.pipe(plugins.inject(appScripts, { relative: true }))
.pipe(plugins.inject(vendorStyles, { relative: true, name: 'bower' }))
.pipe(plugins.inject(appStyles, { relative: true }))
.pipe(plugins.htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(gulp.dest(paths.dist));
};
pipes.builtAppDev = function () {
return es.merge(pipes.builtIndexDev(), pipes.builtPartialsDev(), pipes.processedImagesDev(), pipes.processedDataDictionaryDev(), pipes.processedIconsDev(), pipes.builtVendorImagesDev());
};
pipes.builtAppProd = function () {
return es.merge(pipes.builtIndexProd(), pipes.builtPartialsProd(), pipes.processedImagesProd(), pipes.processedDataDictionaryProd(), pipes.processedIconsProd(), pipes.builtVendorImagesProd());
};
// == TASKS ========
// removes all compiled dev files
gulp.task('clean-dev', function () {
var deferred = Q.defer();
del(paths.dev, function () {
deferred.resolve();
});
return deferred.promise;
});
// removes all compiled production files
gulp.task('clean-prod', function () {
var deferred = Q.defer();
del(paths.dist, function () {
deferred.resolve();
});
return deferred.promise;
});
gulp.task('images', function () {
return gulp.src([
'src/images/**/*',
'src/lib/images/*'])
.pipe(gulp.dest('build/images'))
.pipe(plugins.size());
});
gulp.task('dataDictionary', function () {
return gulp.src([
'src/datadictionary/**/*'])
.pipe(gulp.dest('build/datadictionary'))
.pipe(plugins.size());
});
// checks html source files for syntax errors
gulp.task('validate-partials', pipes.validatedPartials);
// checks index.html for syntax errors
gulp.task('validate-index', pipes.validatedIndex);
// moves html source files into the dev environment
gulp.task('build-partials-dev', pipes.builtPartialsDev);
// converts partials to javascript using html2js
//gulp.task('convert-partials-to-js', pipes.scriptedPartials);
// moves html partials into production environment (replaces convert-partials-to-js)
gulp.task('build-partials-prod', pipes.builtPartialsProd);
// runs jshint on the dev server scripts
//gulp.task('validate-devserver-scripts', pipes.validatedDevServerScripts);
// runs jshint on the app scripts
gulp.task('validate-app-scripts', pipes.validatedAppScripts);
// moves app scripts into the dev environment
gulp.task('build-app-scripts-dev', pipes.builtAppScriptsDev);
// concatenates, uglifies, and moves app scripts and partials into the prod environment
gulp.task('build-app-scripts-prod', pipes.builtAppScriptsProd);
// compiles app sass and moves to the dev environment
gulp.task('build-app-styles-dev', pipes.builtAppStylesDev);
// compiles and minifies app sass to css and moves to the prod environment
gulp.task('build-app-styles-prod', pipes.builtAppStylesProd);
// compiles and minifies vendor sass to css and moves to the prod environment
gulp.task('build-avendor-styles-prod', pipes.builtVendorStylesProd);
// moves vendor scripts into the dev environment
gulp.task('build-vendor-scripts-dev', pipes.builtVendorScriptsDev);
//moves vendor images into the dev environment
gulp.task('build-vendor-images-dev', pipes.builtVendorImagesDev);
// concatenates, uglifies, and moves vendor scripts into the prod environment
gulp.task('build-vendor-scripts-prod', pipes.builtVendorScriptsProd);
// validates and injects sources into index.html and moves it to the dev environment
gulp.task('build-index-dev', pipes.builtIndexDev);
// validates and injects sources into index.html, minifies and moves it to the dev environment
gulp.task('build-index-prod', pipes.builtIndexProd);
// builds a complete dev environment
gulp.task('build-app-dev', pipes.builtAppDev);
// builds a complete prod environment
gulp.task('build-app-prod', pipes.builtAppProd);
// cleans and builds a complete dev environment
gulp.task('clean-build-app-dev', ['clean-dev'], pipes.builtAppDev);
// cleans and builds a complete prod environment
gulp.task('clean-build-app-prod', ['clean-prod'], pipes.builtAppProd);
// clean, build, and watch live changes to the dev environment
gulp.task('watch-dev', ['build-app-dev'], function () {
connect.server({
root: 'dev',
port: 9000,
livereload: true
});
open("http://localhost:9000");
// watch index
gulp.watch(paths.index, function () {
return pipes.builtIndexDev()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch app scripts
gulp.watch(paths.scripts, function () {
return pipes.builtAppScriptsDev()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch html partials
gulp.watch(paths.partials, function () {
return pipes.builtPartialsDev()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch app styles
gulp.watch(paths.appStyles, function () {
return pipes.builtAppStylesDev()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
});
// clean, build, and watch live changes to the prod environment
gulp.task('watch-prod', ['build-app-prod'], function () {
connect.server({
root: 'dist',
port: 9001,
livereload: true
});
open("http://localhost:9001");
// watch index
gulp.watch(paths.index, function () {
return pipes.builtIndexProd()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch app scripts
gulp.watch(paths.scripts, function () {
return pipes.builtAppScriptsProd()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch html partials
gulp.watch(paths.partials, function () {
return pipes.builtAppScriptsProd()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
// watch app styles
gulp.watch(paths.appStyles, function () {
return pipes.builtAppStylesProd()
//.pipe(plugins.livereload());
.pipe(connect.reload());
});
});
// default task builds for prod
gulp.task('default', ['clean-build-app-prod']);