@circlesac/oneup 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/oneup +14 -2
- package/install.js +29 -16
- package/package.json +1 -1
package/bin/oneup
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const { existsSync } = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
7
|
+
const bin = path.join(__dirname, "native", `oneup${ext}`);
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
10
|
+
if (!existsSync(bin)) {
|
|
11
|
+
await require("../install.js");
|
|
12
|
+
}
|
|
13
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
14
|
+
process.exit(result.status ?? 1);
|
|
15
|
+
})();
|
package/install.js
CHANGED
|
@@ -8,9 +8,11 @@ const { version } = require("./package.json");
|
|
|
8
8
|
const REPO = "circlesac/oneup";
|
|
9
9
|
|
|
10
10
|
const PLATFORMS = {
|
|
11
|
-
"darwin-x64": "oneup-x86_64-apple-darwin",
|
|
12
|
-
"darwin-arm64": "oneup-aarch64-apple-darwin",
|
|
13
|
-
"linux-x64": "oneup-x86_64-unknown-linux-gnu",
|
|
11
|
+
"darwin-x64": { artifact: "oneup-x86_64-apple-darwin", ext: ".tar.gz" },
|
|
12
|
+
"darwin-arm64": { artifact: "oneup-aarch64-apple-darwin", ext: ".tar.gz" },
|
|
13
|
+
"linux-x64": { artifact: "oneup-x86_64-unknown-linux-gnu", ext: ".tar.gz" },
|
|
14
|
+
"linux-arm64": { artifact: "oneup-aarch64-unknown-linux-gnu", ext: ".tar.gz" },
|
|
15
|
+
"win32-x64": { artifact: "oneup-x86_64-pc-windows-msvc", ext: ".zip" },
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
async function download(url) {
|
|
@@ -34,35 +36,46 @@ async function download(url) {
|
|
|
34
36
|
|
|
35
37
|
async function main() {
|
|
36
38
|
const platform = `${process.platform}-${process.arch}`;
|
|
37
|
-
const
|
|
39
|
+
const info = PLATFORMS[platform];
|
|
38
40
|
|
|
39
|
-
if (!
|
|
41
|
+
if (!info) {
|
|
40
42
|
console.error(`Unsupported platform: ${platform}`);
|
|
41
43
|
console.error(`Supported: ${Object.keys(PLATFORMS).join(", ")}`);
|
|
42
44
|
process.exit(1);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const
|
|
47
|
+
const { artifact, ext } = info;
|
|
48
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${artifact}${ext}`;
|
|
46
49
|
console.log(`Downloading ${artifact}...`);
|
|
47
50
|
|
|
48
51
|
try {
|
|
49
52
|
const data = await download(url);
|
|
50
|
-
const
|
|
53
|
+
const nativeDir = path.join(__dirname, "bin", "native");
|
|
51
54
|
|
|
52
|
-
if (!fs.existsSync(
|
|
53
|
-
fs.mkdirSync(
|
|
55
|
+
if (!fs.existsSync(nativeDir)) {
|
|
56
|
+
fs.mkdirSync(nativeDir, { recursive: true });
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
const tmpFile = path.join(binDir, "tmp.tar.gz");
|
|
59
|
+
const tmpFile = path.join(nativeDir, `tmp${ext}`);
|
|
58
60
|
fs.writeFileSync(tmpFile, data);
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
if (ext === ".zip") {
|
|
63
|
+
// Windows: use PowerShell to extract zip
|
|
64
|
+
execSync(
|
|
65
|
+
`powershell -Command "Expand-Archive -Force '${tmpFile}' '${nativeDir}'"`,
|
|
66
|
+
{ cwd: nativeDir }
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
// Unix: use tar
|
|
70
|
+
execSync(`tar xzf "${tmpFile}"`, { cwd: nativeDir });
|
|
71
|
+
}
|
|
61
72
|
fs.unlinkSync(tmpFile);
|
|
62
73
|
|
|
63
|
-
// Make executable
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
// Make executable (Unix only)
|
|
75
|
+
if (process.platform !== "win32") {
|
|
76
|
+
const binPath = path.join(nativeDir, "oneup");
|
|
77
|
+
fs.chmodSync(binPath, 0o755);
|
|
78
|
+
}
|
|
66
79
|
|
|
67
80
|
console.log(`Installed oneup v${version}`);
|
|
68
81
|
} catch (err) {
|
|
@@ -71,4 +84,4 @@ async function main() {
|
|
|
71
84
|
}
|
|
72
85
|
}
|
|
73
86
|
|
|
74
|
-
main();
|
|
87
|
+
module.exports = main();
|