forked from exiletrade/exiletrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
396 lines (344 loc) · 13.2 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
// FOUNDATION FOR APPS TEMPLATE GULPFILE
// -------------------------------------
// This file processes all of the assets in the "client" folder, combines them with the Foundation for Apps assets, and outputs the finished files in the "build" folder as a finished app.
// 1. LIBRARIES
// - - - - - - - - - - - - - - -
var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var gulp = require('gulp');
var rimraf = require('rimraf');
var gulpRimraf = require('gulp-rimraf');
var router = require('front-router');
var sequence = require('run-sequence');
var ignore = require('gulp-ignore');
var download = require('download-file');
var replace = require('gulp-replace-task');
var concatenate = require('gulp-concat');
var notify = require('gulp-notify');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var gitStaged = require("gulp-git-staged");
var gitmodified = require('gulp-gitmodified');
var gulpUglify = require('gulp-uglify');
var rename = require("gulp-rename");
// Check for --production flag
var isProduction = !!(argv.production);
// Check for --demo flag
var isDemo = !!(argv.demo);
var destination = (isDemo ? './demo' : './build' );
var destinationDemo = '../exiletrade.github.io';
var routerPath = (isDemo ? 'demo' : 'build' );
// 2. FILE PATHS
// - - - - - - - - - - - - - - -
var paths = {
assets: [
'./client/**/*.*',
'!./client/templates/**/*.*',
'!./client/assets/{scss,js}/**/*.*'
],
// Sass will check these folders for files when you use @import.
sass: [
'client/assets/scss',
'bower_components/foundation-apps/scss'
],
// These files include Foundation for Apps and its dependencies
foundationJS: [
'bower_components/fastclick/lib/fastclick.js',
'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
'bower_components/tether/tether.min.js',
'bower_components/hammerjs/hammer.js',
//'node_modules/clipboard/clipboard.js',
'bower_components/jquery/dist/jquery.min.js',
'bower_components/angular/angular.min.js',
'bower_components/angular-animate/angular-animate.min.js',
'bower_components/angular-ui-router/release/angular-ui-router.min.js',
'bower_components/angular-scroll/angular-scroll.min.js',
'bower_components/ng-file-upload-shim/ng-file-upload-shim.min.js',
'bower_components/ng-file-upload/ng-file-upload.min.js',
'bower_components/favico.js/favico.js',
'bower_components/foundation-apps/js/vendor/**/*.js',
'bower_components/foundation-apps/js/angular/**/*.js',
'!bower_components/foundation-apps/js/angular/app.js',
//'bower_components/elasticsearch/elasticsearch.angular.js',
'node_modules/js-yaml/dist/js-yaml.min.js',
'node_modules/ngclipboard/dist/ngclipboard.js',
'node_modules/angular-cache/dist/angular-cache.min.js',
'node_modules/spin.js/spin.js',
'node_modules/angular-spinner/angular-spinner.js',
'bower_components/angular-mass-autocomplete/massautocomplete.js',
'node_modules/ng-focus-if/focusIf.js'
],
// These files are for your app's JavaScript
appJS: [
'client/assets/js/affixes.js',
'client/assets/js/fm.js',
(isDemo || isProduction) ? '' : 'client/assets/js/debug.js',
'client/assets/js/app.js'
],
vendorJS: [
'bower_components/fuck-adblock/fuckadblock.js',
],
spreadsheet_urls : [
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=675822745",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=40738669",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=244311060",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=1965399973",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=1443807460",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=57824604",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=224979895",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=14190859",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=154866940",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=583395837",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=380600191",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=739334965",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=1985025128",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=550808329",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=1782931570",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=223573764",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=207179951",
"https://docs.google.com/spreadsheets/d/1jG2gzYuAukoJtYonlWghbkk9m5W6yGzM21cscpqJ5TU/gviz/tq?tq=SELECT+A,+B,+C,+D,+E&headers=1&gid=1732537543"
]
};
// 3. TASKS
// - - - - - - - - - - - - - - -
// Cleans the build directory
gulp.task('clean', function (cb) {
if (!isDemo) {
rimraf(destination, cb);
}
else {
return gulp.src('../exiletrade.github.io/**/*', {read: false})
.pipe(ignore('.git/**'))
.pipe(ignore('.gitignore'))
.pipe(gulpRimraf({force: true}));
cb();
}
});
// Copies everything in the client folder except templates, Sass, and JS
gulp.task('copy', ['copy:vendorJS'], function () {
return gulp.src(paths.assets, {
base: './client/'
})
.pipe(gulp.dest(destination));
});
// Copy vendor js (without concatenating it to some other files)
// has to be changed to work with multiple files
gulp.task('copy:vendorJS', function () {
return gulp.src(paths.vendorJS)
.pipe($.uglify())
.pipe(rename('ads.js'))
.pipe(gulp.dest(destination + '/assets/js/'));
});
// Copy index
gulp.task('copy:index', function (cb) {
if (isDemo) {
gulp.src('./client/index.html')
.pipe(replace({
patterns: [
{
match: /https:\/\/docs\.google\.com\/spreadsheets\/.*gid=(\d+)/ig,
replacement: './data/speadsheet_gid$1.js'
}
]
}))
.pipe(gulp.dest(destination))
;
}
cb();
});
// Copies your app's page templates and generates URLs for them
gulp.task('copy:templates', function () {
return gulp.src('./client/templates/**/*.html')
.pipe(router({
path: routerPath + '/assets/js/routes.js',
root: 'client'
}))
.pipe(gulp.dest(destination + '/templates'))
;
});
// Compiles the Foundation for Apps directive partials into a single JavaScript file
gulp.task('copy:foundation', function (cb) {
gulp.src('bower_components/foundation-apps/js/angular/components/**/*.html')
.pipe($.ngHtml2js({
prefix: 'components/',
moduleName: 'foundation',
declareModule: false
}))
.pipe($.uglify())
.pipe($.concat('templates.js'))
.pipe(gulp.dest(destination + '/assets/js'))
;
// Iconic SVG icons
gulp.src('./bower_components/foundation-apps/iconic/**/*')
.pipe(gulp.dest(destination + '/assets/img/iconic/'))
;
cb();
});
// Copy images
gulp.task('copy:images', function (cb) {
// Asset icons
gulp.src('./client/assets/img/**/*.+(jpg|jpeg|gif|png|svg)')
.pipe(gulp.dest(destination + '/assets/img/'))
;
cb();
});
// Copy sounds
gulp.task('copy:sound', function (cb) {
gulp.src('./client/assets/sound/**/*.+(mp3|wmv)')
.pipe(gulp.dest(destination + '/assets/sound/'))
;
cb();
});
// Copy downloads
gulp.task('copy:downloads', function (cb) {
gulp.src('./client/download/**/*')
.pipe(gulp.dest(destination + '/download/'))
;
cb();
});
// Copy Demo Build to production repo
gulp.task('copy:build', function (cb) {
if (isDemo) {
gulp.src([
'./demo/**/*',
'LICENSE',
'CNAME',
'README.md',
'!./demo/**/*.psd',
'!./demo/**/{logo_assets,logo_assets/*.*}'
])
.pipe(gulp.dest(destinationDemo));
}
cb();
});
// Compiles Sass
gulp.task('sass', function () {
var minifyCss = $.if(isDemo, $.minifyCss());
return gulp.src('client/assets/scss/app.scss')
.pipe($.sass({
includePaths: paths.sass,
outputStyle: (isProduction ? 'compressed' : 'nested'),
errLogToConsole: true
}))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'ie 10']
}))
.pipe(minifyCss)
.pipe(gulp.dest(destination + '/assets/css/'));
});
// Compiles and copies the Foundation for Apps JavaScript, as well as your app's custom JS
gulp.task('uglify', ['uglify:foundation', 'uglify:app']);
gulp.task('uglify:foundation', function (cb) {
var uglify = $.if(isDemo || isProduction, gulpUglify({"mangle":false})
.on('error', function (e) {
console.log(e);
}));
return gulp.src(paths.foundationJS)
.pipe(uglify)
.pipe($.concat('foundation.js'))
.pipe(gulp.dest(destination + '/assets/js/'));
});
gulp.task('uglify:app', function () {
var uglify = $.if(isDemo || isProduction, gulpUglify({"mangle":false})
.on('error', function (e) {
console.log(e);
}));
if (isProduction || isDemo) {
console.log('Removing all console debug output for production build.');
}
return gulp.src(paths.appJS)
.pipe(uglify)
.pipe($.concat('app.js'))
.pipe(gulp.dest(destination + '/assets/js/'));
});
// js-hint git modified files
// keep in mind linting can occur before data.js is compiled together
gulp.task('lint', function(cb) {
gulp.src(['./client/assets/js/**/*.js', './client/assets/data/**/*.js'])
.pipe(gitmodified('modified'))
.pipe(jscs())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
//.pipe(jshint.reporter('fail')) //uncomment to fail on warning/error
.pipe(notify({
title: 'JSHint <%= file.relative %>',
message: 'jscs/JSHint Passed. Let it fly!'
}));
cb();
});
// js-hint all files
gulp.task('lintAll', function(cb) {
gulp.src(['./client/assets/js/**/*.js', './client/assets/data/**/*.js'])
.pipe(jscs())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
//.pipe(jshint.reporter('fail')) //uncomment to fail on warning/error
.pipe(notify({
title: 'JSHint <%= file.relative %>',
message: 'jscs/JSHint Passed. Let it fly!'
}));
cb();
});
// Downloads spreadsheets and concats them
gulp.task('download', function (cb){
var dataPath = './client/data';
rimraf(dataPath, cb);
var j = 0;
for (var i = 0; i < paths.spreadsheet_urls.length; i++) {
var gidIdx = paths.spreadsheet_urls[i].indexOf("gid=");
var urlLen = paths.spreadsheet_urls[i].length;
var gid = paths.spreadsheet_urls[i].substring(gidIdx + 4, urlLen);
var options = {
directory: dataPath,
filename: "speadsheet_" + gid + ".js"
};
download(paths.spreadsheet_urls[i], options, function(err){
if (err) throw err;
j++;
if (j == paths.spreadsheet_urls.length-1){
console.log('Cleaned Data directory.');
console.log('Waiting for downloads to be finished...');
setTimeout(function(){
console.log('Downloaded Spreadsheets.');
return gulp.src(['./client/assets/js/google.vizualize.query.js', dataPath+'/*.*'])
.pipe(concatenate('data.js'), {newLine: ';'})
.pipe(gulp.dest( destination + '/assets/data/'))
.pipe(gulp.dest( './client/assets/data/'));
}, 2000);
}
})
}
});
// Starts a test server, which you can view at http://localhost:8079
gulp.task('server', ['build'], function () {
gulp.src('./build')
.pipe($.webserver({
port: 8079,
host: 'localhost',
fallback: 'index.html',
livereload: true,
open: true
}))
;
});
// Builds your entire app once, without starting a server
gulp.task('build', function (cb) {
sequence('clean', 'download', ['copy', 'copy:foundation', 'sass', 'uglify'], 'copy:index', 'copy:templates', 'copy:images', 'copy:sound', 'copy:build', 'lint', cb);
});
// Default task: builds your app, starts a server, and recompiles assets when they change
gulp.task('default', ['server'], function () {
// Watch Sass
gulp.watch(['./client/assets/scss/**/*', './scss/**/*'], ['sass']);
// Watch JavaScript
gulp.watch(['./client/assets/js/**/*', './js/**/*'], ['lint', 'uglify:app']);
// Watch static files
gulp.watch(['./client/**/*.*', '!./client/templates/**/*.*', '!./client/assets/{scss,js}/**/*.*'], ['copy']);
// Watch Images
gulp.watch(['./client/assets/img/**/*', './img/**/*.+(jpg|jpeg|gif|png|svg)'], ['copy:images']);
// Watch sound files
gulp.watch(['./client/assets/sound/**/*', './sound/**/*.+(mp3|wmv)'], ['copy:sound']);
// Watch app templates
gulp.watch(['./client/templates/**/*.html'], ['copy:templates']);
// Watch download folder
gulp.watch(['./client/download/**/*', './download/**/*'], ['copy:downloads']);
});