-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
272 lines (238 loc) · 7.62 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
'use strict';
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const gulpNgConfig = require('gulp-ng-config');
const size = require('gulp-size');
const templateCache = require('gulp-angular-templatecache');
const RevAll = require('gulp-rev-all');
const runSequence = require('run-sequence');
const del = require('del');
const gutil = require('gulp-util');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const SOURCE_PATH = 'src';
const BUILD_PATH = 'build';
const DIST_PATH = 'dist';
// Use command line flag to trigger this, eg. 'gulp build --production'
const isProduction = gutil.env.production ? true : false;
const buildDestinationPath = gutil.env.production || gutil.env.qa ? DIST_PATH : BUILD_PATH;
const config = {
assets: {
appHtmlSrc: [
SOURCE_PATH + '/app/**/*.html'
],
// App app javascript source
appSrc: [
SOURCE_PATH + '/app/**/*.js'
],
// App style source
appStyleSrc: [
'node_modules/bootstrap-sass/assets/stylesheets/*.scss',
'node_modules/font-awesome/scss/**/*.scss',
SOURCE_PATH + '/app/scss/main.scss'
],
// Dependencies
libSrc: [
'node_modules/jquery/dist/jquery.js',
'node_modules/bluebird/js/browser/bluebird.js',
'node_modules/angular/angular.js',
'node_modules/angular-animate/angular-animate.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
'node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
'node_modules/angular-sanitize/angular-sanitize.js',
'node_modules/angular-ui-router/release/angular-ui-router.js',
'node_modules/ng-tags-input/build/ng-tags-input.js',
'node_modules/ui-select/dist/select.js',
'node_modules/angular-touch/angular-touch.js',
'node_modules/ng-csv/build/ng-csv.js'
],
// Define lib styles here
libStyleSrc: [
'node_modules/ui-select/dist/select.css',
'node_modules/ng-tags-input/build/ng-tags-input.css',
'node_modules/ng-tags-input/build/ng-tags-input.bootstrap.css'
],
// Define path for fonts
fontSrc: [
SOURCE_PATH + '/assets/fonts/*',
SOURCE_PATH + '/**/*.ttf',
'node_modules/font-awesome/fonts/**/*'
],
// Define path for images
imageSrc: [
SOURCE_PATH + '/assets/img/*'
],
rootAssetSrc: [
SOURCE_PATH + '/assets/root/*'
],
// Bundle files
appScriptsBundleFileSrc: buildDestinationPath + '/js/app-bundle.js',
libScriptsBundleFileSrc: buildDestinationPath + '/js/lib-bundle.js',
appStylesBundleFileSrc: buildDestinationPath + '/css/style-bundle.css',
libStylesBundleFileSrc: buildDestinationPath + '/css/libstyle-bundle.css'
}
};
// Files to revision
var revSourceFiles = [
config.assets.appScriptsBundleFileSrc,
config.assets.libScriptsBundleFileSrc,
config.assets.libStylesBundleFileSrc,
config.assets.appStylesBundleFileSrc
];
// Renames files after build
gulp.task('rev-all', function (callback) {
if (isProduction === false) {
return gutil.noop();
}
var revAll = new RevAll({
dontRenameFile: ['index.html', 'config.js'],
dontUpdateReference: ['index.html', 'config.js']
});
return gulp.src(
revSourceFiles
.concat(buildDestinationPath + '/index.html')
.concat(buildDestinationPath + '/config.js')
)
.pipe(revAll.revision())
.pipe(size({
title: 'rev'
}))
.pipe(gulp.dest(buildDestinationPath));
});
gulp.task('templatecache', function () {
return gulp.src(config.assets.appHtmlSrc)
.pipe(size({
title: 'html'
}))
.pipe(templateCache({
standalone: true
}))
.pipe(gulp.dest(SOURCE_PATH + '/app'));
});
// Copy additional html files
gulp.task('html', function () {
return gulp.src([SOURCE_PATH + '/index.html', SOURCE_PATH + '/config.js'])
.pipe(gulp.dest(buildDestinationPath))
.on('error', function(e) {
gutil.log(e);
});
});
// Deletes all files generated in the build
gulp.task('clean', [], function () {
return del([buildDestinationPath]);
});
gulp.task('del-lib-js', function () {
return del([config.assets.libScriptsBundleFileSrc]);
});
gulp.task('del-app-js', function () {
return del([config.assets.appScriptsBundleFileSrc]);
});
gulp.task('del-app-css', function () {
return del([config.assets.appStylesBundleFileSrc]);
});
gulp.task('del-lib-css', function () {
return del([config.assets.libStylesBundleFileSrc]);
});
gulp.task('app-js', function () {
return gulp.src(config.assets.appSrc)
.pipe(isProduction ? sourcemaps.init() : gutil.noop())
.pipe(
babel({ presets: ['es2015'], comments: false })
.on('error', function(e) {
gutil.log(e);
})
)
.pipe(concat('app-bundle.js'))
.pipe(isProduction ? uglify().on('error', function(e) {
gutil.log(e);
}) : gutil.noop())
.pipe(isProduction ? sourcemaps.write('/') : gutil.noop())
.pipe(gulp.dest(buildDestinationPath + '/js'))
.on('error', function(e) {
gutil.log(e);
});
});
gulp.task('app-css', function () {
return gulp.src(config.assets.appStyleSrc)
.pipe(sass().on('error', sass.logError))
.pipe(concat('style-bundle.css'))
.pipe(isProduction ? cleanCSS().on('error', function(e) {
gutil.log(e);
}) : gutil.noop())
.pipe(gulp.dest(buildDestinationPath + '/css'));
});
gulp.task('lib-js', function () {
return gulp.src(config.assets.libSrc)
.pipe(isProduction ? sourcemaps.init() : gutil.noop())
.pipe(concat('lib-bundle.js'))
.pipe(isProduction ? uglify().on('error', function(e) {
gutil.log(e);
}) : gutil.noop())
.pipe(isProduction ? sourcemaps.write('/') : gutil.noop())
.pipe(gulp.dest(buildDestinationPath + '/js'));
});
gulp.task('lib-css', [], function () {
return gulp.src(config.assets.libStyleSrc)
.pipe(concat('libstyle-bundle.css'))
.pipe(isProduction ? cleanCSS().on('error', function(e) {
gutil.log(e);
}) : gutil.noop())
.pipe(gulp.dest(buildDestinationPath + '/css'));
});
gulp.task('fonts', function () {
gulp.src(config.assets.fontSrc)
.pipe(gulp.dest(buildDestinationPath + '/fonts'));
});
gulp.task('images', function () {
gulp.src(config.assets.imageSrc)
.pipe(gulp.dest(buildDestinationPath + '/img'));
});
gulp.task('rootAssets', function () {
gulp.src(config.assets.rootAssetSrc)
.pipe(gulp.dest(buildDestinationPath + '/'));
});
gulp.task('generate-config', () => {
let environment = isProduction ? 'production' : 'development';
if (gutil.env.qa) {
environment = 'qa';
}
gutil.log(gutil.colors.yellow(`Generating app config for ${environment} environment`));
gulp.src(SOURCE_PATH + '/environment_config.json')
.pipe(gulpNgConfig('appConfig', { environment: environment }))
.pipe(gulp.dest(SOURCE_PATH + '/app/js'))
.on('error', function(e) {
gutil.log(e);
});
});
gulp.task('build', function (callback) {
runSequence(
'clean',
'generate-config',
'templatecache',
['app-js', 'lib-js', 'app-css', 'lib-css', 'fonts', 'images', 'rootAssets', 'html'],
'rev-all',
callback
);
});
gulp.task('watch', function () {
gulp.watch('./src/**/*.html', ['default']);
gulp.watch('./src/**/*.js', ['app-js']);
gulp.watch('./src/**/*.scss', ['app-css']);
});
gulp.task('dev', function () {
runSequence(
'clean',
'generate-config',
'templatecache',
['app-js', 'lib-js', 'app-css', 'lib-css', 'fonts', 'images', 'rootAssets', 'html'],
'watch',
function() {
gutil.log(gutil.colors.green('Build successful, waiting for changes...'));
}
);
});
// Set a default task
gulp.task('default', ['dev']);