forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
596 lines (462 loc) · 16.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
"use strict";
var _ = require("underscore");
var path = require('path');
var gulp = require('gulp');
var exec = require('child_process').exec;
var del = require('del');
var replace = require('gulp-replace');
var runSeq = require('run-sequence');
var merge = require('merge-stream');
var rename = require("gulp-rename");
var download = require('gulp-download-stream');
var flatten = require('gulp-flatten');
var tap = require("gulp-tap");
const shell = require('shelljs');
const mocha = require('gulp-spawn-mocha');
// const zip = require('gulp-zip');
// var zip = require('gulp-zip');
// var zip = require('gulp-jszip');
// var EasyZip = require('easy-zip').EasyZip;
var minimist = require('minimist');
var fs = require('fs');
var rcedit = require('rcedit');
var syncRequest = require('sync-request');
var builder = require('electron-builder');
var options = minimist(process.argv.slice(2), {
string: ['platform','walletSource'],
default: {
platform: 'all',
walletSource: 'master'
}
});
if(options.platform.indexOf(',') !== -1)
options.platform = options.platform.replace(/ +/g,'').split(',');
else
options.platform = options.platform.split(' ');
// CONFIG
var type = 'mist';
var filenameLowercase = 'mist';
var filenameUppercase = 'Mist';
var applicationName = 'Mist';
var electronVersion = require('electron-prebuilt/package.json').version;
var gethVersion = '1.4.14';
var nodeUrls = {
'mac-x64': {
url: 'https://bintray.com/artifact/download/karalabe/ethereum/geth-1.4.14-prerelease-f88bca7-darwin-10.6-amd64.tar.bz2',
ext: 'tar'
},
'linux-x64': {
url: 'https://bintray.com/artifact/download/karalabe/ethereum/geth-1.4.14-prerelease-f88bca7-linux-amd64.tar.bz2',
ext: 'tar',
},
'linux-ia32': {
url: 'https://bintray.com/artifact/download/karalabe/ethereum/geth-1.4.14-prerelease-f88bca7-linux-386.tar.bz2',
ext: 'tar',
},
'win-x64': {
url: 'https://bintray.com/artifact/download/karalabe/ethereum/geth-1.4.14-prerelease-f88bca7-windows-4.0-amd64.exe.zip',
ext: 'zip',
},
'win-ia32': {
url: 'https://bintray.com/artifact/download/karalabe/ethereum/geth-1.4.14-prerelease-f88bca7-windows-4.0-386.exe.zip',
ext: 'zip',
},
};
var packJson = require('./package.json');
var version = packJson.version;
console.log('You can select a platform like: --platform <mac|win|linux|all>');
console.log('App type:', type);
console.log('Mist version:', version);
console.log('Electron version:', electronVersion);
if(_.contains(options.platform, 'all')) {
options.platform = ['win', 'linux', 'mac'];
}
console.log('Selected platform:', options.platform);
function platformIsActive(osArch) {
for (let p of options.platform) {
if (0 <= osArch.indexOf(p)) {
return true;
}
}
return false;
}
/// --------------------------------------------------------------
// TASKS
gulp.task('set-variables-mist', function () {
type = 'mist';
filenameLowercase = 'mist';
filenameUppercase = 'Mist';
applicationName = 'Mist';
});
gulp.task('set-variables-wallet', function () {
type = 'wallet';
filenameLowercase = 'ethereum-wallet';
filenameUppercase = 'Ethereum-Wallet';
applicationName = 'Ethereum Wallet';
});
gulp.task('clean:dist', function (cb) {
return del([
'./dist_'+ type +'/**/*',
'./meteor-dapp-wallet',
], cb);
});
// DOWNLOAD NODES
gulp.task('clean:nodes', function (cb) {
return del([
'./nodes/geth/',
], cb);
});
gulp.task('downloadNodes', ['clean:nodes'], function() {
let toDownload = [];
_.each(nodeUrls, function(info, osArch) {
// donwload nodes
if (platformIsActive(osArch)) {
toDownload.push({
file: `geth_${gethVersion}_${osArch}.${info.ext}`,
url: info.url,
});
}
});
return download(toDownload)
.pipe(gulp.dest('./nodes/geth/'));
});
gulp.task('unzipNodes', ['downloadNodes'], function(done) {
let nodeZips = fs.readdirSync('./nodes/geth');
var streams = [];
for (let zipFileName of nodeZips) {
let match = zipFileName.match(/_(\w+\-\w+)\./);
if (!match) {
continue;
}
let osArch = match[1];
let ret;
shell.mkdir('-p', `./nodes/geth/${osArch}`);
switch (path.extname(zipFileName)) {
case '.zip':
ret = shell.exec(`unzip -o ./nodes/geth/${zipFileName} -d ./nodes/geth/${osArch}`);
break;
case '.tar':
ret = shell.exec(`tar -xf ./nodes/geth/${zipFileName} -C ./nodes/geth/${osArch}`);
break;
case '.bz2':
ret = shell.exec(`tar -xf ./nodes/geth/${zipFileName} -C ./nodes/geth/${osArch}`);
break;
default:
return done(new Error(`Don't know how to process: ${zipFileName}`));
}
if (0 !== ret.code) {
console.error('Error unzipping ' + zipFileName);
console.log(ret.stdout);
console.error(ret.stderr);
return done(ret.stderr);
}
}
done();
});
gulp.task('renameNodes', ['unzipNodes'], function(done) {
var streams = [];
for (let osArch in nodeUrls) {
let file;
try {
file = fs.readdirSync('./nodes/geth/' + osArch).pop();
} catch (err) {
console.warn(`Skipping ${osArch} node: ${err.message}`);
continue;
}
const finalName = (0 <= osArch.indexOf('win') ? 'geth.exe' : 'geth');
const originalPath = `./nodes/geth/${osArch}/${file}`,
finalPath = `./nodes/geth/${osArch}/${finalName}`;
let ret = shell.mv(originalPath, finalPath);
if (0 !== ret.code) {
console.error(`Error renaming ${originalPath}`);
return done(ret.stderr);
}
ret = shell.exec(`chmod +x ${finalPath}`);
if (0 !== ret.code) {
console.error(`Error setting executable permission: ${finalPath}`);
return done(ret.stderr);
}
}
return done();
});
// CHECK FOR NODES
var nodeUpdateNeeded = false;
gulp.task('checkNodes', function(cb) {
_.each(nodeUrls, (info, osArch) => {
// check for zip file
if (platformIsActive(osArch)) {
const fileName = `geth_${gethVersion}_${osArch}.${info.ext}`;
try {
fs.accessSync(`./nodes/geth/${fileName}`, fs.R_OK);
} catch (err) {
nodeUpdateNeeded = true;
}
}
});
cb();
});
// BUNLDE PROCESS
gulp.task('copy-app-source-files', ['checkNodes', 'clean:dist'], function() {
// check if nodes are there
if(nodeUpdateNeeded){
console.error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes');
throw new Error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes');
}
return gulp.src([
'./tests/**/*.*',
'./icons/'+ type +'/*',
'./modules/**/**/**/*',
'./sounds/*',
'./*.js',
'!gulpfile.js'
], { base: './' })
.pipe(gulp.dest('./dist_'+ type +'/app'));
});
gulp.task('copy-app-folder-files', ['copy-app-source-files'], function(done) {
let ret = shell.exec(
`cp -a ${__dirname}/node_modules ${__dirname}/dist_${type}/app/node_modules`
);
if (0 !== ret.code) {
console.error(`Error symlinking node_modules`);
return done(ret.stderr);
}
return done();
});
gulp.task('copy-build-folder-files', ['clean:dist', 'copy-app-folder-files'], function() {
return gulp.src([
'./icons/'+ type +'/*',
'./interface/public/images/dmg-background.jpg',
], { base: './' })
.pipe(flatten())
.pipe(gulp.dest('./dist_'+ type +'/build'));
});
gulp.task('copy-node-folder-files', ['checkNodes', 'clean:dist'], function(done) {
// check if nodes are there
if(nodeUpdateNeeded){
console.error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes');
done(new Error('YOUR NODES NEED TO BE UPDATED run $ gulp update-nodes'));
return;
}
var streams = [];
_.each(nodeUrls, (info, osArch) => {
if (platformIsActive(osArch)) {
// copy eth node binaries
streams.push(gulp.src([
'./nodes/eth/'+ osArch + '/*'
])
.pipe(gulp.dest('./dist_'+ type +'/app/nodes/eth/' + osArch)));
// copy geth node binaries
streams.push(gulp.src([
'./nodes/geth/'+ osArch + '/*'
])
.pipe(gulp.dest('./dist_'+ type +'/app/nodes/geth/' + osArch)));
}
});
return merge.apply(null, streams);
});
gulp.task('copy-files', [
'clean:dist',
'copy-app-folder-files',
'copy-build-folder-files',
'copy-node-folder-files',
]);
gulp.task('switch-production', ['copy-files'], function(cb) {
fs.writeFileSync(__dirname+'/dist_'+ type +'/app/config.json', JSON.stringify({
production: true,
mode: type,
}));
cb();
});
gulp.task('bundling-interface', ['switch-production'], function(cb) {
if(type === 'mist') {
exec('cd interface && meteor-build-client ../dist_'+ type +'/app/interface -p ""', function (err, stdout, stderr) {
console.log(stdout);
cb(err);
});
}
if(type === 'wallet') {
// TODO move mist interface too
if(options.walletSource === 'local') {
console.log('Use local wallet at ../meteor-dapp-wallet/app');
exec('cd interface/ && meteor-build-client ../dist_'+ type +'/app/interface/ -p "" &&'+
'cd ../../meteor-dapp-wallet/app && meteor-build-client ../../mist/dist_'+ type +'/app/interface/wallet -p ""', function (err, stdout, stderr) {
console.log(stdout);
cb(err);
});
} else {
console.log('Pulling https://github.com/ethereum/meteor-dapp-wallet/tree/'+ options.walletSource +' "'+ options.walletSource +'" branch...');
exec('cd interface/ && meteor-build-client ../dist_'+ type +'/app/interface/ -p "" &&'+
'cd ../dist_'+ type +'/ && git clone --depth 1 https://github.com/ethereum/meteor-dapp-wallet.git && cd meteor-dapp-wallet/app && meteor-build-client ../../app/interface/wallet -p "" && cd ../../ && rm -rf meteor-dapp-wallet', function (err, stdout, stderr) {
console.log(stdout);
cb(err);
});
}
}
});
// needs to be copied, so the backend can use it
gulp.task('copy-i18n', ['bundling-interface'], function() {
return gulp.src([
'./interface/i18n/*.*',
'./interface/project-tap.i18n'
], { base: './' })
.pipe(gulp.dest('./dist_'+ type +'/app'));
});
gulp.task('build-dist', ['copy-i18n'], function(cb) {
console.log('Bundling platforms: ', options.platform);
var appPackageJson = _.extend({}, packJson, {
name: applicationName.replace(/\s/, ''),
productName: applicationName,
description: applicationName,
homepage: "https://github.com/ethereum/mist",
build: {
appId: "com.ethereum.mist." + type,
"category": "public.app-category.productivity",
asar: true,
files: [
"**/*",
"!nodes",
"build-dist.js",
],
extraFiles: [
"nodes/eth/${os}-${arch}",
"nodes/geth/${os}-${arch}"
],
dmg: {
background: "../build/dmg-background.jpg",
"icon-size": 128,
"contents": [{
"x": 441,
"y": 448,
"type": "link",
"path": "/Applications"
},
{
"x": 441,
"y": 142,
"type": "file"
}]
}
},
directories: {
buildResources: "../build",
app: ".",
output: "../dist",
},
});
fs.writeFileSync(
path.join(__dirname, 'dist_' + type, 'app', 'package.json'),
JSON.stringify(appPackageJson, null, 2),
'utf-8'
);
// Copy build script
shell.cp(
path.join(__dirname, 'scripts', 'build-dist.js'),
path.join(__dirname, 'dist_' + type, 'app')
);
// run build script
var oses = '--' + options.platform.join(' --');
var ret = shell.exec(`./build-dist.js --type ${type} ${oses}`, {
cwd: path.join(__dirname, 'dist_' + type, 'app'),
});
if (0 !== ret.code) {
console.error(ret.stdout);
console.error(ret.stderr);
return cb(new Error('Error building distributables'));
} else {
console.log(ret.stdout);
cb();
}
});
gulp.task('release-dist', ['build-dist'], function(done) {
const distPath = path.join(__dirname, `dist_${type}`, 'dist'),
releasePath = path.join(__dirname, `dist_${type}`, 'release');
shell.rm('-rf', releasePath);
shell.mkdir('-p', releasePath);
_.each(nodeUrls, (info, osArch) => {
if (platformIsActive(osArch)) {
switch (osArch) {
case 'win-ia32':
shell.cp(path.join(distPath, 'win-ia32', `${applicationName} Setup ${version}-ia32.exe`), releasePath);
break;
case 'win-x64':
shell.cp(path.join(distPath, 'win', `${applicationName} Setup ${version}.exe`), releasePath);
break;
case 'mac-x64':
shell.cp(path.join(distPath, 'mac', `${applicationName}-${version}.dmg`), releasePath);
break;
case 'linux-ia32':
shell.cp(path.join(distPath, `Mist-${version}-ia32.deb`), path.join(releasePath, `${applicationName}-${version}-ia32.deb`) );
break;
case 'linux-x64':
shell.cp(path.join(distPath, `Mist-${version}.deb`), path.join(releasePath, `${applicationName}-${version}.deb`) );
break;
}
}
});
done();
});
gulp.task('get-release-checksums', function(done) {
const releasePath = `./dist_${type}/release`;
let files = fs.readdirSync(releasePath);
for (let file of files) {
let sha = shell.exec(`shasum -a 256 "./dist_${type}/release/${file}"`);
if (0 !== sha.code) {
return done(new Error('Error executing shasum: ' + sha.stderr));
}
}
});
gulp.task('download-signatures', function(){
var signatures = {},
getFrom4byteAPI = function(url){
console.log('Requesting ', url);
var res = syncRequest('GET', url);
if (res.statusCode == 200) {
var responseData = JSON.parse(res.getBody('utf8'));
_.map(responseData.results, function(e){
if (!!signatures[e.hex_signature]) {
signatures[e.hex_signature].push(e.text_signature);
}
else {
signatures[e.hex_signature] = [e.text_signature];
}
});
responseData.next && getFrom4byteAPI(responseData.next);
}
};
getFrom4byteAPI('https://www.4byte.directory/api/v1/signatures/');
fs.writeFileSync('interface/client/lib/signatures.js', "window.SIGNATURES = " + JSON.stringify(signatures, null, '\t') + ";");
});
gulp.task('taskQueue', [
'release-dist'
]);
// DOWNLOAD nodes
gulp.task('update-nodes', [
'renameNodes'
]);
gulp.task('download-nodes', ['update-nodes']);
// MIST task
gulp.task('mist', function(cb) {
runSeq('set-variables-mist', 'taskQueue', cb);
});
// WALLET task
gulp.task('wallet', function(cb) {
runSeq('set-variables-wallet', 'taskQueue', cb);
});
// WALLET task
gulp.task('mist-checksums', function(cb) {
runSeq('set-variables-mist', 'get-release-checksums', cb);
});
gulp.task('wallet-checksums', function(cb) {
runSeq('set-variables-wallet', 'get-release-checksums', cb);
});
gulp.task('test-wallet', function() {
return gulp.src([
'./test/wallet/*.test.js'
])
.pipe(mocha({
timeout: 60000,
ui: 'exports',
reporter: 'spec'
}));
});
gulp.task('default', ['mist']);