-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathbuild.js
70 lines (65 loc) · 2.07 KB
/
build.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
import * as childProcess from 'child_process';
import { existsSync, readFileSync } from 'fs';
import os from 'os';
function exec(command, cwd, args = []) {
const child = childProcess.spawn(command, args, {
cwd,
stdio: ['inherit', 'inherit', 'inherit'],
});
return new Promise((resolve, reject) => {
child.on('close', () => {
resolve();
});
child.on('error', err => {
reject(new Error(`${command} error ${err}`));
});
child.on('exit', code => {
if (code !== 0) {
reject(new Error(`${command} exited with code ${code}`));
}
});
});
}
(async () => {
// Detect whether we're under Git. We aren't when building Docker images.
let underGit;
try {
await exec('git', '.', ['submodule']);
underGit = true;
} catch (e) {
underGit = false;
}
// Do the moral equivalent of submodule when not under Git.
// TODO: refactor overlap with git submodules file.
if (!underGit) {
if (!existsSync('moddable')) {
await exec('git', '.', [
'clone',
'https://github.com/Moddable-OpenSource/moddable.git',
'moddable',
]);
}
await exec('git', 'moddable', ['pull', '--ff-only']);
} else {
await exec('git', '.', ['submodule', 'update', '--init']);
}
const pjson = readFileSync(`${__dirname}/../package.json`, 'utf-8');
const pkg = JSON.parse(pjson);
const XSNAP_VERSION = `XSNAP_VERSION=${pkg.version}`;
// Run command depending on the OS
if (os.type() === 'Linux') {
await exec('make', 'makefiles/lin', [XSNAP_VERSION]);
await exec('make', 'makefiles/lin', ['GOAL=debug', XSNAP_VERSION]);
} else if (os.type() === 'Darwin') {
await exec('make', 'makefiles/mac', [XSNAP_VERSION]);
await exec('make', 'makefiles/mac', ['GOAL=debug', XSNAP_VERSION]);
} else if (os.type() === 'Windows_NT') {
await exec('nmake', 'makefiles/win', [XSNAP_VERSION]);
await exec('make', 'makefiles/win', ['GOAL=debug', XSNAP_VERSION]);
} else {
throw new Error(`Unsupported OS found: ${os.type()}`);
}
})().catch(e => {
console.error(e);
process.exit(1);
});