@byteplus/cli 1.0.19

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.
Files changed (4) hide show
  1. package/bin/bp +3 -0
  2. package/checksum +26 -0
  3. package/install.js +292 -0
  4. package/package.json +37 -0
package/bin/bp ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ console.error("bp not installed. Run npm rebuild for this package");
3
+ process.exit(1);
package/checksum ADDED
@@ -0,0 +1,26 @@
1
+ 18dc2e7989e14fab7c2487279d212198345555d7983a901b812a5617987878f3 byteplus-cli_1.0.19_darwin_amd64.tar.gz
2
+ db09d0c4f25a6a5dfb68a24f30b7e26640728af9fe6597853eeb2579b355ecf4 byteplus-cli_1.0.19_darwin_amd64.zip
3
+ 9777c6a94d4192bb1537ddd4c7e8ef83519d1bba591590d47d8f89a8f469e018 byteplus-cli_1.0.19_darwin_arm64.tar.gz
4
+ 038bae34debda944f021572e7f50ff31ce2f18c234e6b9d66d071aea08762a34 byteplus-cli_1.0.19_darwin_arm64.zip
5
+ 0a244116d8fbff2bb170fae6cb9dc48e7da11ace980d5da058a68450d7f89998 byteplus-cli_1.0.19_freebsd_386.tar.gz
6
+ 01b6fafad313f54d064ee917ec0744fed8b59b45f0f55ad97189b02cfd1d1ff3 byteplus-cli_1.0.19_freebsd_386.zip
7
+ b7f14fb8573dc4ee7255203fafe4f570ab4a4a6f2d7b02278ad66afeeba71b62 byteplus-cli_1.0.19_freebsd_amd64.tar.gz
8
+ e03aa6a23a47549083c29a78d4cf23d98700d9f78e855f55c0cb709d2f643d59 byteplus-cli_1.0.19_freebsd_amd64.zip
9
+ bef8646fdc0688e4fc19b43cb78305525e0f7e9f02d7a29d2b3ff6c047b193da byteplus-cli_1.0.19_freebsd_arm.tar.gz
10
+ 7c1dfee9f1491cad52f4b321b7ca1ad948939df40711a73572cc16cf29769c06 byteplus-cli_1.0.19_freebsd_arm.zip
11
+ ce2c5e5f33c4479b918e159e7274bda906a4d7a157c4d5cde0aff440661d8621 byteplus-cli_1.0.19_freebsd_arm64.tar.gz
12
+ 6fea21463640e08185ab54cac060804b49b75c07808a22285b7db84fdb30ccf1 byteplus-cli_1.0.19_freebsd_arm64.zip
13
+ d6251eed4f20fd757f7485811e593bb162b6e4d0754f29ef97ece7b7e32080ac byteplus-cli_1.0.19_linux_386.tar.gz
14
+ 3470c821f02d264aae1a8e11be468195958b0e150c290fdcf09ff1ea1de88648 byteplus-cli_1.0.19_linux_386.zip
15
+ 822618f8caa4bdb6027dae587e08af03f660296bfaa56316c96e0ed1b693e28f byteplus-cli_1.0.19_linux_amd64.tar.gz
16
+ ac9fd5bf0eef860e4f920d2b4cb590c2f159aee800f75437b07e866c2455fe78 byteplus-cli_1.0.19_linux_amd64.zip
17
+ 63dd76ae1224a6ea6c1566c9611067730282ba7862ac1cc58d00b3ad82e79a71 byteplus-cli_1.0.19_linux_arm.tar.gz
18
+ fc01d9afb02a70f9df537b1284c371a0786fb99a391a6e66fbbed3b2ac02b9de byteplus-cli_1.0.19_linux_arm.zip
19
+ 460a7e70f10afa87c682a073338e3642ff7d20ea996fb74a961a11422e099a42 byteplus-cli_1.0.19_linux_arm64.tar.gz
20
+ 45679d8cbdffd4b1cf087ec93ddea2a541dd4ab16c33203f6053f6bf4c03e12a byteplus-cli_1.0.19_linux_arm64.zip
21
+ 5a2c9eb5c97d46b8f729972d8b15ce99312825f623c87870a789ea179fe9c767 byteplus-cli_1.0.19_windows_386.tar.gz
22
+ 82e638ed7c9e61d4dc7355e9e063751cb43fa677856f408d4000e6e8bd85522c byteplus-cli_1.0.19_windows_386.zip
23
+ 052eae7490d84ae759acb46a92d0f2b639af6902cd7b13f6e9e697d42b7589ed byteplus-cli_1.0.19_windows_amd64.tar.gz
24
+ fb3f0564f4b4ede594ac847465c8b3f1f212b142d55f72542866fd0272dc246a byteplus-cli_1.0.19_windows_amd64.zip
25
+ 891eb435922bcff595dfaa2cfd387f17f57041716fdbd5e3f780aee088b0ef89 byteplus-cli_1.0.19_windows_arm64.tar.gz
26
+ ad53c2e902383bd7e57a3a2a22e76d0ba663c81eb8e5fe84ac8fc452c3470f6c byteplus-cli_1.0.19_windows_arm64.zip
package/install.js ADDED
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execFileSync } = require("child_process");
4
+ const crypto = require("crypto");
5
+ const https = require("https");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+
9
+ const VERSION = require("./package.json").version;
10
+ const DEFAULT_DOWNLOAD_BASE_URL = "https://cloudcache.volccdn.com/bp";
11
+ const CHECKSUM_PATH = path.join(__dirname, "checksum");
12
+ const OFFICIAL_RELEASES_URL = "https://github.com/byteplus-sdk/byteplus-cli/releases";
13
+ const DOWNLOAD_BASE_URL = normalizeBaseURL(
14
+ process.env.BYTEPLUS_CLI_DOWNLOAD_BASE_URL || DEFAULT_DOWNLOAD_BASE_URL
15
+ );
16
+
17
+ const PLATFORM_MAP = {
18
+ darwin: "darwin",
19
+ linux: "linux",
20
+ win32: "windows",
21
+ freebsd: "freebsd",
22
+ };
23
+
24
+ const ARCH_MAP = {
25
+ x64: "amd64",
26
+ arm64: "arm64",
27
+ ia32: "386",
28
+ arm: "arm",
29
+ };
30
+
31
+ const SUPPORTED_TARGETS = {
32
+ darwin: ["amd64", "arm64"],
33
+ linux: ["amd64", "386", "arm", "arm64"],
34
+ freebsd: ["amd64", "386", "arm", "arm64"],
35
+ windows: ["amd64", "386", "arm64"],
36
+ };
37
+
38
+ function normalizeBaseURL(url) {
39
+ return String(url || "").replace(/\/+$/, "");
40
+ }
41
+
42
+ function binaryNameForPlatform(platform) {
43
+ return platform === "win32" ? "bp.exe" : "bp";
44
+ }
45
+
46
+ function targetForPlatform(platform, arch) {
47
+ const targetPlatform = PLATFORM_MAP[platform];
48
+ const targetArch = ARCH_MAP[arch];
49
+
50
+ if (!targetPlatform || !targetArch) {
51
+ return null;
52
+ }
53
+
54
+ const supportedArchs = SUPPORTED_TARGETS[targetPlatform] || [];
55
+ if (supportedArchs.indexOf(targetArch) === -1) {
56
+ return null;
57
+ }
58
+
59
+ return {
60
+ platform: targetPlatform,
61
+ arch: targetArch,
62
+ };
63
+ }
64
+
65
+ function archiveNameForTarget(target, version) {
66
+ return `byteplus-cli_${version}_${target.platform}_${target.arch}.zip`;
67
+ }
68
+
69
+ function archiveURLForTarget(target, version, downloadBaseURL) {
70
+ const baseURL = normalizeBaseURL(downloadBaseURL);
71
+ return `${baseURL}/v${version}/${archiveNameForTarget(target, version)}`;
72
+ }
73
+
74
+ function archiveBasename(filename) {
75
+ return String(filename || "").split(/[\\/]/).pop();
76
+ }
77
+
78
+ function sha256(data) {
79
+ return crypto.createHash("sha256").update(data).digest("hex");
80
+ }
81
+
82
+ function parseChecksum(content) {
83
+ const entries = [];
84
+ String(content || "")
85
+ .split(/\r?\n/)
86
+ .forEach((line, index) => {
87
+ const trimmed = line.trim();
88
+ if (!trimmed) {
89
+ return;
90
+ }
91
+
92
+ const match = trimmed.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
93
+ if (!match) {
94
+ throw new Error(`Invalid checksum line ${index + 1}`);
95
+ }
96
+
97
+ entries.push({
98
+ hash: match[1].toLowerCase(),
99
+ filename: match[2],
100
+ });
101
+ });
102
+ return entries;
103
+ }
104
+
105
+ function checksumForArchive(content, archiveName) {
106
+ const match = parseChecksum(content).find(
107
+ (entry) => entry.filename === archiveName || archiveBasename(entry.filename) === archiveName
108
+ );
109
+
110
+ if (!match) {
111
+ throw new Error(`Checksum entry not found for ${archiveName}`);
112
+ }
113
+
114
+ return match.hash;
115
+ }
116
+
117
+ function verifyArchiveChecksum(data, archiveName, checksumPath = CHECKSUM_PATH) {
118
+ let checksumContent;
119
+ try {
120
+ checksumContent = fs.readFileSync(checksumPath, "utf8");
121
+ } catch (err) {
122
+ if (err && err.code === "ENOENT") {
123
+ throw new Error(`Checksum file not found: ${checksumPath}`);
124
+ }
125
+ throw err;
126
+ }
127
+
128
+ const expected = checksumForArchive(checksumContent, archiveName);
129
+ const actual = sha256(data);
130
+
131
+ if (actual !== expected) {
132
+ throw new Error(
133
+ `Checksum mismatch for ${archiveName}: expected ${expected}, got ${actual}. ` +
134
+ `The downloaded archive may have been tampered with. ` +
135
+ `Please download BytePlus CLI from the official releases page: ${OFFICIAL_RELEASES_URL}`
136
+ );
137
+ }
138
+
139
+ return actual;
140
+ }
141
+
142
+ function downloadErrorMessage(statusCode, url) {
143
+ return (
144
+ `Download failed: HTTP ${statusCode} for ${url}. ` +
145
+ `\nPlease download BytePlus CLI from the official releases page: ${OFFICIAL_RELEASES_URL}`
146
+ );
147
+ }
148
+
149
+ function createWindowsBpShim(binDir) {
150
+ const shimPath = path.join(binDir, "bp");
151
+ const shim = `#!/usr/bin/env node
152
+
153
+ const { spawnSync } = require("child_process");
154
+ const path = require("path");
155
+
156
+ const exePath = path.join(__dirname, "bp.exe");
157
+ const result = spawnSync(exePath, process.argv.slice(2), { stdio: "inherit" });
158
+
159
+ if (result.error) {
160
+ console.error(result.error.message);
161
+ process.exit(1);
162
+ }
163
+
164
+ process.exit(result.status === null ? 1 : result.status);
165
+ `;
166
+
167
+ fs.writeFileSync(shimPath, shim);
168
+ fs.chmodSync(shimPath, 0o755);
169
+ }
170
+
171
+ function download(url) {
172
+ return new Promise((resolve, reject) => {
173
+ const follow = (currentURL) => {
174
+ https
175
+ .get(currentURL, (res) => {
176
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
177
+ res.resume();
178
+ follow(new URL(res.headers.location, currentURL).toString());
179
+ return;
180
+ }
181
+ if (res.statusCode !== 200) {
182
+ reject(new Error(downloadErrorMessage(res.statusCode, currentURL)));
183
+ return;
184
+ }
185
+ const chunks = [];
186
+ res.on("data", (chunk) => chunks.push(chunk));
187
+ res.on("end", () => resolve(Buffer.concat(chunks)));
188
+ res.on("error", reject);
189
+ })
190
+ .on("error", reject);
191
+ };
192
+ follow(url);
193
+ });
194
+ }
195
+
196
+ async function install() {
197
+ const target = targetForPlatform(process.platform, process.arch);
198
+
199
+ if (!target) {
200
+ console.error(`Unsupported platform: ${process.platform} ${process.arch}`);
201
+ process.exit(1);
202
+ }
203
+
204
+ const zipName = archiveNameForTarget(target, VERSION);
205
+ const url = archiveURLForTarget(target, VERSION, DOWNLOAD_BASE_URL);
206
+ const binDir = path.join(__dirname, "bin");
207
+ const isWindows = process.platform === "win32";
208
+ const binaryName = binaryNameForPlatform(process.platform);
209
+ const binPath = path.join(binDir, binaryName);
210
+
211
+ fs.mkdirSync(binDir, { recursive: true });
212
+ console.log(`Downloading ${zipName}...`);
213
+
214
+ const data = await download(url);
215
+ console.log(`Verifying ${zipName}...`);
216
+ verifyArchiveChecksum(data, zipName);
217
+
218
+ const tmpDir = path.join(__dirname, ".tmp");
219
+ const zipPath = path.join(tmpDir, zipName);
220
+
221
+ fs.mkdirSync(tmpDir, { recursive: true });
222
+ fs.writeFileSync(zipPath, data);
223
+
224
+ try {
225
+ if (isWindows) {
226
+ execFileSync(
227
+ "powershell",
228
+ [
229
+ "-NoProfile",
230
+ "-Command",
231
+ "Expand-Archive -LiteralPath $args[0] -DestinationPath $args[1] -Force",
232
+ zipPath,
233
+ tmpDir,
234
+ ],
235
+ { stdio: "pipe" }
236
+ );
237
+ } else {
238
+ execFileSync("unzip", ["-o", "-q", zipPath, "-d", tmpDir], { stdio: "pipe" });
239
+ }
240
+
241
+ const extracted = fs.readdirSync(tmpDir);
242
+ const bpBinary = extracted.find((f) => f === "bp" || f === "bp.exe");
243
+
244
+ if (!bpBinary) {
245
+ console.error("Could not find 'bp' binary in zip archive. Found:", extracted);
246
+ process.exit(1);
247
+ }
248
+
249
+ fs.copyFileSync(path.join(tmpDir, bpBinary), binPath);
250
+
251
+ if (isWindows) {
252
+ createWindowsBpShim(binDir);
253
+ } else {
254
+ fs.chmodSync(binPath, 0o755);
255
+ }
256
+
257
+ if (process.platform === "darwin") {
258
+ try {
259
+ execFileSync("xattr", ["-d", "com.apple.quarantine", binPath], { stdio: "pipe" });
260
+ } catch (_) {
261
+ // Attribute may not exist, ignore.
262
+ }
263
+ }
264
+
265
+ console.log(`BytePlus CLI v${VERSION} installed for ${target.platform}/${target.arch}`);
266
+ } finally {
267
+ fs.rmSync(tmpDir, { recursive: true, force: true });
268
+ }
269
+ }
270
+
271
+ if (require.main === module) {
272
+ install().catch((err) => {
273
+ console.error("Installation failed:", err.message);
274
+ process.exit(1);
275
+ });
276
+ }
277
+
278
+ module.exports = {
279
+ archiveNameForTarget,
280
+ archiveURLForTarget,
281
+ binaryNameForPlatform,
282
+ checksumForArchive,
283
+ createWindowsBpShim,
284
+ defaultDownloadBaseURL: DEFAULT_DOWNLOAD_BASE_URL,
285
+ downloadErrorMessage,
286
+ normalizeBaseURL,
287
+ parseChecksum,
288
+ sha256,
289
+ targetForPlatform,
290
+ verifyArchiveChecksum,
291
+ version: VERSION,
292
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@byteplus/cli",
3
+ "version": "1.0.19",
4
+ "description": "BytePlus CLI npm installer",
5
+ "bin": {
6
+ "bp": "bin/bp"
7
+ },
8
+ "scripts": {
9
+ "prepack": "node -e \"const fs=require('fs');fs.mkdirSync('bin',{recursive:true});fs.writeFileSync('bin/bp','#!/usr/bin/env node\\nconsole.error(\\\"bp not installed. Run npm rebuild for this package\\\");\\nprocess.exit(1);\\n');fs.chmodSync('bin/bp',0o755)\"",
10
+ "postinstall": "node install.js",
11
+ "test": "node install_test.js"
12
+ },
13
+ "files": [
14
+ "bin/",
15
+ "checksum",
16
+ "install.js"
17
+ ],
18
+ "keywords": [
19
+ "byteplus",
20
+ "cli",
21
+ "cloud"
22
+ ],
23
+ "license": "Apache-2.0",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/byteplus-sdk/byteplus-cli"
27
+ },
28
+ "os": [
29
+ "darwin",
30
+ "linux",
31
+ "win32",
32
+ "freebsd"
33
+ ],
34
+ "engines": {
35
+ "node": ">=14"
36
+ }
37
+ }