forked from 18F/fedramp-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
313 lines (290 loc) · 9.05 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
var gulp = require('gulp');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var del = require('del');
var zip = require('gulp-zip');
var tar = require('gulp-tar');
var gzip = require('gulp-gzip');
var templateCache = require('gulp-angular-templatecache');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var karma = require('karma');
// Filename for final minified javascript file
var concatOutputFilename = 'fedramp.js';
/**
* Deletes the build/ directory to ensure a clean start
*/
gulp.task('clean:all', function () {
'use strict';
console.log('Blowing away the build artifacts');
return del(['build', 'fonts', 'img', 'css', 'dist']);
});
/**
* Removes artifacts not necessary for a release
*/
gulp.task('clean:release', ['mangle'], function () {
'use strict';
console.log('Removing development files');
return del([
'dist/coverage/',
'dist/doc/',
'dist/test/'
]);
});
/**
* Compile SASS
*/
gulp.task('sass', function () {
'use strict';
return gulp
.src([
'node_modules/font-awesome/**/*.scss',
'node_modules/uswds/src/stylesheets/**/*.scss',
'src/sass/**/*.scss'
])
.pipe(sass.sync().on('error', sass.logError))
.pipe(cleanCSS())
.pipe(concat('fedramp.css'))
.pipe(gulp.dest('dist/css'));
});
/**
* Copies all source files over to build/src.
*/
gulp.task('copy:src', ['clean:all'], function () {
'use strict';
console.log('Copying over all of the source files');
return gulp
.src(['src/**/*'])
.pipe(gulp.dest('build/src'));
});
/**
* Copies the necessary production libs
*/
gulp.task('copy:lib', ['clean:all'], function () {
'use strict';
console.log('Copying over all of the lib files');
return gulp
.src([
'node_modules/babel-polyfill/dist/*.min.js',
'node_modules/angular/angular.min.js',
'node_modules/angular-ui-router/release/*.min.js',
'node_modules/angular-aria/*.min.js',
'node_modules/angular-sticky-top/*.min.js',
'node_modules/jasmine-core/lib/jasmine-core/jasmine.js',
'node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js',
'node_modules/jasmine-core/lib/jasmine-core/boot.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/papaparse/papaparse.min.js',
'node_modules/showdown/dist/*.min.js',
'node_modules/uswds/dist/js/*.min.js'
])
.pipe(gulp.dest('build/lib'));
});
gulp.task('copy:test', ['clean:all'], function () {
'use strict';
console.log('Copying over all of the lib files');
return gulp
.src([
'test/**/*',
'node_modules/jasmine-core/lib/jasmine-core/jasmine.css'
])
.pipe(gulp.dest('dist/test'));
});
/**
* Copies over all font resources
*/
gulp.task('copy:fonts', ['clean:all'], function () {
'use strict';
console.log('Copying over all of the font files');
return gulp
.src([
'node_modules/uswds/dist/fonts/**/*',
'node_modules/font-awesome/fonts/**/*'
])
.pipe(gulp.dest('dist/fonts'));
});
/**
* Copies over all image resources
*/
gulp.task('copy:images', ['clean:all'], function () {
'use strict';
console.log('Copying over all of the image files');
return gulp
.src([
'node_modules/uswds/dist/img/**/*',
'src/img/**/*'
])
.pipe(gulp.dest('dist/img'));
});
/**
* Runs the linter (jshint) on all the source files
*/
gulp.task('copy:lint', ['copy:src'], function () {
'use strict';
console.log('Linting dev JS files');
return gulp
.src([
'build/src/**/*.js',
])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
// Ensure build fails and linter complains
//.pipe(jshint.reporter('fail'));
});
/**
* Finds all templates and creates a file containing the contents of each template in
* an angular module.
* Requires the `copy` build task to finish
*/
gulp.task('templates:cache', ['copy'], function () {
'use strict';
console.log('Caching angular templates');
return gulp
.src([
'!build/src/index.html',
'build/src/**/*.html'
])
.pipe(templateCache({
module: 'fedramp',
filename: 'fedramp.templates.js'
}))
.pipe(gulp.dest('build/src'));
});
/**
* Concatenates all the minified application javascript files from /build/src.min
* into one file.
**/
gulp.task('mangle:concat', ['templates'], function () {
'use strict';
console.log('Concatenating JS files');
return gulp
.src([
'build/src/**/*.module.js',
'build/src/**/*.js'
])
.pipe(concat(concatOutputFilename))
.pipe(gulp.dest('build/'));
});
gulp.task('mangle:babel', ['mangle:concat'], function () {
'use strict';
return gulp
.src('build/' + concatOutputFilename)
.pipe(babel({ presets: ['es2015'] }))
.pipe(gulp.dest('build/'));
});
/**
* Concatenate the minified application source with the libraries
*/
gulp.task('mangle:concat-test', ['mangle:babel'], function () {
'use strict';
console.log('Concatenating JS files');
return gulp
.src([
'build/lib/jasmine.js',
'build/lib/jasmine-html.js',
'build/lib/boot.js',
'build/lib/polyfill.min.js',
'test/blanket.min.js',
'test/jasmine-blanket.js',
'build/lib/angular.min.js',
'build/lib/angular-ui-router.min.js',
'build/lib/angular-aria.min.js',
'build/lib/angular-sticky.min.js',
'build/lib/angular-mocks.js',
'build/lib/papaparse.min.js',
'build/lib/showdown.min.js',
'build/lib/uswds.min.js'
])
.pipe(concat('fedramp.test.js'))
.pipe(gulp.dest('build/'));
});
/**
* Minifies all individual javascript files
*/
gulp.task('mangle:uglify', ['mangle:babel'], function () {
'use strict';
console.log('Uglifying js files');
return gulp
.src(['build/' + concatOutputFilename])
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest('build/'));
});
/**
* Concatenate the minified application source with the libraries
*/
gulp.task('mangle:concat-libs', ['mangle:uglify'], function () {
'use strict';
console.log('Concatenating JS files');
return gulp
.src([
'build/lib/polyfill.min.js',
'build/lib/angular.min.js',
'build/lib/angular-ui-router.min.js',
'build/lib/angular-aria.min.js',
'build/lib/angular-sticky.min.js',
'build/lib/papaparse.min.js',
'build/lib/showdown.min.js',
'build/lib/uswds.min.js',
'build/fedramp.min.js'
])
.pipe(concat('fedramp.min.js'))
.pipe(gulp.dest('build/'));
});
/**
* Copy compiled and minified source to dist/
*/
gulp.task('mangle:copy', ['mangle:concat-libs'], function () {
'use strict';
return gulp
.src([
'build/fedramp.min.js',
'build/src/index.html',
'build/src/robots.txt'
])
.pipe(gulp.dest('dist/'));
});
/**
* Copy compiled and minified source to dist/test/
*/
gulp.task('mangle:copy-test', ['mangle:concat-libs'], function () {
'use strict';
return gulp
.src([
'build/fedramp.js',
'build/fedramp.test.js'
])
.pipe(gulp.dest('dist/test/'));
});
gulp.task('test', ['default'], function (done) {
'use strict';
new karma.Server(
{
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done)
.start();
});
/**
* Watch specific files to trigger builds during development
*/
gulp.task('watch:dog', [], function () {
'use strict';
console.log('Watch dog, ARF ARF!!!');
gulp.watch('src/**/*.js', ['default', 'test']);
gulp.watch('src/**/*.html', ['default', 'test']);
gulp.watch('src/**/*.scss', ['default', 'test']);
gulp.watch('test/**/*.js', ['default', 'test']);
});
// Creates sub-tasks
gulp.task('mangle', ['mangle:concat', 'mangle:babel', 'mangle:concat-test', 'mangle:uglify', 'mangle:concat-libs', 'mangle:copy', 'mangle:copy-test']);
gulp.task('templates', ['templates:cache']);
gulp.task('copy', ['copy:src', 'copy:lib', 'copy:test', 'copy:fonts', 'copy:images', 'copy:lint']);
// Default is the 'main' task that gets executed when you simply run `gulp`
gulp.task('default', ['clean:all', 'sass', 'copy', 'templates', 'mangle']);
gulp.task('package', ['clean:all', 'sass', 'copy', 'templates', 'mangle', 'clean:release']);
gulp.task('watch', ['watch:dog']);