This repository was archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
318 lines (286 loc) · 9.1 KB
/
gulpfile.js
File metadata and controls
318 lines (286 loc) · 9.1 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
'use strict'
const gulp = require('gulp')
const browserify = require('browserify')
const clean = require('gulp-clean')
const source = require('vinyl-source-stream')
const sass = require('gulp-sass')
const concat = require('gulp-concat')
const watchify = require('watchify')
const runSequence = require('run-sequence')
const gulpif = require('gulp-if')
const buffer = require('vinyl-buffer')
const sourcemaps = require('gulp-sourcemaps')
const templateCache = require('gulp-angular-templatecache')
// Note that we only use harmony for our code (bundle.js) not vendor.js, where we use normal minify
const inlinesource = require('gulp-inline-source')
const gulpProtractor = require('gulp-protractor')
const karma = require('karma')
const stringify = require('stringify')
const sassUnicode = require('gulp-sass-unicode')
const gulpNgConfig = require('gulp-ng-config')
const expect = require('gulp-expect-file')
const terser = require('gulp-terser')
const filePath = {
destination: './dist',
build: {
dest: './dist',
jsDest: './dist/js',
cssDest: './dist/css'
},
browserify: {
src: './app/app.js',
paths: ['./']
},
styles: {
sass: './app/**/*.sass',
src: './app/**/*.scss'
},
templates: {
src: './app/**/*.html'
},
assets: {
src: ['./app/common/assets/**/*', './app/**/*.svg'],
watch: ['./dist/common/assets/', './dist/common/assets/**/*'],
dest: './dist/common/assets/'
},
copyIndex: {
src: './app/index.html',
watch: './app/index.html'
},
copyFonts: {
src: './node_modules/@fortawesome/fontawesome-free/webfonts/*',
dest: './dist/css/fonts'
},
copyFavicon: {
src: './app/common/favicon/*'
},
vendorCSS: {
src: [
'./resources/animate.min.css',
'./node_modules/angular-ui-notification/dist/angular-ui-notification.css',
'./node_modules/ngprogress/ngProgress.css',
'./node_modules/angular-ui-tree/dist/angular-ui-tree.min.css'
]
}
}
function handleError (err) {
console.log(err.toString())
this.emit('end')
}
// =======================================================================
// Browserify Bundle
// =======================================================================
const bundle = {}
bundle.conf = {
entries: filePath.browserify.src,
debug: true,
cache: {},
packageCache: {},
paths: filePath.browserify.paths
}
function dhbrowserify () {
return browserify(bundle.conf).transform(stringify, {appliesTo: {includeExtensions: ['.html']}})
}
function rebundle () {
console.log('bundle started')
return bundle.bundler.bundle()
.pipe(source('bundle.js'))
.on('error', handleError)
.pipe(buffer())
.pipe(gulpif(!bundle.prod, sourcemaps.init({
loadMaps: true
})))
.pipe(gulpif(!bundle.prod, sourcemaps.write('./')))
.pipe(gulpif(bundle.prod, terser({
warnings: true,
mangle: false,
ecma: 6,
compress: {
unused: false,
unsafe_Function: true,
unsafe_math: true,
warnings: true
},
output: {
quote_style: 3,
semicolons: false
}
})))
.pipe(gulp.dest(filePath.build.jsDest))
}
gulp.task('bundle-dev-once', function () {
bundle.bundler = dhbrowserify(bundle.conf)
bundle.prod = false
rebundle()
console.log('bundle finished')
})
gulp.task('bundle-dev', function () {
bundle.bundler = watchify(dhbrowserify(bundle.conf))
bundle.prod = false
bundle.bundler.on('update', rebundle)
bundle.bundler.on('error', handleError)
bundle.bundler.on('time', function (time) {
const text = 'Bundle finished in ' + time / 1000 + ' s'
console.log(text)
})
return rebundle()
})
gulp.task('bundle-prod', function () {
'use strict'
bundle.bundler = dhbrowserify(bundle.conf)
bundle.prod = true
return rebundle()
})
// =======================================================================
// Images Task
// =======================================================================
gulp.task('assets', function () {
return gulp.src(filePath.assets.src)
.on('error', handleError)
.pipe(gulp.dest(filePath.assets.dest))
})
// =======================================================================
// Copy index.html
// =======================================================================
function copyIndex () {
return gulp.src(filePath.copyIndex.src)
.pipe(inlinesource({compress: false}))
.pipe(gulp.dest(filePath.build.dest))
}
gulp.task('copyIndex', copyIndex)
// =======================================================================
// Copy Favicon
// =======================================================================
gulp.task('copyFavicon', function () {
return gulp.src(filePath.copyFavicon.src)
.pipe(gulp.dest(filePath.build.dest))
})
// =======================================================================
// Generate Config file
// =======================================================================
gulp.task('config', () => {
const c = 'config.yml'
return gulp.src(c)
.pipe(expect(c))
.pipe(gulpNgConfig('common.constants', {
environment: ['default', process.env.DH_ENV || 'development'],
parser: 'yml',
createModule: false,
wrap: 'module.exports = <%= module %>'
}))
.pipe(gulp.dest(filePath.destination))
})
// =======================================================================
// Watch for changes
// =======================================================================
gulp.task('watch', function () {
gulp.watch(filePath.styles.sass, ['sass'])
gulp.watch(filePath.styles.src, ['sass'])
gulp.watch(filePath.templates.src, ['templates'])
gulp.watch(filePath.assets.watch, ['assets'])
gulp.watch(filePath.copyIndex.watch, ['copyIndex'])
console.log('Watching...')
})
gulp.task('clean', function () {
return gulp.src(filePath.destination)
.pipe(clean({
force: true
}))
})
gulp.task('templates', function () {
return gulp.src(filePath.templates.src)
.pipe(templateCache('templates.js', {standalone: true, moduleSystem: 'Browserify'}))
.pipe(gulp.dest(filePath.destination))
})
gulp.task('_sass', function () {
return gulp.src([filePath.styles.sass, filePath.styles.src])
.pipe(sass())
// Used to correctly compile glyphicons
// see https://github.com/sass/sass/issues/1395#issuecomment-211974664
.pipe(sassUnicode())
.pipe(concat('app.css'))
.pipe(gulp.dest(filePath.build.cssDest))
})
gulp.task('sass', () => {
runSequence(['_sass'], ['copyIndex'])
})
gulp.task('vendorCSS', function () {
return gulp.src(filePath.vendorCSS.src)
.pipe(concat('vendor.css'))
.on('error', sass.logError)
.pipe(gulp.dest(filePath.build.cssDest))
})
// =======================================================================
// Copy Fonts
// =======================================================================
gulp.task('copyFonts', function () {
return gulp.src(filePath.copyFonts.src)
.pipe(gulp.dest(filePath.copyFonts.dest))
})
// =======================================================================
// Sequential Build Rendering
// =======================================================================
// run "gulp" in terminal to build the DEV app
gulp.task('build-dev', function (callback) {
runSequence(
// images and vendor tasks are removed to speed up build time. Use "gulp build" to do a full
// re-build of the dev app.
['config', 'templates'],
['bundle-dev', '_sass'],
['copyIndex'],
['watch'],
callback
)
})
// run "gulp build" in terminal for a full re-build in DEV
gulp.task('build', function (callback) {
runSequence(
['clean'],
['config', 'templates'],
['bundle-dev', 'vendorCSS', '_sass', 'assets', 'copyFavicon', 'copyFonts', 'copyIndex'],
callback
)
})
// run "gulp prod" in terminal to build the PROD-ready app
gulp.task('build-prod', function (callback) {
runSequence(
['clean'],
['config', 'templates'],
['bundle-prod', 'vendorCSS', '_sass', 'assets', 'copyFavicon', 'copyFonts', 'copyIndex'],
callback
)
})
// =======================================================================
// Documentation
// =======================================================================
gulp.task('docs', [], function () {
const gulpDocs = require('gulp-ngdocs')
return gulp.src('./app/**/*.js')
.pipe(gulpDocs.process())
.pipe(gulp.dest('./docs'))
})
// =======================================================================
// Testing
// =======================================================================
gulp.task('unit-test', done => {
new karma.Server({
configFile: __dirname + '/karma.conf.js'
}, done).start()
})
gulp.task('unit-test-once', done => {
new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start()
})
// =======================================================================
// E2E Testing
// =======================================================================
/**
* Runs the selenium server.
*/
gulp.task('Run Selenium', callback => {
runSequence(['_webdriverUpdate'], ['_runSelenium'], callback)
})
gulp.task('_webdriverUpdate', gulpProtractor.webdriver_update)
gulp.task('_runSelenium', gulpProtractor.webdriver_standalone)