-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·405 lines (353 loc) · 11.1 KB
/
gulpfile.js
File metadata and controls
executable file
·405 lines (353 loc) · 11.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
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
'use strict';
var fs = require('fs');
var config = require('./build/build.config.js');
var protractorConfig = require('./build/protractor.config.js');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var pkg = require('./package');
var karma = require('karma').server;
var del = require('del');
var url = require('url');
var proxy = require('proxy-middleware');
var filelog = require('gulp-filelog');
var replace = require('gulp-replace-task');
var minifyCSS = require('gulp-minify-css');
var rsync = require('gulp-rsync');
var confirm = require('gulp-confirm');
var _ = require('lodash');
var backandSync = require('./node_modules/backand/lib/api/backand-sync-s3');
var sassVariables = require('gulp-sass-variables');
var ngConstant = require('gulp-ng-constant');
var argv = require('yargs').argv;
var es = require('event-stream');
/* jshint camelcase:false*/
var webdriverStandalone = require('gulp-protractor').webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;
var currEnv = 'dev';
var assets_path;
//update webdriver if necessary, this task will be used by e2e task
gulp.task('webdriver:update', webdriverUpdate);
// run unit tests and watch files
gulp.task('tdd', function () {
karma.start(karmaConfig);
});
// run unit tests with travis CI
gulp.task('travis', ['build'], function (cb) {
karma.start(_.assign({}, karmaConfig, {
singleRun: true,
browsers: ['PhantomJS']
}), cb);
});
// optimize images and put them in the dist folder
gulp.task('images', function () {
return gulp.src(config.images)
.pipe($.imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.dist + '/assets/images'))
.pipe($.size({
title: 'images'
}));
});
//generate angular templates using html2js
gulp.task('templates', function () {
return gulp.src(config.tpl)
.pipe($.changed(config.tmp))
.pipe($.html2js('templates.js', {
adapter: 'angular',
name: 'templates',
base: 'client',
useStrict: true
}))
.pipe(filelog())
.pipe(gulp.dest(config.tmp))
.pipe($.size({
title: 'templates'
}));
});
//generate css files from scss sources
gulp.task('sass', function () {
return gulp.src(config.mainScss)
.pipe(sassVariables({
$assets_path: assets_path
}))
.pipe($.sass({
includePaths: [
process.cwd() + '/client/vendor/bootstrap-sass-official/assets/stylesheets'
]
}).on('error', $.sass.logError))
// .pipe($.rubySass({
// loadPath: [
// process.cwd() + '/client/vendor/bootstrap-sass-official/assets/stylesheets'
// ]
// }))
// .on('error', function(err) {
// console.log(err.message);
// })
.pipe(gulp.dest(config.tmp))
.pipe($.size({
title: 'sass'
}));
});
//build files for creating a dist release
gulp.task('build:dist', ['clean'], function (cb) {
runSequence(['build', 'copy', 'images'], 'html', cb);
});
//build files for development
gulp.task('build', ['clean'], function (cb) {
runSequence(['configAssetsPath', 'sass', 'templates'], cb);
});
//generate a minified css files, 2 js file, change theirs name to be unique, and generate sourcemaps
gulp.task('html', function () {
var assets = $.useref.assets({
searchPath: '{build,client}'
});
return gulp.src(config.index)
.pipe(assets)
.pipe($.if(currEnv != 'prod', $.sourcemaps.init()))
.pipe($.if('**/*main.js', $.ngAnnotate()))
.pipe($.if('*.js', $.uglify({
mangle: false,
})))
.pipe($.if('*.css', $.csso()))
.pipe($.if(['**/*main.js', '**/*main.css'], $.header(config.banner, {
pkg: pkg
})))
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe($.if('*.html', $.minifyHtml({
empty: true
})))
.pipe($.if(currEnv != 'prod', $.sourcemaps.write()))
.pipe(filelog())
.pipe($.if('*.css', $.if(currEnv == 'prod', minifyCSS())))
.pipe(gulp.dest(config.dist))
.pipe($.size({
title: 'html'
}));
});
//copy fonts
gulp.task('copy:fonts', function () {
return es.merge(
gulp.src([config.assets + '/fonts/**'], {
dot: true
}).pipe(gulp.dest(config.dist + '/assets/fonts'))
.pipe($.size({
title: 'copy:fonts'
})),
gulp.src([config.vendor + 'angular-ui-grid/*.{woff,woff2,svg,ttf,eot,otf}'], {
dot: true
})
.pipe(gulp.dest(config.dist + '/assets/css'))
);
});
//copy assets in dist folder
gulp.task('copy', ['copy:fonts', 'copy:extra', 'copy:envConfig'], function () {
return es.merge(gulp.src([
config.base + '/*',
'!' + config.base + '/*.html',
'!' + config.base + '/src',
'!' + config.base + '/test'
]).pipe(gulp.dest(config.dist))
.pipe($.size({
title: 'copy'
})),
gulp.src([
config.base + '/common/plugins/ace/*.{js,json}',
'!' + config.base + '/common/plugins/ace/{ace.js, theme-monokai.js, mode-javascript.js}'
]).pipe(gulp.dest(config.dist))
.pipe($.size({
title: 'copy editor files'
})));
});
gulp.task('copy:extra', function () {
gulp.src([
config.base + '/views/database/db_templates/*',
config.base + '/vendor/zeroclipboard/dist/*'
], { base: config.base })
.pipe(gulp.dest(config.dist));
});
/**
* copy env configuration file in /dist
* configuration can be changed in this file
* Purpose to do this is to make configuration dynamic and use can change config after build
*/
gulp.task('copy:envConfig', function () {
gulp.src([
config.base + '/config/env/' + currEnv + '.json'
], {
base: config.base, dot: true
})
.pipe(gulp.dest(config.dist));
});
//clean temporary directories
gulp.task('clean', del.bind(null, [config.dist, config.tmp]));
//lint files
gulp.task('jshint', function () {
return gulp.src(config.js)
.pipe(reload({
stream: true,
once: true
}))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});
/* tasks supposed to be public */
//default task
gulp.task('default', ['serve']); //
//run unit tests and exit
gulp.task('test:unit', ['build'], function (cb) {
karma.start(_.assign({}, karmaConfig, {
singleRun: true
}), cb);
});
// Run e2e tests using protractor, make sure serve task is running.
gulp.task('test:e2e', ['webdriver:update'], function () {
return gulp.src(protractorConfig.config.specs)
.pipe($.protractor.protractor({
configFile: 'build/protractor.config.js'
}))
.on('error', function (e) {
throw e;
});
});
//run the server, watch for file changes and redo tests.
gulp.task('serve:tdd', function (cb) {
runSequence(['serve', 'tdd']);
});
//run the server after having built generated files, and watch for changes
gulp.task('serve', ['env:dev', 'build'], function () {
//var proxyOptions = url.parse('http://api.backand.info:8099');
var proxyOptions = url.parse('https://api.backand.co');
proxyOptions.route = '/api';
browserSync({
browser: ['google chrome'],
notify: false,
port: 3001,
ghostMode: false,
logPrefix: pkg.name,
server: {
baseDir: ['build', 'client'],
middleware: [proxy(proxyOptions)]
}
});
gulp.watch(config.html, reload);
gulp.watch(config.scss, ['sass', reload]);
gulp.watch(config.js, ['jshint']);
gulp.watch(config.tpl, ['templates', reload]);
gulp.watch(config.assets, reload);
});
//run the server after having built generated files, and watch for changes
gulp.task('serve:prod', ['env:prod', 'configAssetsPath', 'build'], function () {
//var proxyOptions = url.parse('http://api.backand.info:8099');
var proxyOptions = url.parse('https://api.backand.com');
proxyOptions.route = '/api';
browserSync({
browser: ['google chrome'],
notify: false,
port: 3001,
ghostMode: false,
logPrefix: pkg.name,
server: {
baseDir: ['build', 'client'],
middleware: [proxy(proxyOptions)]
}
});
gulp.watch(config.html, reload);
gulp.watch(config.scss, ['sass', reload]);
gulp.watch(config.js, ['jshint']);
gulp.watch(config.tpl, ['templates', reload]);
gulp.watch(config.assets, reload);
});
//run the app packed in the dist folder
gulp.task('serve:dist', ['serve:deploy'], function () {
browserSync({
notify: false,
server: [config.dist]
});
});
gulp.task('serve:deploy', ['env:prod', 'configAssetsPath', 'build:dist'], function () {
});
//run the dev in the dist folder
gulp.task('dev:dist', ['configAssetsPath', 'env:dev', 'build:dist'], function () {
browserSync({
notify: false,
server: [config.dist]
});
});
//run the local in the dist folder
gulp.task('local:dist', ['env:local', 'build:dist'], function () {
browserSync({
notify: false,
server: [config.dist]
});
//return backandSync.dist(config.dist, 'bklocal');
//backand sync --app bklocal --master 2021e4b3-50e1-4e24-8ff0-f512e13b6e51 --user ff46366b-840f-11e6-8eff-0e00ae4d21e3 --folder /Users/itay/dev/cloudservice-baas/build/dist
});
gulp.task('local', ['configAssetsPath'], function () {
return backandSync.dist(config.dist, 'bklocal');
//backand sync --app bklocal --master 2021e4b3-50e1-4e24-8ff0-f512e13b6e51 --user ff46366b-840f-11e6-8eff-0e00ae4d21e3 --folder /Users/itay/dev/cloudservice-baas/build/dist
});
//run the Blue in the dist folder
gulp.task('blue:dist', ['configAssetsPath', 'env:blue', 'build:dist'], function () {
// browserSync({
// notify: false,
// server: [config.dist]
// });
//backand sync --app blue --master 229e14c2-9229-4f9e-9908-5bd41d8bddaf --user e6b8e25f-6eb3-4919-a44f-91c95f480cf8 --folder /Users/itay/dev/cloudservice-baas/build/dist
});
//deploy the code into production
gulp.task('qa:deploy', ['sts'], function () {
//backand sync --app qa1 --master 9b37748c-0646-40da-9100-59a86d4c7da4 --user d94c5b9e-9f2a-11e5-be83-0ed7053426cb --folder /Users/itay/dev/cloudservice-baas/build/dist
return backandSync.dist(config.dist, 'qa1');
});
//deploy the code into production
gulp.task('qa:dist', ['setAssetsPath', 'env:dev', 'build:dist'], function () {
return backandSync.dist(config.dist, 'qa1');
});
gulp.task('prod:dist', ['env:prod', 'build:dist']);
gulp.task('sts', function () {
var username = "9b37748c-0646-40da-9100-59a86d4c7da4";
var password = "d94c5b9e-9f2a-11e5-be83-0ed7053426cb";
return backandSync.sts(username, password);
});
function setEnv(env) {
currEnv = env;
}
function setAssetsPath() {
var gtask = argv._[0],
constants;
assets_path = _.startsWith(gtask, 'serve') ? '/assets/' : '../';
constants = { assets_path: assets_path, env: currEnv };
return ngConstant({
name: 'backand.ENV_CONFIG',
constants: constants,
template: config.constantTemplate,
stream: true,
wrap: false
})
//.rename('app.constants.js'),
.pipe(gulp.dest(config.consts));
}
gulp.task('configAssetsPath', function () {
setAssetsPath();
});
gulp.task('env:dev', function () {
setEnv('dev');
});
gulp.task('env:prod', function () {
setEnv('prod');
});
gulp.task('env:local', function () {
setEnv('local');
});
gulp.task('env:blue', function () {
setEnv('blue');
});