@eggplanty/mycli 0.1.17 → 0.1.20
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 +1 -1
- package/scripts/install.js +46 -15
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const https = require("https");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const os = require("os");
|
|
4
6
|
|
|
5
7
|
const VERSION = require("../package.json").version;
|
|
6
8
|
const REPO = "eggplanty/test_npm";
|
|
@@ -27,27 +29,32 @@ if (!platform || !arch) {
|
|
|
27
29
|
process.exit(1);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
32
|
+
const isWindows = process.platform === "win32";
|
|
33
|
+
const ext = isWindows ? ".zip" : ".tar.gz";
|
|
34
|
+
const archiveName = `${NAME}-${VERSION}-${platform}-${arch}${ext}`;
|
|
35
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
|
|
36
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
37
|
+
const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
|
|
34
38
|
|
|
35
|
-
fs.mkdirSync(
|
|
39
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
36
40
|
|
|
37
|
-
function download(url,
|
|
41
|
+
function download(url, destPath) {
|
|
38
42
|
return new Promise((resolve, reject) => {
|
|
39
43
|
const client = url.startsWith("https") ? https : require("http");
|
|
40
44
|
client
|
|
41
45
|
.get(url, (res) => {
|
|
42
46
|
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
43
|
-
return download(res.headers.location,
|
|
47
|
+
return download(res.headers.location, destPath).then(
|
|
48
|
+
resolve,
|
|
49
|
+
reject
|
|
50
|
+
);
|
|
44
51
|
}
|
|
45
52
|
if (res.statusCode !== 200) {
|
|
46
53
|
return reject(
|
|
47
54
|
new Error(`Download failed with status ${res.statusCode}: ${url}`)
|
|
48
55
|
);
|
|
49
56
|
}
|
|
50
|
-
const file = fs.createWriteStream(
|
|
57
|
+
const file = fs.createWriteStream(destPath);
|
|
51
58
|
res.pipe(file);
|
|
52
59
|
file.on("finish", () => {
|
|
53
60
|
file.close();
|
|
@@ -58,12 +65,36 @@ function download(url, dest) {
|
|
|
58
65
|
});
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
.
|
|
68
|
+
async function install() {
|
|
69
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "mycli-"));
|
|
70
|
+
const archivePath = path.join(tmpDir, archiveName);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
await download(url, archivePath);
|
|
74
|
+
|
|
75
|
+
if (isWindows) {
|
|
76
|
+
execSync(
|
|
77
|
+
`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
|
|
78
|
+
{ stdio: "ignore" }
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, {
|
|
82
|
+
stdio: "ignore",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const binaryName = NAME + (isWindows ? ".exe" : "");
|
|
87
|
+
const extractedBinary = path.join(tmpDir, binaryName);
|
|
88
|
+
|
|
89
|
+
fs.copyFileSync(extractedBinary, dest);
|
|
63
90
|
fs.chmodSync(dest, 0o755);
|
|
64
91
|
console.log(`${NAME} v${VERSION} installed successfully`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
} finally {
|
|
93
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
install().catch((err) => {
|
|
98
|
+
console.error(`Failed to install ${NAME}:`, err.message);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|