-
Notifications
You must be signed in to change notification settings - Fork 32
/
mk
executable file
·124 lines (117 loc) · 4.31 KB
/
mk
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
#!/usr/bin/env node
// instead of a Makefile
process.chdir(__dirname);
const rq = require;
const fs = rq('fs');
const path = rq('path');
const { execSync } = rq('child_process');
const async = rq('async');
const { generateLicenses } = rq('./generate-licenses');
const sh = x => execSync(x, { encoding: 'utf8' }).replace(/[\r\n]/g, ''); // exec in shell
const rf = x => fs.readFileSync(x, 'utf8'); // read file
const wf = (x, y) => fs.writeFileSync(x, y); // write file
const mv = (x, y) => fs.renameSync(x, y); // move/rename file
const md = (x) => { if (!fs.existsSync(x)) { md(path.dirname(x)); fs.mkdirSync(x); } }; // mkdir -p
const rm = (x) => {
let s;
try { s = fs.lstatSync(x); } catch (_) { /**/ }
if (s) {
if (s.isDirectory()) {
fs.readdirSync(x).map(y => rm(`${x}/${y}`));
fs.rmdirSync(x);
} else { fs.unlinkSync(x); }
}
};
const pj = JSON.parse(rf('package.json'));
// v:version string - "x.y.z" where z is the number of commits since the beginning of the project
const v = `${pj.version.replace(/\.0$/, '')}.${sh('git rev-list --count HEAD')}`;
const isDyalogBuild = /^dyalog/.test(pj.name);
const tasks = { };
let buildDone = 0;
const b = (f) => {
if (buildDone) { f(); return; }
md('_'); wf('_/version', v); console.info(`v${v}`);
const vi = {
versionInfo: {
version: v,
date: sh('git show -s HEAD --pretty=format:%ci'),
rev: sh('git rev-parse HEAD'),
},
};
wf('_/version.js', `D=${JSON.stringify(vi)}`);
buildDone = 1; f();
};
const incl = new RegExp('^$'
+ '|^/(D\\.png|favicon.*|[^/]*\\.html|main\\.js|package\\.json)$'
+ '|^/(src|lib|node_modules|_)(/|$)'
+ '|^/style($|/(fonts|img)|.*\\.css$)');
const pkg = (x, y, f) => {
rq('electron-packager')({
dir: '.',
platform: x,
arch: y,
tmpdir: '/tmp/ridebuild',
out: `_/${pj.name}`,
overwrite: true,
'download.cache': 'cache',
icon: 'D',
ignore: p => (!incl.test(p) && !(x === 'win32' && /^\/windows-ime(\/set-ime.exe|$)/.test(p)))
|| /monaco-editor\/(dev|esm|min-maps)/.test(p)
|| /toastr\/(?!build($|\/toastr.min))/.test(p)
|| /jquery\/(?!dist($|\/jquery\.min\.js))/.test(p)
|| /node_modules\/.*\/node_gyp_bins/.test(p)
|| /node_modules\/\.bin/.test(p)
|| /\/test/.test(p)
|| /\.map$/.test(p),
appBundleId: `com.dyalog.${pj.name}`,
appCopyright: `(c) 2014-${new Date().getFullYear()} Dyalog Ltd`,
appVersion: isDyalogBuild ? process.env.APPVERSION : v,
buildVersion: isDyalogBuild ? process.env.APPVERSION : v,
appCategoryType: 'public.app-category.developer-tools',
extendInfo: isDyalogBuild ? 'CI/packagescripts/osx/Info.plist' : null,
win32metadata: { // ends up in Windows Explorer's right click > Properties
CompanyName: 'Dyalog Ltd',
FileDescription: 'Cross-platform IDE for Dyalog APL',
OriginalFilename: `${pj.productName}.exe`,
ProductName: 'Ride',
InternalName: 'Ride',
},
}).then(() => {
const d = `_/${pj.name}/${pj.productName}-${x}-${y}`;
rm(`${d}/version`);
fs.existsSync(`${d}/LICENSE`) && mv(`${d}/LICENSE`, `${d}/LICENSE.electron`);
generateLicenses(`${d}/ThirdPartyNotices.txt`);
f();
}, e => f(e));
};
const l = (f) => { b(e => (e ? f(e) : pkg('linux', 'x64', f))); };
const w = (f) => { b(e => (e ? f(e) : pkg('win32', 'ia32', f))); };
const o = (f) => { b(e => (e ? f(e) : pkg('darwin', 'x64', f))); };
const oa= (f) => { b(e => (e ? f(e) : pkg('darwin', 'arm64', f))); };
const m = (f) => { b(e => (e ? f(e) : pkg('mas', 'x64', f))); };
const ma= (f) => { b(e => (e ? f(e) : pkg('mas', 'arm64', f))); };
const a = (f) => { b(e => (e ? f(e) : pkg('linux', 'armv7l', f))); };
const d = (f) => { async.series([l, w, o, a], (e) => { f(e); }); };
const c = (f) => { rm('_'); rm('/tmp/ridebuild'); f(); };
tasks.b = b; tasks.build = b;
tasks.l = l; tasks.linux = l;
tasks.w = w; tasks.win = w;
tasks.o = o; tasks.osx = o;
tasks.oa=oa; tasks.osxarm = oa;
tasks.m = m; tasks.mas = m;
tasks.ma=ma; tasks.masarm = ma;
tasks.a = a; tasks.arm = a;
tasks.d = d; tasks.dist = d;
tasks.c = c; tasks.clean = c;
async.each(
process.argv.length > 2 ? process.argv.slice(2) : ['build'],
(x, f) => {
if (tasks[x]) {
tasks[x](f);
} else {
process.stderr.write(`ERROR: no task named ${JSON.stringify(x)}\n`);
process.exit(1);
}
},
(e) => { if (e) throw e; }
);