This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
gulpfile.js
423 lines (337 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
421
422
423
/* eslint-disable
import/no-extraneous-dependencies,
no-console,
strict,
prefer-spread,
arrow-body-style,
import/no-unresolved */
'use strict';
const _ = require('underscore');
const path = require('path');
const gulp = require('gulp');
const exec = require('child_process').exec;
const del = require('del');
const runSeq = require('run-sequence');
const merge = require('merge-stream');
const flatten = require('gulp-flatten');
const shell = require('shelljs');
const mocha = require('gulp-spawn-mocha');
const minimist = require('minimist');
const fs = require('fs');
const got = require('got');
const 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
let type = 'mist';
let applicationName = 'Mist';
const electronVersion = require('electron/package.json').version;
const packJson = require('./package.json');
const version = packJson.version;
const osArchList = [
'mac-x64',
'linux-x64',
'win-x64',
];
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 (const p of options.platform) {
if (osArch.indexOf(p) >= 0) {
return true;
}
}
return false;
}
// / --------------------------------------------------------------
// TASKS
gulp.task('set-variables-mist', () => {
type = 'mist';
applicationName = 'Ethereum Classic Mist';
});
gulp.task('set-variables-wallet', () => {
type = 'wallet';
applicationName = 'Ethereum Classic Wallet';
});
gulp.task('clean:dist', (cb) => {
return del([
`./dist_${type}/**/*`,
'./meteor-dapp-wallet',
], cb);
});
// BUNLDE PROCESS
gulp.task('copy-app-source-files', ['clean:dist'], () => {
return gulp.src([
'./tests/**/*.*',
'!./tests/wallet/*.*',
`./icons/${type}/*`,
'./modules/**/**/**/*',
'./sounds/*',
'./*.js',
'./clientBinaries.json',
'!gulpfile.js',
], { base: './' })
.pipe(gulp.dest(`./dist_${type}/app`));
});
gulp.task('copy-app-folder-files', ['copy-app-source-files'], (done) => {
const ret = shell.exec(
`cp -a ${__dirname}/node_modules ${__dirname}/dist_${type}/app/node_modules`
);
if (ret.code !== 0) {
console.error('Error symlinking node_modules');
return done(ret.stderr);
}
return done();
});
gulp.task('copy-build-folder-files', ['clean:dist', 'copy-app-folder-files'], () => {
//fix not generating icons
gulp.src([`./icons/${type}/icons/*`], { base: './' })
.pipe(flatten())
.pipe(gulp.dest(`./dist_${type}/build/icons`));
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', ['clean:dist'], () => {
const streams = [];
_.each(osArchList, (osArch) => {
if (platformIsActive(osArch)) {
// copy eth node binaries
streams.push(gulp.src([
`./nodes/eth/${osArch}/*`,
])
.pipe(gulp.dest(`./dist_${type}/app/nodes/eth/${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'], (cb) => {
fs.writeFileSync(`${__dirname}/dist_${type}/app/config.json`, JSON.stringify({
production: true,
mode: type,
}));
cb();
});
gulp.task('bundling-interface', ['switch-production'], (cb) => {
if (type === 'mist') {
exec(`cd interface && meteor-build-client ../dist_${type}/app/interface -p ""`, (err, stdout) => {
console.log(stdout);
cb(err);
});
}
if (type === 'wallet') {
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 ""`, (err, stdout) => {
console.log(stdout);
cb(err);
});
} else {
console.log(`Pulling https://github.com/ethereumproject/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/ethereumproject/meteor-dapp-wallet.git && cd meteor-dapp-wallet/app && meteor-build-client ../../app/interface/wallet -p "" && cd ../../ && rm -rf meteor-dapp-wallet`, (err, stdout) => {
console.log(stdout);
cb(err);
});
}
}
});
// needs to be copied, so the backend can use it
gulp.task('copy-i18n', ['bundling-interface'], () => {
return gulp.src([
'./interface/i18n/*.*',
'./interface/project-tap.i18n',
], { base: './' })
.pipe(gulp.dest(`./dist_${type}/app`));
});
gulp.task('build-dist', ['download-signatures', 'copy-i18n'], (cb) => {
console.log('Bundling platforms: ', options.platform);
const appPackageJson = _.extend({}, packJson, {
name: applicationName.replace(/\s/g, ''),
productName: applicationName,
description: applicationName,
homepage: 'https://github.com/ethereumproject/mist',
build: {
appId: `com.ethereum.mist.${type}`,
category: 'public.app-category.productivity',
asar: true,
files: [
'**/*',
'!nodes',
'build-dist.js',
],
extraFiles: [
'nodes/eth/${os}-${arch}', // eslint-disable-line no-template-curly-in-string
],
linux: {
target: [
'zip',
'deb',
],
},
win: {
target: [
'zip',
'squirrel',
],
},
dmg: {
background: '../build/dmg-background.jpg',
'icon-size': 128,
contents: [
{
x: 470,
y: 135,
type: 'link',
path: '/Applications',
},
{
x: 125,
y: 135,
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
const oses = `--${options.platform.join(' --')}`;
const ret = shell.exec(`./build-dist.js --type ${type} ${oses}`, {
cwd: path.join(__dirname, `dist_${type}`, 'app'),
});
if (ret.code !== 0) {
console.error(ret.stdout);
console.error(ret.stderr);
return cb(new Error('Error building distributables'));
}
console.log(ret.stdout);
return cb();
});
gulp.task('release-dist', ['build-dist'], (done) => {
const distPath = path.join(__dirname, `dist_${type}`, 'dist');
const releasePath = path.join(__dirname, `dist_${type}`, 'release');
shell.rm('-rf', releasePath);
shell.mkdir('-p', releasePath);
const appNameHypen = applicationName.replace(/\s/g, '-');
const appNameNoSpace = applicationName.replace(/\s/g, '');
const versionDashed = version.replace(/\./g, '-');
const cp = (inputPath, outputPath) => {
shell.cp(path.join(distPath, inputPath), path.join(releasePath, outputPath));
};
_.each(osArchList, (osArch) => {
if (platformIsActive(osArch)) {
switch (osArch) { // eslint-disable-line default-case
case 'win-x64':
cp(path.join('win', `${applicationName} Setup ${version}.exe`), `${appNameHypen}-win64-${versionDashed}.exe`);
cp(`${applicationName}-${version}-win.zip`, `${appNameHypen}-win64-${versionDashed}.zip`);
break;
case 'mac-x64':
cp(path.join('mac', `${applicationName}-${version}.dmg`), `${appNameHypen}-macosx-${versionDashed}.dmg`);
break;
case 'linux-x64':
cp(`${appNameNoSpace}-${version}.deb`, `${appNameHypen}-linux64-${versionDashed}.deb`);
cp(`${appNameNoSpace}-${version}.zip`, `${appNameHypen}-linux64-${versionDashed}.zip`);
break;
}
}
});
done();
});
gulp.task('get-release-checksums', (done) => {
const releasePath = `./dist_${type}/release`;
const files = fs.readdirSync(releasePath);
for (const file of files) {
const sha = shell.exec(`shasum -a 256 "${file}"`, { cwd: releasePath });
if (sha.code !== 0) {
return done(new Error(`Error executing shasum: ${sha.stderr}`));
}
}
return done();
});
gulp.task('download-signatures', (cb) => {
got('https://www.4byte.directory/api/v1/signatures/?page_size=20000&ordering=created_at', {
json: true,
})
.then((res) => {
if (res.statusCode !== 200) {
throw new Error(res.statusText);
}
const signatures = {};
_.each(res.body.results, (e) => {
signatures[e.hex_signature] = signatures[e.hex_signature] || [];
signatures[e.hex_signature].push(e.text_signature);
});
fs.writeFileSync('interface/client/lib/signatures.js', `window.SIGNATURES = ${JSON.stringify(signatures, null, 4)};`);
cb();
})
.catch(cb);
});
gulp.task('taskQueue', [
'release-dist',
]);
// MIST task
gulp.task('mist', (cb) => {
runSeq('set-variables-mist', 'taskQueue', cb);
});
// WALLET task
gulp.task('wallet', (cb) => {
runSeq('set-variables-wallet', 'taskQueue', cb);
});
// WALLET task
gulp.task('mist-checksums', (cb) => {
runSeq('set-variables-mist', 'get-release-checksums', cb);
});
gulp.task('wallet-checksums', (cb) => {
runSeq('set-variables-wallet', 'get-release-checksums', cb);
});
gulp.task('test-wallet', () => {
return gulp.src([
'./tests/wallet/*.test.js',
])
.pipe(mocha({
timeout: 60000,
ui: 'exports',
reporter: 'spec',
}));
});
gulp.task('default', ['mist']);