-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy-binaries.js
38 lines (30 loc) · 1.34 KB
/
copy-binaries.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
const fs = require('fs');
const path = require('path');
const lastCommit = require('git-last-commit');
const mkdir = require('mkdirp');
const cwd = process.cwd();
const numArgs = process.argv.length;
if (4 > numArgs) {
console.error('You must provide the path where the binaries should be copied.');
process.exit(5);
}
const nodeName = fs.readFileSync(path.join(cwd, 'node', 'Cargo.toml'), 'utf-8').match(/\[\[bin\]\]\nname = '(.+)'/);
if (!nodeName) {
console.error('Cannot find node name in Cargo file.');
process.exit(6);
}
const runtimeName = fs.readFileSync(path.join(cwd, 'runtime', 'Cargo.toml'), 'utf-8').match(/name = '(.+)'/);
if (!runtimeName) {
console.error('Cannot find runtime name in Cargo file.');
process.exit(7);
}
mkdir.sync(path.join(cwd, process.argv[3]));
lastCommit.getLastCommit((err, info) => {
if (err) {
console.error('Cannot get last git commit.');
process.exit(8);
}
fs.copyFileSync(path.join(cwd, 'target', 'release', nodeName[1]), path.join(cwd, process.argv[3], `${nodeName[1]}-${info.shortHash}`));
const underbarredRuntime = runtimeName[1].replace(/-/g, '_');
fs.copyFileSync(path.join(cwd, 'target', 'release', 'wbuild', runtimeName[1], `${underbarredRuntime}.compact.wasm`), path.join(cwd, process.argv[3], `${underbarredRuntime}_${info.shortHash}.compact.wasm`));
}, {dst: cwd});