-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
896 lines (775 loc) · 26.3 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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
const path = require('path');
const gulp = require('gulp');
const mkdirp = require('mkdirp');
const argv = require('yargs').argv;
const fs = require('fs-extra');
const packager = require('electronite-packager');
const change = require('gulp-change');
const rimraf = require('rimraf');
const ncp = require('ncp').ncp;
const request = require('./scripts/request');
const CrowdinApi = require('./scripts/CrowdinApi');
function copy(src, dest) {
return new Promise((resolve, reject) => {
console.log(`copying ${src} to ${dest}`);
ncp(src, dest, (err) => {
if (err) {
console.log(`failed copying ${src}`);
reject(err);
} else {
console.log(`finished copying ${src}`);
resolve();
}
});
});
}
const BUILD_DIR = './dist/';
const RELEASE_DIR = './release/';
const getBranchType = () => {
if (process.env.TRAVIS && process.env.TRAVIS_BRANCH) {
if (process.env.TRAVIS_BRANCH.startsWith('release-')) {
return 'release';
} else if (process.env.TRAVIS_BRANCH.startsWith('sandbox-')) {
return 'sandbox';
} else if (process.env.TRAVIS_BRANCH === 'develop') {
return 'develop';
}
}
return 'unknown';
};
gulp.task('crowdin', () => {
if (process.env.CROWDIN_API_KEY && process.env.CROWDIN_PROJECT) {
const api = new CrowdinApi({ apiKey: process.env.CROWDIN_API_KEY });
const files = { 'English-en_US.json': './src/locale/English-en_US.json' };
return api.updateFile(process.env.CROWDIN_PROJECT, files)
.then(function (result) {
if (result.success) {
console.log('Crowdin upload succeeded', result.files);
} else {
console.log(result);
}
})
.catch(function (err) {
console.log('Crowdin error', err);
});
} else {
console.log('Missing Crowdin environment vars. Skipping locale upload.');
}
});
/**
* set developer build properties
* TRICKY: this will modify package.json.
* however, these changes should not be committed to git.
* As a safety net this will only run on travis.
*/
gulp.task('set_mode', () => {
let p = require('./package');
if (!process.env.TRAVIS) {
console.log('Skipping build mode. On non-travis environment');
return Promise.resolve();
}
if (process.env.TRAVIS_TAG) {
console.log('Tag mode');
if (!process.env.TRAVIS_TAG.startsWith('v')) {
return Promise.reject(`The tag must be prefixed with a "v".`);
}
if (process.env.TRAVIS_TAG !== `v${p.version}`) {
return Promise.reject(
`The package version does not match the tag name. Expected ${process.env.TRAVIS_TAG} but found ${p.version}`);
}
} else if (process.env.TRAVIS_BRANCH &&
process.env.TRAVIS_BRANCH.startsWith('release-')) {
console.log('Release mode');
let branchVersion = process.env.TRAVIS_BRANCH.replace(/^release-/, '');
if (!branchVersion.startsWith('v')) {
return Promise.reject(
`The release branch version must be prefixed with a "v".`);
}
if (branchVersion !== `v${p.version}`) {
return Promise.reject(
`The package version does not match the release branch version. Expected ${branchVersion} but found ${p.version}`);
}
return Promise.resolve();
} else {
console.log('Develop mode');
p.developer_mode = true;
if (process.env.TRAVIS_COMMIT) {
p.version = p.version + '-' + process.env.TRAVIS_COMMIT.substring(0, 7);
} else {
p.version = p.version + '-dev';
}
// write modifications to package
return gulp.src(['package.json'])
.pipe(change(() => JSON.stringify(p)))
.pipe(gulp.dest('./'));
}
});
gulp.task('clean', done => {
rimraf.sync(BUILD_DIR);
rimraf.sync(RELEASE_DIR);
rimraf.sync('node_modules');
done();
});
gulp.task('build_binaries', done => {
let platforms = [];
let arch = argv.win ? 'all' : 'x64';
const mac_arch = 'x64,arm64';
if (argv.win) {
platforms.push('win32');
}
if (argv.macos || argv.osx) {
platforms.push('darwin');
arch = mac_arch;
} // legacy
if (argv.linux) {
platforms.push('linux');
}
if (!platforms.length) {
platforms.push('win32', 'darwin', 'linux');
}
console.log('fetching platforms: ' + JSON.stringify(platforms));
console.log('arch: ' + arch);
let p = require('./package');
let ignored = Object.keys(p['devDependencies']).concat([
'.github',
'coverage',
'.idea',
'__tests__',
'__mocks__',
'vendor',
BUILD_DIR,
RELEASE_DIR,
'scripts',
'\\.(?!env|compilerc|babelrc)', // TRICKY: exclude hidden files except for .env files
]).map(name => new RegExp('(^/' + name + '|' + '^/node_modules/' + name + ')'));
packager({
'asar': true,
'quiet': true,
'arch': arch,
'platform': platforms,
'dir': '.',
'ignore': function (name) {
for (let i = 0, len = ignored.length; i < len; ++i) {
if (ignored[i].test(name)) {
console.log('\t(Ignoring)\t', name);
return true;
}
}
return false;
},
'out': BUILD_DIR,
'app-version': p.version,
'icon': './src/images/icon',
}, (err) => {
if (err) {
throw new Error(err);
}
console.log('Done building...');
done();
});
});
/**
* Releases a linux build
* @param out - the path to which the release will be saved
*/
gulp.task('release-linux', () => {
const p = require('./package');
const archiver = require('archiver');
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-linux-x64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return new Promise((resolve, reject) => {
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
try {
let output = fs.createWriteStream(dest);
output.on('close', resolve);
let archive = archiver.create('zip');
archive.on('error', reject);
archive.pipe(output);
archive.directory(buildPath, p.name);
archive.finalize();
} catch (e) {
reject(e);
}
});
});
/**
* Compiles a .deb package for x64
* @param out - the path to which the release will be saved
*/
gulp.task('release-linux-deb', () => {
const p = require('./package');
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-linux-x64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
// build .deb
const tmp = buildPath.replace(/\/+$/, '') + '.deb.stage';
const optDir = path.join(tmp, 'opt/translationcore');
mkdirp.sync(tmp);
return copy('./scripts/deb', tmp)
.then(() => copy(buildPath, optDir)).then(() => {
// update desktop file with latest version
const desktopPath = path.join(optDir, 'unfoldingword-translationcore.desktop');
let desktop = fs.readFileSync(desktopPath, 'utf8');
desktop = desktop.replace('Version=1.0', 'Version=' + p.version);
fs.writeFileSync(desktopPath, desktop, 'utf8');
console.log('\n\nDEB Desktop Config:\n' + desktop + '\n');
// update control file with latest version
const controlPath = path.join(tmp, 'DEBIAN/control');
let control = fs.readFileSync(controlPath, 'utf8');
control = control.replace('Version: 1.0.0', 'Version: ' + p.version);
fs.writeFileSync(controlPath, control, 'utf8');
console.log('\n\nDEB control:\n' + control + '\n');
// compile
console.log('compiling DEB...');
return new Promise((resolve, reject) => {
const exec = require('child_process').exec;
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
let cmd = `dpkg-deb --build ${tmp} ${dest}`;
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
console.log('DEB output to: ' + dest);
resolve();
}
});
});
});
});
/**
* Compiles a .deb package for arm
* @param out - the path to which the release will be saved
*/
gulp.task('release-linux-deb-arm64', () => {
const p = require('./package');
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-linux-arm64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
// build .deb
const tmp = buildPath.replace(/\/+$/, '') + '.deb.stage';
const optDir = path.join(tmp, 'opt/translationcore');
mkdirp.sync(tmp);
return copy('./scripts/deb', tmp)
.then(() => copy(buildPath, optDir)).then(() => {
// update desktop file with latest version
const desktopPath = path.join(optDir, 'unfoldingword-translationcore.desktop');
let desktop = fs.readFileSync(desktopPath, 'utf8');
desktop = desktop.replace('Version=1.0', 'Version=' + p.version);
fs.writeFileSync(desktopPath, desktop, 'utf8');
console.log('\n\nDEB Desktop Config:\n' + desktop + '\n');
// update control file with latest version
const controlPath = path.join(tmp, 'DEBIAN/control');
let control = fs.readFileSync(controlPath, 'utf8');
control = control.replace('Version: 1.0.0', 'Version: ' + p.version);
fs.writeFileSync(controlPath, control, 'utf8');
console.log('\n\nDEB control:\n' + control + '\n');
// compile
console.log('compiling DEB...');
return new Promise((resolve, reject) => {
const exec = require('child_process').exec;
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
let cmd = `dpkg-deb --build ${tmp} ${dest}`;
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
console.log('DEB output to: ' + dest);
resolve();
}
});
});
});
});
/**
* Releases a macOS x64 build
* @param out - the path to which the release will be saved.
*/
gulp.task('release-macos', () => {
const p = require('./package');
const exec = require('child_process').exec;
const isLinux = /^linux/.test(process.platform);
const isMacOS = /^darwin/.test(process.platform);
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
if (!isLinux && !isMacOS) {
throw new Error('You must be on Linux or macOS to create macOS releases');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-darwin-x64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return new Promise((resolve, reject) => {
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
let cmd = `scripts/osx/makedmg.sh "${p.name}" ${buildPath} ${dest}`;
console.log(cmd);
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});
});
/**
* Releases a macOS build
* @param out - the path to which the release will be saved.
*/
gulp.task('release-macos-universal', () => {
const p = require('./package');
const exec = require('child_process').exec;
const isLinux = /^linux/.test(process.platform);
const isMacOS = /^darwin/.test(process.platform);
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
if (!isLinux && !isMacOS) {
throw new Error('You must be on Linux or macOS to create macOS releases');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-darwin-universal/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return new Promise((resolve, reject) => {
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
let cmd = `scripts/osx/makedmg.sh "${p.name}" ${buildPath} ${dest}`;
console.log(cmd);
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});
});
/**
* Releases a macOS build
* @param out - the path to which the release will be saved.
*/
gulp.task('release-macos-arm64', () => {
const p = require('./package');
const exec = require('child_process').exec;
const isLinux = /^linux/.test(process.platform);
const isMacOS = /^darwin/.test(process.platform);
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
if (!isLinux && !isMacOS) {
throw new Error('You must be on Linux or macOS to create macOS releases');
}
mkdirp.sync('release');
const buildPath = BUILD_DIR + p.name + '-darwin-arm64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return new Promise((resolve, reject) => {
const dest = path.normalize(outPath);
mkdirp.sync(path.dirname(dest));
let cmd = `scripts/osx/makedmg.sh "${p.name}" ${buildPath} ${dest}`;
console.log(cmd);
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});
});
/**
* Releases a Windows x64 build
*/
gulp.task('release-win64', () => {
const p = require('./package');
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
const buildPath = BUILD_DIR + p.name + '-win32-x64/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return releaseWindows('64', buildPath, path.normalize(outPath));
});
/**
* Releases a Windows x32 build
*/
gulp.task('release-win32', () => {
const p = require('./package');
const outPath = argv.out;
if (!outPath || typeof outPath !== 'string') {
throw new Error('The --out argument is required.');
}
const buildPath = BUILD_DIR + p.name + '-win32-ia32/';
if (!fs.existsSync(buildPath)) {
throw new Error(`The build path "${buildPath}" does not exist`);
}
return releaseWindows('32', buildPath, path.normalize(outPath));
});
const GIT_VERSION = '2.35.1';
const GIT_PATCH_LEVEL = '.2';
/**
* Releases a windows build
* @param {string} arch - the os architecture (e.g. 64 or 32)
* @param {string} src - the build directory
* @param {string} dest - the release file path
* @return {Promise<never>}
*/
const releaseWindows = (arch, src, dest) => {
const p = require('./package');
const exec = require('child_process').exec;
const gitVersion = GIT_VERSION;
const gitPatch = GIT_PATCH_LEVEL;
const isLinux = /^linux/.test(process.platform);
const isWindows = /^win/.test(process.platform);
// locate Inno Setup
let isccPath;
if (isLinux) {
isccPath = './scripts/innosetup/iscc';
} else if (isWindows) {
isccPath = `"${process.env['ProgramFiles(x86)']}/Inno Setup 6/ISCC.exe"`;
// try falling back to version 5
if (!fs.existsSync(isccPath.replace(/"/g, ''))) {
isccPath = `"${process.env['ProgramFiles(x86)']}/Inno Setup 5/ISCC.exe"`;
}
} else {
return Promise.reject(
'Windows builds can only be released on linux and windows');
}
// on windows you can manually install Inno Setup
// on linux you can execute ./scripts/innosetup/setup.sh
if (!fs.existsSync(isccPath.replace(/"/g, ''))) {
return Promise.reject(
'Inno Setup is not installed. Please install Inno Setup and try again.');
}
const destDir = path.dirname(dest);
mkdirp.sync(destDir);
// TRICKY: the iss script cannot take the .exe extension on the file name
const file = path.basename(dest, '.exe');
let cmd = `${isccPath} scripts/win_installer.iss /DArch=${arch === '64'
? 'x64'
: 'x86'} /DRootPath=../ /DVersion=${p.version} /DGitVersion=${gitVersion}${gitPatch} /DDestFile=${file} /DDestDir=${destDir} /DBuildDir=${BUILD_DIR} /q`;
return downloadWinGit(gitVersion, arch, gitPatch).then(() => new Promise(function (resolve, reject) {
console.log(`Generating ${arch} bit windows installer`);
console.log(`executing: \n${cmd}\n`);
exec(cmd, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
}));
};
/**
* Downloads git for windows
* @param version - such as 2.35.1
* @param arch
* @param patch - optional patch level such as `.1`
* @return {*}
*/
const downloadWinGit = function (version, arch, patch = '') {
let url = `https://github.com/git-for-windows/git/releases/download/v${version}.windows${patch}/Git-${version}${patch}-${arch}-bit.exe`;
let dir = './vendor';
let dest = dir + `/Git-${version}${patch}-${arch}-bit.exe`;
mkdirp.sync(dir);
if (!fs.existsSync(dest)) {
console.log(`Downloading git ${version} for ${arch} bit from ${url}`);
return request.download(url, dest);
} else {
console.log(`Cache hit: ${dest}`);
return Promise.resolve();
}
};
gulp.task('release', done => {
const p = require('./package');
const archiver = require('archiver');
const exec = require('child_process').exec;
const isLinux = /^linux/.test(process.platform);
const isMacOS = /^darwin/.test(process.platform);
let promises = [];
let platforms = [];
const gitVersion = GIT_VERSION;
const gitPatch = GIT_PATCH_LEVEL;
if (argv.win) {
platforms.push('win32', 'win64');
}
if (argv.win32) {
platforms.push('win32');
}
if (argv.win64) {
platforms.push('win64');
}
if (argv.osx) {
platforms.push('darwin');
} // legacy
if (argv.macos) {
platforms.push('darwin');
}
if (argv.linux) {
platforms.push('linux');
}
if (!platforms.length) {
platforms.push('win32', 'win64', 'darwin', 'linux');
}
/**
*
* @param version - such as 2.35.1
* @param arch 64|32
* @param patch - optional patch level such as `.1`
* @returns {Promise}
*/
const downloadGit = function (version, arch, patch = '') {
let url = `https://github.com/git-for-windows/git/releases/download/v${version}.windows${patch}/Git-${version}${patch}-${arch}-bit.exe`;
let dir = './vendor';
let dest = dir + `/Git-${version}${patch}-${arch}-bit.exe`;
mkdirp.sync(dir);
if (!fs.existsSync(dest)) {
console.log(`Downloading git ${version}${patch} for ${arch} bit from ${url}`);
return request.download(url, dest);
} else {
console.log('Using cached git installer');
return Promise.resolve();
}
};
/**
* This depends on first installing InnoSetup. On linux run ./scripts/innosetup/setup.sh
* On windows download and install from http://www.jrsoftware.org/isinfo.php
*
* @param arch 64|32
* @param os
* @returns {Promise}
*/
const releaseWin = function (arch, os) {
let isccPath;
if (isLinux) {
isccPath = './scripts/innosetup/iscc';
} else if (/^win/.test(process.platform)) {
isccPath = `"${process.env['ProgramFiles(x86)']}/Inno Setup 5/ISCC.exe"`;
} else {
return Promise.reject(
'Windows builds can only be released on linux and windows');
}
// on windows you can manually install Inno Setup
// on linux you can execute ./scripts/innosetup/setup.sh
if (!fs.existsSync(isccPath.replace(/"/g, ''))) {
return Promise.reject(
'Inno Setup is not installed. Please install Inno Setup and try again.');
}
// TRICKY: the iss script cannot take the .exe extension on the file name
let file = `translationCore-win-x${arch}-${p.version}.setup`;
let destDir = `${RELEASE_DIR}win-x${arch}/`;
mkdirp(destDir);
let cmd = `${isccPath} scripts/win_installer.iss /DArch=${arch === '64'
? 'x64'
: 'x86'} /DRootPath=../ /DVersion=${p.version} /DGitVersion=${gitVersion} /DDestFile=${file} /DDestDir=${destDir} /DBuildDir=${BUILD_DIR} /q`;
return new Promise(function (resolve, reject) {
console.log(`Generating ${arch} bit windows installer`);
console.log(`executing: \n${cmd}\n`);
exec(cmd, function (err, stdout, stderr) {
if (err) {
console.error(err);
resolve({
os: os,
status: 'error',
path: null,
});
} else {
resolve({
os: 'win' + arch,
status: 'ok',
path: destDir + file + '.exe',
link: `http://win${arch}.tc-${getBranchType()}.unfoldingword.surge.sh/${file}.exe`,
});
}
});
});
};
mkdirp('release', function () {
for (let os of platforms) {
switch (os) {
case 'win32':
if (fs.existsSync(BUILD_DIR + p.name + '-win32-ia32/')) {
promises.push(downloadGit(gitVersion, '32', gitPatch)
.then(releaseWin.bind(undefined, '32', os)));
} else {
promises.push(Promise.resolve({
os: os,
status: 'missing',
path: null,
}));
}
break;
case 'win64':
if (fs.existsSync(BUILD_DIR + p.name + '-win32-x64/')) {
promises.push(downloadGit(gitVersion, '64', gitPatch)
.then(releaseWin.bind(undefined, '64', os)));
} else {
promises.push(Promise.resolve({
os: os,
status: 'missing',
path: null,
}));
}
break;
case 'darwin':
if ((isLinux || isMacOS) &&
fs.existsSync(BUILD_DIR + p.name + '-darwin-x64/')) {
promises.push(new Promise(function (os, resolve, reject) {
let src = `out/${p.name}-darwin-x64`;
let name = `translationCore-macos-x64-${p.version}.dmg`;
let dest = `${RELEASE_DIR}macos-x64/${name}`;
mkdirp(path.dirname(dest));
let cmd = `scripts/osx/makedmg.sh "${p.name}" ${src} ${dest}`;
console.log(cmd);
exec(cmd, function (err, stdout, stderr) {
if (err) {
console.log(err);
resolve({
os: os,
status: 'error',
path: null,
});
} else {
resolve({
os: os,
status: 'ok',
path: dest,
link: `http://macos.tc-${getBranchType()}.unfoldingword.surge.sh/${name}`,
});
}
});
}.bind(undefined, os)));
} else {
if (!isLinux && !isMacOS) {
console.log(
'You must be on linux or macOS to create macOS releases');
}
promises.push(Promise.resolve({
os: os,
status: 'missing',
path: null,
}));
}
break;
case 'linux':
if (isLinux && fs.existsSync(BUILD_DIR + p.name + '-linux-x64/')) {
promises.push(new Promise(function (os, resolve, reject) {
let name = `translationCore-linux-x64-${p.version}.zip`;
let dest = `${RELEASE_DIR}linux-x64/${name}`;
mkdirp.sync(path.dirname(dest));
try {
let output = fs.createWriteStream(dest);
output.on('close', function () {
resolve({
os: os,
status: 'ok',
path: dest,
link: `http://linux.tc-${getBranchType()}.unfoldingword.surge.sh/${name}`,
});
});
let archive = archiver.create('zip');
archive.on('error', reject);
archive.pipe(output);
archive.directory(BUILD_DIR + p.name + '-linux-x64/', p.name);
archive.finalize();
} catch (e) {
console.error(e);
resolve({
os: os,
status: 'error',
path: null,
});
}
}.bind(undefined, os)));
} else {
if (!isLinux) {
console.log(
'You must be on linux to create linux releases');
}
promises.push(Promise.resolve({
os: os,
status: 'missing',
path: null,
}));
}
break;
default:
console.warn('No release procedure has been defined for ' + os);
}
}
return Promise.all(promises).then(function (values) {
mkdirp(RELEASE_DIR + 'overview');
var releaseNotes = fs.createWriteStream(RELEASE_DIR +
'overview/index.html');
releaseNotes.on('error', function (e) {
console.error(e);
});
releaseNotes.write('<link rel="stylesheet" href="build.css">');
releaseNotes.write(
'<meta name="viewport" content="width=device-width, initial-scale=1.0">');
fs.createReadStream('scripts/releases/builds/build.css')
.pipe(fs.createWriteStream('release/overview/build.css'));
releaseNotes.write(
`<h1>${p.name} <span id="build-num">${p.version}</span></h1><ul>`);
if (process.env.TRAVIS_COMMIT) {
var branch = process.env.TRAVIS_BRANCH;
var commit = process.env.TRAVIS_COMMIT;
var buildNumber = process.env.TRAVIS_BUILD_NUMBER;
var buildId = process.env.TRAVIS_BUILD_ID;
var repoSlug = process.env.TRAVIS_REPO_SLUG;
releaseNotes.write(
`<h2><a href="https://github.com/${repoSlug}/commit/${commit}" target="_blank">Commit ${commit.substring(
0, 7)} on ${branch}</a></h2>`);
releaseNotes.write(
`<h2><a href="https://travis-ci.org/${repoSlug}/builds/${buildId}" target="_blank">Travis build #${buildNumber}</a></h2>`);
}
for (var release of values) {
if (release.status === 'ok') {
release.path = release.path.substring(release.path.indexOf('/') + 1);
releaseNotes.write(
`<li class="ok">${release.os} <span class="status">${release.status}</span> <a href="${release.link}" class="build-link" data-os="${release.os}">Download</a></li>`);
} else {
releaseNotes.write(
`<li class="${release.status}">${release.os} <span class="status">${release.status}</span>`);
}
console.log(`${release.os}: ${release.status} : ${release.path}`);
}
releaseNotes.write('</ul>');
releaseNotes.end();
done();
}).catch(done);
});
});
gulp.task('build', gulp.series('set_mode', 'build_binaries'));