-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_libs.js
69 lines (59 loc) · 1.6 KB
/
build_libs.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
const spawn = require('child_process').spawn;
const os = require('os');
const osPlatform = os.platform();
let params = {};
const runSpawn = (title, cmdStr) => (
new Promise((resolve) => {
cmdStr = cmdStr.split(' ');
if (osPlatform === 'win32') {
cmdStr[0] += '.cmd';
}
const build = spawn(cmdStr[0], cmdStr.slice(1));
build.stdout.on('data', (data) => {
console.warn(data.toString());
});
build.stderr.on('data', (data) => {
console.error(data.toString());
});
build.on('close', (code) => {
console.warn(`${title} exited with code ${code}`);
if (code !== 0) {
process.exit(code);
return;
}
resolve();
});
})
);
const parseCmdParams = () => {
const argv = process.argv;
const features = argv.filter((e) => (e.indexOf('--features') !== -1))
.toString()
.split('=')
.slice(1)
.toString();
const cleanLibs = (argv.indexOf('--clean') !== -1);
params = {
features,
cleanLibs
};
};
const cleanLibs = () => {
const cmd = 'npm run clean-libs';
if (!params.cleanLibs) {
return Promise.resolve(true);
}
return runSpawn('Cleaning native modules', cmd);
};
const buildAuthenticator = () => {
const cmd = `npm run build-libs:${(params.features === 'mock-routing') ? 'mock' : 'actual'}`;
return runSpawn('Build Authenticator', cmd);
};
const copyLibs = () => {
const cmd = `npm run copy-binaries:${(osPlatform === 'win32') ? 'win' : 'unix'}`;
return runSpawn('Copy Authenticator files', cmd);
};
parseCmdParams();
cleanLibs()
.then(() => buildAuthenticator())
.then(() => copyLibs());