forked from Ratimon/solid-grinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-npm.js
60 lines (49 loc) · 3.05 KB
/
build-npm.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
#!/usr/bin/env node
const args = process.argv.slice(2);
const {execFileSync} = require('child_process')
const fs = require("fs");
const stdio = ["inherit", "inherit", "inherit"];
const version_regex = /version[\s]*=[\s]*"(.*?)"/gm;
const cargo_toml = fs.readFileSync("Cargo.toml", "utf-8");
const version = [...version_regex.exec(cargo_toml)][1];
const pkg_version = (args[0] === 'publish:npm' || args[0] === 'npm:final') ? version : version + '-rc.1';
// ------------------------------------------------------------------------------------------------
// package.json
// ------------------------------------------------------------------------------------------------
const package_json = fs.readFileSync("npm/package.json", "utf-8");
fs.writeFileSync("package.json", package_json.replace("__VERSION__", pkg_version))
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// install.js
// ------------------------------------------------------------------------------------------------
const install_js = fs.readFileSync("npm/install.js", "utf-8");
fs.writeFileSync("install.js", install_js.replace("__VERSION__", version))
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// run.js
// ------------------------------------------------------------------------------------------------
const run_js = fs.readFileSync("npm/run.js", "utf-8");
fs.writeFileSync("run.js", run_js.replace("__VERSION__", version));
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// binary.js
// ------------------------------------------------------------------------------------------------
const binary_js = fs.readFileSync("npm/binary.js", "utf-8");
fs.writeFileSync("binary.js", binary_js.replace("__VERSION__", version));
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// binary.js: just copy
// ------------------------------------------------------------------------------------------------
const binary_install = fs.readFileSync("npm/binary-install.js", "utf-8");
fs.writeFileSync("binary-install.js", binary_install);
// ------------------------------------------------------------------------------------------------
if (args[0] === 'npm:final') {
} else if (args[0] === 'publish:npm') {
execFileSync("npm", ["publish"], {stdio});
} else if (args[0] === 'publish') {
execFileSync("cargo", ["install", "cargo-release"], {stdio});
execFileSync("cargo", ["release", "--execute"], {stdio});
execFileSync("npm", ["publish", "--tag", "rc"], {stdio});
} else {
execFileSync("cargo", ["build"], {stdio});
}