forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
420 lines (338 loc) · 11.5 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
var _ = require("underscore");
var gulp = require('gulp');
var exec = require('child_process').exec;
var del = require('del');
var replace = require('gulp-replace');
var packager = require('electron-packager');
var spawn = require('child_process').spawn;
var merge = require('merge-stream');
var rename = require("gulp-rename");
// 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 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 = '0.37.2';
var osVersions = [];
var packJson = require('./package.json');
var version = packJson.version;
console.log('You can select a platform like: --platform (all or darwin or win32 or linux)');
console.log('Mist version:', version);
console.log('Electron version:', electronVersion);
if(_.contains(options.platform, 'win32')) {
osVersions.push('win32-ia32');
osVersions.push('win32-x64');
}
if(_.contains(options.platform, 'linux')) {
osVersions.push('linux-ia32');
osVersions.push('linux-x64');
}
if(_.contains(options.platform, 'darwin')) {
osVersions.push('darwin-x64');
}
if(_.contains(options.platform, 'all')) {
osVersions = [
'darwin-x64',
// 'linux-arm',
'linux-ia32',
'linux-x64',
'win32-ia32',
'win32-x64'
];
}
console.log('Bundling platforms: ', osVersions);
// Helpers
var createNewFileName = function(os) {
var newOs;
if(os.indexOf('win32') !== -1) {
newOs = os.replace('win32-ia32','win32').replace('win32-x64','win64');
}
if(os.indexOf('darwin') !== -1) {
newOs = 'macosx';
}
if(os.indexOf('linux') !== -1) {
newOs = os.replace('linux-x64','linux64').replace('linux-ia32','linux32');
}
return './dist_'+ type +'/'+ filenameUppercase +'-'+ newOs + '-'+ version.replace(/\./g,'-');
};
/// --------------------------------------------------------------
// 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);
});
gulp.task('copy-files', ['clean:dist'], function() {
return gulp.src([
'./tests/**/*.*',
'./modules/**/*.*',
'./node_modules/**/*.*',
'./sounds/*.*',
'./icons/'+ type +'/*.*',
'./*.*',
'!./interface/**/*.*',
'!./geth',
'!./geth.exe',
'!./main.js',
'!./Wallet-README.txt'
], { base: './' })
.pipe(gulp.dest('./dist_'+ type +'/app'));
});
gulp.task('switch-production', ['clean:dist'], function() {
return gulp.src(['./main.js'])
.pipe(replace('global.production = false;', 'global.production = true;'))
.pipe(replace('global.mode = (argv.mode ? argv.mode : \'mist\');', 'global.mode = (argv.mode ? argv.mode : \''+ type +'\');'))
.pipe(gulp.dest('./dist_'+ type +'/app'));
});
gulp.task('bundling-interface', ['clean:dist', 'copy-files'], function(cb) {
if(type === 'mist') {
exec('cd interface && meteor-build-client ../dist_'+ type +'/app/interface -p ""', function (err, stdout, stderr) {
// console.log(stdout);
console.log(stderr);
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);
console.log(stderr);
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 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);
console.log(stderr);
cb(err);
});
}
}
});
// needs to be copied, so the backend can use it
gulp.task('copy-i18n', ['copy-files', 'bundling-interface'], function() {
return gulp.src([
'./interface/i18n/*.*',
'./interface/project-tap.i18n'
], { base: './' })
.pipe(gulp.dest('./dist_'+ type +'/app'));
});
gulp.task('create-binaries', ['copy-i18n'], function(cb) {
packager({
dir: './dist_'+ type +'/app/',
out: './dist_'+ type +'/',
name: filenameUppercase,
platform: options.platform.join(','),
arch: 'all',
icon: './icons/'+ type +'/icon.icns',
version: electronVersion,
'app-version': version,
'build-version': electronVersion,
// DO AFTER: codesign --deep --force --verbose --sign "5F515C07CEB5A1EC3EEB39C100C06A8C5ACAE5F4" Ethereum-Wallet.app
//'sign': '3rd Party Mac Developer Application: Stiftung Ethereum (3W6577R383)',
'app-bundle-id': 'com.ethereum.'+ type,
'helper-bundle-id': 'com.ethereum.'+ type + '.helper',
//'helper-bundle-id': 'com.github.electron.helper',
// cache: './dist_'+ type +'/', // directory of cached electron downloads. Defaults to '$HOME/.electron'
ignore: '', //do not copy files into App whose filenames regex .match this string
prune: true,
overwrite: true,
asar: true,
// sign: '',
'version-string': {
CompanyName: 'Stiftung Ethereum',
// LegalCopyright
// FileDescription
// OriginalFilename
ProductName: applicationName
// InternalName:
}
}, function(){
setTimeout(function(){
cb();
}, 1000)
});
});
gulp.task('change-files', ['create-binaries'], function() {
var streams = [];
osVersions.map(function(os){
var stream,
path = './dist_'+ type +'/'+ filenameUppercase +'-'+ os;
// change version file
streams.push(gulp.src([
path +'/version'
])
.pipe(replace(electronVersion, version))
.pipe(gulp.dest(path +'/')));
// copy license file
streams.push(gulp.src([
'./LICENSE'
])
.pipe(gulp.dest(path +'/')));
// copy authors file
streams.push(gulp.src([
'./AUTHORS'
])
.pipe(gulp.dest(path +'/')));
// copy and rename readme
streams.push(gulp.src([
'./Wallet-README.txt'
], { base: './' })
.pipe(rename(function (path) {
path.basename = "README";
}))
.pipe(gulp.dest(path + '/')));
var destPath = (os === 'darwin-x64')
? path +'/'+ filenameUppercase +'.app/Contents/Frameworks/node'
: path +'/resources/node';
// copy eth node binaries
streams.push(gulp.src([
'./nodes/eth/'+ os + '/*'
])
.pipe(gulp.dest(destPath +'/eth')));
// copy geth node binaries
streams.push(gulp.src([
'./nodes/geth/'+ os + '/*'
])
.pipe(gulp.dest(destPath +'/geth')));
});
return merge.apply(null, streams);
});
//gulp.task('cleanup-files', ['change-files'], function (cb) {
// return del(['./dist_'+ type +'/**/Wallet-README.txt'], cb);
//});
gulp.task('rename-folders', ['change-files'], function(done) {
var count = 0;
var called = false;
osVersions.forEach(function(os){
var path = createNewFileName(os);
fs.renameSync('./dist_'+ type +'/'+ filenameUppercase +'-'+ os, path);
// change icon on windows
if(os.indexOf('win32') !== -1) {
rcedit(path +'/'+ filenameUppercase +'.exe', {
'file-version': version,
'product-version': version,
'icon': './icons/'+ type +'/icon.ico'
}, function(){
if(!called && osVersions.length === count) {
done();
called = true;
}
});
}
//var zip5 = new EasyZip();
//zip5.zipFolder(path, function(){
// zip5.writeToFile(path +'.zip');
//});
count++;
if(!called && osVersions.length === count) {
done();
called = true;
}
});
});
gulp.task('zip', ['rename-folders'], function () {
var streams = osVersions.map(function(os){
var stream,
name = filenameUppercase +'-'+ os +'-'+ version.replace(/\./g,'-');
// TODO doesnt work!!!!!
stream = gulp.src([
'./dist_'+ type +'/'+ name + '/**/*'
])
.pipe(zip({
name: name + ".zip",
outpath: './dist_'+ type +'/'
}));
// .pipe(zip(name +'.zip'))
// .pipe(gulp.dest('./dist_'+ type +'/'));
return stream;
});
return merge.apply(null, streams);
});
gulp.task('getChecksums', [], function(done) {
var count = 0;
osVersions.forEach(function(os){
var path = createNewFileName(os) + '.zip';
// spit out shasum and md5
var fileName = path.replace('./dist_'+ type +'/', '');
var sha = spawn('shasum', [path]);
sha.stdout.on('data', function(data){
console.log('SHASUM '+ fileName +': '+ data.toString().replace(path, ''));
});
var md5 = spawn('md5', [path]);
md5.stdout.on('data', function(data){
console.log('MD5 '+ fileName +': '+ data.toString().replace('MD5 ('+ path +') = ', ''));
});
count++;
if(osVersions.length === count) {
done();
}
});
});
gulp.task('taskQueue', [
'clean:dist',
'copy-files',
'copy-i18n',
'switch-production',
'bundling-interface',
'create-binaries',
'change-files',
//'cleanup-files',
'rename-folders',
// 'zip'
]);
// MIST task
gulp.task('mist', [
'set-variables-mist',
'taskQueue'
]);
// WALLET task
gulp.task('wallet', [
'set-variables-wallet',
'taskQueue'
]);
// WALLET task
gulp.task('mist-checksums', [
'set-variables-mist',
'getChecksums'
]);
gulp.task('wallet-checksums', [
'set-variables-wallet',
'getChecksums'
]);
gulp.task('default', ['mist']);