@eggplanty/mycli 0.1.0
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/package.json +32 -0
- package/scripts/install.js +69 -0
- package/scripts/run.js +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eggplanty/mycli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A simple CLI demo built with Go",
|
|
5
|
+
"bin": {
|
|
6
|
+
"mycli": "scripts/run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node scripts/install.js"
|
|
10
|
+
},
|
|
11
|
+
"os": [
|
|
12
|
+
"darwin",
|
|
13
|
+
"linux",
|
|
14
|
+
"win32"
|
|
15
|
+
],
|
|
16
|
+
"cpu": [
|
|
17
|
+
"x64",
|
|
18
|
+
"arm64"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=16"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/eggplanty/test_npm.git"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"files": [
|
|
29
|
+
"scripts/",
|
|
30
|
+
"bin/"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
|
|
5
|
+
const VERSION = require("../package.json").version;
|
|
6
|
+
const REPO = "eggplanty/test_npm";
|
|
7
|
+
const NAME = "mycli";
|
|
8
|
+
|
|
9
|
+
const PLATFORM_MAP = {
|
|
10
|
+
darwin: "darwin",
|
|
11
|
+
linux: "linux",
|
|
12
|
+
win32: "windows",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ARCH_MAP = {
|
|
16
|
+
x64: "amd64",
|
|
17
|
+
arm64: "arm64",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
21
|
+
const arch = ARCH_MAP[process.arch];
|
|
22
|
+
|
|
23
|
+
if (!platform || !arch) {
|
|
24
|
+
console.error(
|
|
25
|
+
`Unsupported platform: ${process.platform}-${process.arch}`
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
31
|
+
const binaryName = `${NAME}-${platform}-${arch}${ext}`;
|
|
32
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryName}`;
|
|
33
|
+
const dest = path.join(__dirname, "..", "bin", NAME + ext);
|
|
34
|
+
|
|
35
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
36
|
+
|
|
37
|
+
function download(url, dest) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const client = url.startsWith("https") ? https : require("http");
|
|
40
|
+
client
|
|
41
|
+
.get(url, (res) => {
|
|
42
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
43
|
+
return download(res.headers.location, dest).then(resolve, reject);
|
|
44
|
+
}
|
|
45
|
+
if (res.statusCode !== 200) {
|
|
46
|
+
return reject(
|
|
47
|
+
new Error(`Download failed with status ${res.statusCode}: ${url}`)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const file = fs.createWriteStream(dest);
|
|
51
|
+
res.pipe(file);
|
|
52
|
+
file.on("finish", () => {
|
|
53
|
+
file.close();
|
|
54
|
+
resolve();
|
|
55
|
+
});
|
|
56
|
+
})
|
|
57
|
+
.on("error", reject);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
download(url, dest)
|
|
62
|
+
.then(() => {
|
|
63
|
+
fs.chmodSync(dest, 0o755);
|
|
64
|
+
console.log(`${NAME} v${VERSION} installed successfully`);
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => {
|
|
67
|
+
console.error(`Failed to install ${NAME}:`, err.message);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
package/scripts/run.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
6
|
+
const bin = path.join(__dirname, "..", "bin", "mycli" + ext);
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
10
|
+
} catch (e) {
|
|
11
|
+
process.exit(e.status || 1);
|
|
12
|
+
}
|