@sdk-liuzhaoliang/cli 1.0.46
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/ve +3 -0
- package/install.js +194 -0
- package/package.json +37 -0
package/bin/ve
ADDED
package/install.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require("child_process");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
const VERSION = "1.0.46";
|
|
9
|
+
const DEFAULT_DOWNLOAD_BASE_URL = "https://vecli-demo.tos-cn-beijing.volces.com/ve";
|
|
10
|
+
const DOWNLOAD_BASE_URL = normalizeBaseURL(
|
|
11
|
+
process.env.VOLCENGINE_CLI_DOWNLOAD_BASE_URL || DEFAULT_DOWNLOAD_BASE_URL
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const PLATFORM_MAP = {
|
|
15
|
+
darwin: "darwin",
|
|
16
|
+
linux: "linux",
|
|
17
|
+
win32: "windows",
|
|
18
|
+
freebsd: "freebsd",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const ARCH_MAP = {
|
|
22
|
+
x64: "amd64",
|
|
23
|
+
arm64: "arm64",
|
|
24
|
+
ia32: "386",
|
|
25
|
+
arm: "arm",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const SUPPORTED_TARGETS = {
|
|
29
|
+
darwin: ["amd64", "arm64"],
|
|
30
|
+
linux: ["amd64", "386", "arm", "arm64"],
|
|
31
|
+
freebsd: ["amd64", "386", "arm", "arm64"],
|
|
32
|
+
windows: ["amd64", "386", "arm64"],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function normalizeBaseURL(url) {
|
|
36
|
+
return String(url || "").replace(/\/+$/, "");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function binaryNameForPlatform(platform) {
|
|
40
|
+
return platform === "win32" ? "ve.exe" : "ve";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function targetForPlatform(platform, arch) {
|
|
44
|
+
const targetPlatform = PLATFORM_MAP[platform];
|
|
45
|
+
const targetArch = ARCH_MAP[arch];
|
|
46
|
+
|
|
47
|
+
if (!targetPlatform || !targetArch) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const supportedArchs = SUPPORTED_TARGETS[targetPlatform] || [];
|
|
52
|
+
if (supportedArchs.indexOf(targetArch) === -1) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
platform: targetPlatform,
|
|
58
|
+
arch: targetArch,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function archiveNameForTarget(target, version) {
|
|
63
|
+
return `volcengine-cli_${version}_${target.platform}_${target.arch}.zip`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function archiveURLForTarget(target, version, downloadBaseURL) {
|
|
67
|
+
const baseURL = normalizeBaseURL(downloadBaseURL);
|
|
68
|
+
return `${baseURL}/v${version}/${archiveNameForTarget(target, version)}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function createWindowsVeShim(binDir) {
|
|
72
|
+
const shimPath = path.join(binDir, "ve");
|
|
73
|
+
const shim = `#!/usr/bin/env node
|
|
74
|
+
|
|
75
|
+
const { spawnSync } = require("child_process");
|
|
76
|
+
const path = require("path");
|
|
77
|
+
|
|
78
|
+
const exePath = path.join(__dirname, "ve.exe");
|
|
79
|
+
const result = spawnSync(exePath, process.argv.slice(2), { stdio: "inherit" });
|
|
80
|
+
|
|
81
|
+
if (result.error) {
|
|
82
|
+
console.error(result.error.message);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync(shimPath, shim);
|
|
90
|
+
fs.chmodSync(shimPath, 0o755);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function download(url) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const follow = (url) => {
|
|
96
|
+
https.get(url, (res) => {
|
|
97
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
98
|
+
follow(res.headers.location);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (res.statusCode !== 200) {
|
|
102
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const chunks = [];
|
|
106
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
107
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
108
|
+
res.on("error", reject);
|
|
109
|
+
}).on("error", reject);
|
|
110
|
+
};
|
|
111
|
+
follow(url);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function install() {
|
|
116
|
+
const target = targetForPlatform(process.platform, process.arch);
|
|
117
|
+
|
|
118
|
+
if (!target) {
|
|
119
|
+
console.error(`Unsupported platform: ${process.platform} ${process.arch}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const zipName = archiveNameForTarget(target, VERSION);
|
|
124
|
+
const url = archiveURLForTarget(target, VERSION, DOWNLOAD_BASE_URL);
|
|
125
|
+
const binDir = path.join(__dirname, "bin");
|
|
126
|
+
const isWindows = process.platform === "win32";
|
|
127
|
+
const binaryName = binaryNameForPlatform(process.platform);
|
|
128
|
+
const binPath = path.join(binDir, binaryName);
|
|
129
|
+
|
|
130
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
131
|
+
console.log(`Downloading ${zipName}...`);
|
|
132
|
+
|
|
133
|
+
const data = await download(url);
|
|
134
|
+
const tmpDir = path.join(__dirname, ".tmp");
|
|
135
|
+
const zipPath = path.join(tmpDir, zipName);
|
|
136
|
+
|
|
137
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
138
|
+
fs.writeFileSync(zipPath, data);
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
if (isWindows) {
|
|
142
|
+
execSync(
|
|
143
|
+
`powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${tmpDir}' -Force"`,
|
|
144
|
+
{ stdio: "pipe" }
|
|
145
|
+
);
|
|
146
|
+
} else {
|
|
147
|
+
execSync(`unzip -o -q "${zipPath}" -d "${tmpDir}"`, { stdio: "pipe" });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const extracted = fs.readdirSync(tmpDir);
|
|
151
|
+
const veBinary = extracted.find((f) => f === "ve" || f === "ve.exe");
|
|
152
|
+
|
|
153
|
+
if (!veBinary) {
|
|
154
|
+
console.error("Could not find 've' binary in zip archive. Found:", extracted);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fs.copyFileSync(path.join(tmpDir, veBinary), binPath);
|
|
159
|
+
|
|
160
|
+
if (isWindows) {
|
|
161
|
+
createWindowsVeShim(binDir);
|
|
162
|
+
} else {
|
|
163
|
+
fs.chmodSync(binPath, 0o755);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (process.platform === "darwin") {
|
|
167
|
+
try {
|
|
168
|
+
execSync(`xattr -d com.apple.quarantine "${binPath}"`, { stdio: "pipe" });
|
|
169
|
+
} catch (_) {
|
|
170
|
+
// Attribute may not exist, ignore.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log(`Volcengine CLI v${VERSION} installed for ${target.platform}/${target.arch}`);
|
|
175
|
+
} finally {
|
|
176
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (require.main === module) {
|
|
181
|
+
install().catch((err) => {
|
|
182
|
+
console.error("Installation failed:", err.message);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = {
|
|
188
|
+
archiveNameForTarget,
|
|
189
|
+
archiveURLForTarget,
|
|
190
|
+
binaryNameForPlatform,
|
|
191
|
+
createWindowsVeShim,
|
|
192
|
+
normalizeBaseURL,
|
|
193
|
+
targetForPlatform,
|
|
194
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sdk-liuzhaoliang/cli",
|
|
3
|
+
"version": "1.0.46",
|
|
4
|
+
"description": "Volcengine CLI test package for sdk-liuzhaoliang",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ve": "bin/ve"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepack": "node -e \"const fs=require('fs');fs.mkdirSync('bin',{recursive:true});fs.writeFileSync('bin/ve','#!/usr/bin/env node\\nconsole.error(\\\"ve not installed. Run npm rebuild @sdk-liuzhaoliang/cli\\\");\\nprocess.exit(1);\\n');fs.chmodSync('bin/ve',0o755)\"",
|
|
10
|
+
"postinstall": "node install.js",
|
|
11
|
+
"test": "node install_test.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/",
|
|
15
|
+
"install.js"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"volcengine",
|
|
19
|
+
"cli",
|
|
20
|
+
"cloud",
|
|
21
|
+
"火山引擎"
|
|
22
|
+
],
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/sdk-liuzhaoliang/volcengine-cli"
|
|
27
|
+
},
|
|
28
|
+
"os": [
|
|
29
|
+
"darwin",
|
|
30
|
+
"linux",
|
|
31
|
+
"win32",
|
|
32
|
+
"freebsd"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=14"
|
|
36
|
+
}
|
|
37
|
+
}
|