-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
408 lines (333 loc) · 12.8 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
397
398
399
400
401
402
403
404
405
406
407
408
const fs = require('fs');
const autoprefixer = require('gulp-autoprefixer');
const archiver = require('archiver');
const bump = require('gulp-bump');
const babelify = require('babelify');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const clean = require('gulp-clean');
const concat = require('gulp-concat');
const cssnano = require('gulp-cssnano');
const fileinclude = require('gulp-file-include');
const gulp = require('gulp');
const less = require('gulp-less');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber' );
const rename = require('gulp-rename');
const runSequence = require('run-sequence');
const shell = require('gulp-shell');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');
const html2js = require('html2js-browserify');
const app = './app/';
const dist = './dist/';
const dist_CX = './chrome-extension/';
// Error / Success Handling
let onError = function(err) {
notify.onError({
title: "Error: " + err.plugin,
subtitle: "<%= file.relative %>",
message: "<%= error.message %>",
sound: "Beep",
icon: app + "images/icons/icon48.png",
})(err);
console.log(err.toString());
this.emit('end');
};
function onSuccess(msg) {
return {
message: msg + " Complete! ",
//sound: "Pop",
icon: app + "images/icons/icon48.png",
onLast: true
}
}
function notifyFunc(msg) {
return gulp.src('.', { read: false })
.pipe(notify(onSuccess(msg)))
}
// HTML / TPL Pages
let htmlFiles = app + 'layouts/*.html';
let tplFiles = app + 'includes/*.tpl';
gulp.task('html', function(done) {
return gulp.src(htmlFiles)
.pipe(plumber({ errorHandler: onError }))
.pipe(fileinclude({ prefix: '@@', basepath: '@file' }))
.pipe(gulp.dest(dist))
.pipe(gulp.dest(dist_CX))
.pipe(notify(onSuccess('HTML')))
});
// styles: Compile and Minify Less / CSS Files
let less_watchFolder = app + 'styles/**/*.less';
let less_srcFile = app + 'styles/etherwallet-master.less';
let less_destFolder = dist + 'css';
let less_destFolder_CX = dist_CX + 'css';
let less_destFile = 'etherwallet-master.css';
let less_destFileMin = 'etherwallet-master.min.css';
gulp.task('styles', function() {
return gulp.src(less_srcFile)
.pipe(plumber({ errorHandler: onError }))
.pipe(less({ compress: false }))
.pipe(autoprefixer({ browsers: ['last 4 versions', 'iOS > 7'], remove: false }))
.pipe(rename(less_destFile))
//.pipe( gulp.dest ( less_destFolder )) // unminified css
//.pipe( gulp.dest ( less_destFolder_CX )) // unminified css
.pipe(cssnano({ autoprefixer: false, safe: true }))
.pipe(rename(less_destFileMin))
.pipe(gulp.dest(less_destFolder))
.pipe(gulp.dest(less_destFolder_CX))
.pipe(notify(onSuccess('Styles')))
});
// js: Browserify
let js_watchFolder = app + 'scripts/**/*.{js,json,html}';
let js_srcFile = app + 'scripts/main.js';
let js_destFolder = dist + 'js/';
let js_destFolder_CX = dist_CX + 'js/';
let js_destFile = 'etherwallet-master.js';
let browseOpts = { debug: true }; // generates inline source maps - only in js-debug
let babelOpts = {
presets: ['es2015'],
compact: false,
global: true
};
function bundle_js(bundler) {
return bundler.bundle()
.pipe(plumber({ errorHandler: onError }))
.pipe(source('main.js'))
.pipe(buffer())
.pipe(rename(js_destFile))
.pipe(gulp.dest(js_destFolder))
.pipe(gulp.dest(js_destFolder_CX))
.pipe(notify(onSuccess('JS')))
}
function bundle_js_debug(bundler) {
return bundler.bundle()
.pipe(plumber({ errorHandler: onError }))
.pipe(source('main.js'))
.pipe(buffer())
.pipe(rename(js_destFile))
.pipe(gulp.dest(js_destFolder))
.pipe(gulp.dest(js_destFolder_CX))
.pipe(notify(onSuccess('JS')))
}
gulp.task('js', function() {
let bundler = browserify(js_srcFile).transform(babelify).transform(html2js);
bundle_js(bundler)
});
gulp.task('js-production', function() {
let bundler = browserify(js_srcFile).transform(babelify, babelOpts).transform(html2js);
bundle_js(bundler)
});
gulp.task('js-debug', function() {
let bundler = browserify(js_srcFile, browseOpts).transform(babelify, babelOpts).transform(html2js);
bundle_js_debug(bundler)
});
// Rebuild Static JS
let js_srcFilesStatic = app + 'scripts/staticJS/to-compile-to-static/*.js';
let js_destFolderStatic = app + 'scripts/staticJS/';
let js_destFileStatic = 'etherwallet-static.min.js';
gulp.task('staticJS', function() {
return gulp.src(js_srcFilesStatic)
.pipe(plumber({ errorHandler: onError }))
.pipe(concat(js_destFileStatic))
.pipe(uglify())
.pipe(gulp.dest(js_destFolderStatic))
.pipe(notify(onSuccess('StaticJS')))
});
// Copy
let imgSrcFolder = app + 'images/**/*';
let fontSrcFolder = app + 'fonts/*.*';
let cxSrcFiles = app + 'includes/browser_action/*.*';
let jsonFile = app + '*.json';
let jQueryFile = app + 'scripts/staticJS/jquery-1.12.3.min.js';
let bin = app + '/bin/*';
let staticJSSrcFile = js_destFolderStatic + js_destFileStatic;
let readMe = './README.md';
gulp.task('copy', ['staticJS'], function() {
gulp.src(imgSrcFolder)
.pipe(gulp.dest(dist + 'images'))
.pipe(gulp.dest(dist_CX + 'images'));
gulp.src(fontSrcFolder)
.pipe(gulp.dest(dist + 'fonts'))
.pipe(gulp.dest(dist_CX + 'fonts'));
gulp.src(staticJSSrcFile)
.pipe(gulp.dest(dist + 'js'))
.pipe(gulp.dest(dist_CX + 'js'));
gulp.src(jQueryFile)
.pipe(gulp.dest(dist + 'js'))
.pipe(gulp.dest(dist_CX + 'js'));
gulp.src(jsonFile)
.pipe(gulp.dest(dist))
.pipe(gulp.dest(dist_CX));
gulp.src(readMe)
.pipe(gulp.dest(dist));
gulp.src(bin)
.pipe(gulp.dest(dist + 'bin'));
return gulp.src(cxSrcFiles)
.pipe(gulp.dest(dist_CX + 'browser_action'))
.pipe(notify(onSuccess(' Copy ')))
});
// Clean files that get compiled but shouldn't
gulp.task('clean', function() {
return gulp.src([
dist_CX + 'images/fav/manifest.json',
dist_CX + 'embedded.html',
dist_CX + 'index.html',
dist_CX + 'signmsg.html',
dist + 'cx-wallet.html',
dist + 'images/icons',
dist + 'manifest.json',
dist_CX + 'package.json'
], { read: false })
.pipe(plumber({ errorHandler: onError }))
.pipe(clean())
.pipe(notify(onSuccess(' Clean ')))
});
// Bumps Version Number
function bumpFunc(t) {
return gulp.src([app + '*.json'])
.pipe( plumber ({ errorHandler: onError }))
.pipe( bump ({ type: t }))
.pipe( gulp.dest ( './app' ))
.pipe( notify ( onSuccess('Bump ' + t ) ))
}
// Get Version Number
let versionNum;
let versionMsg;
gulp.task('getVersion', function() {
manifest = JSON.parse(fs.readFileSync(app + 'manifest.json'));
versionNum = 'v' + manifest.version;
versionMsg = 'Release: ' + versionNum
//return gulp.src( './' )
//.pipe( notify ( onSuccess('Version Number ' + versionNum ) ))
});
// zips dist folder
gulp.task('zip', ['getVersion'], function() {
gulp.src(dist + '**/**/*')
.pipe(plumber({ errorHandler: onError }))
.pipe(zip('./dist-' + versionNum + '.zip'))
.pipe(gulp.dest('./releases/'))
.pipe(notify(onSuccess('Zip Dist ' + versionNum)));
return gulp.src(dist_CX + '**/**/*')
.pipe(plumber({ errorHandler: onError }))
.pipe(zip('./chrome-extension-' + versionNum + '.zip'))
.pipe(gulp.dest('./releases/'))
.pipe(notify(onSuccess('Zip CX ' + versionNum)))
});
function archive() {
let outputZip = fs.createWriteStream(__dirname + '/example.zip');
let archiveZip = archiver('zip', {
gzip: true,
});
outputZip.on('close', function() {
console.log(archiveZip.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
});
archiveZip.on('error', function(err) {
throw err;
});
archiveZip.pipe(outputZip);
archiveZip.directory(dist, 'test2');
archiveZip.finalize();
let outputTar = fs.createWriteStream(__dirname + '/example.tgz');
let archiveTar = archiver('tar', {
gzip: true,
});
outputTar.on('close', function() {
return gulp.src(archiveTar).pipe(onSuccess('Archive Complete: Tar, /dist' ));
});
archiveTar.on('error', function(err) {
throw err;
});
archiveTar.pipe(outputTar);
archiveTar.directory(dist, 'test2');
archiveTar.finalize();
}
gulp.task('travisZip', ['getVersion'], function() {
gulp.src(dist + '**/**/*')
.pipe(plumber({ errorHandler: onError }))
.pipe(zip('./dist-' + versionNum + '.zip'))
.pipe(gulp.dest('./deploy/'))
.pipe(notify(onSuccess('Zip Dist ' + versionNum)));
return gulp.src(dist_CX + '**/**/*')
.pipe(plumber({ errorHandler: onError }))
.pipe(zip('./chrome-extension-' + versionNum + '.zip'))
.pipe(gulp.dest('./deploy/'))
.pipe(notify(onSuccess('Zip CX ' + versionNum)))
});
// add all
gulp.task('add', function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git add -A'
]))
//.pipe( notify ( onSuccess('Git Add' ) ))
});
// commit with current v# in manifest
gulp.task('commit', ['getVersion'], function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git commit -m "Rebuilt and cleaned everything. Done for now."'
]))
.pipe(notify(onSuccess('Commit')))
});
// commit with current v# in manifest
gulp.task('commitV', ['getVersion'], function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git commit -m " ' + versionMsg + ' "'
]))
.pipe(notify(onSuccess('Commit w ' + versionMsg)))
});
// tag with current v# in manifest
gulp.task('tag', ['getVersion'], function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git tag -a ' + versionNum + ' -m " ' + versionMsg + '"'
]))
.pipe(notify(onSuccess('Tagged Commit' + versionMsg)))
});
// Push Release to Mercury
gulp.task('push', ['getVersion'], function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git push origin mercury ' + versionNum
]))
.pipe(notify(onSuccess('Push')))
});
// Push Live
// Pushes dist folder to gh-pages branch
gulp.task('pushlive', ['getVersion'], function() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'git subtree push --prefix dist origin gh-pages'
]))
.pipe(notify(onSuccess('Push Live')))
});
// Prep & Release
// gulp prep
// gulp bump or gulp zipit
// gulp commit
// git push --tags
// gulp pushlive ( git subtree push --prefix dist origin gh-pages )
gulp.task('watchJS', function() { gulp.watch(js_watchFolder, ['js'] ) })
gulp.task('watchJSDebug', function() { gulp.watch(js_watchFolder, ['js-debug'] ) })
gulp.task('watchJSProd', function() { gulp.watch(js_watchFolder, ['js-production'] ) })
gulp.task('watchLess', function() { gulp.watch(less_watchFolder, ['styles'] ) })
gulp.task('watchPAGES', function() { gulp.watch(htmlFiles, ['html'] ) })
gulp.task('watchTPL', function() { gulp.watch(tplFiles, ['html'] ) })
gulp.task('watchCX', function() { gulp.watch(cxSrcFiles, ['copy'] ) })
gulp.task('bump', function() { return bumpFunc( 'patch' ) });
gulp.task('bump-patch', function() { return bumpFunc( 'patch' ) });
gulp.task('bump-minor', function() { return bumpFunc( 'minor' ) });
gulp.task('archive', function() { return archive() });
gulp.task('prep', function(cb) { runSequence('js-production', 'html', 'styles', 'copy', cb); });
gulp.task('bump', function(cb) { runSequence('bump-patch', 'clean', 'zip', cb); });
gulp.task('zipit', function(cb) { runSequence('clean', 'zip', cb); });
gulp.task('commit', function(cb) { runSequence('add', 'commitV', 'tag', cb); });
gulp.task('watch', ['watchJS', 'watchLess', 'watchPAGES', 'watchTPL', 'watchCX'])
gulp.task('watchProd', ['watchJSProd', 'watchLess', 'watchPAGES', 'watchTPL', 'watchCX'])
gulp.task('build', ['js', 'html', 'styles', 'copy']);
gulp.task('build-debug', ['js-debug', 'html', 'styles', 'watchJSDebug', 'watchLess', 'watchPAGES', 'watchTPL', 'watchCX'])
gulp.task('default', ['build', 'watch']);