@openvcs/sdk 0.2.0 → 0.2.1
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/README.md +61 -6
- package/bin/openvcs.d.ts +2 -0
- package/bin/openvcs.js +9 -0
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +67 -0
- package/lib/dist.d.ts +30 -0
- package/lib/dist.js +277 -0
- package/lib/fs-utils.d.ts +5 -0
- package/lib/fs-utils.js +76 -0
- package/lib/init.d.ts +7 -0
- package/lib/init.js +274 -0
- package/package.json +17 -6
- package/src/bin/openvcs.ts +9 -0
- package/src/lib/cli.ts +77 -0
- package/src/lib/dist.ts +353 -0
- package/src/lib/fs-utils.ts +78 -0
- package/src/lib/init.ts +330 -0
- package/test/cli.test.js +87 -0
- package/test/dist.test.js +456 -0
- package/test/fs-utils.test.js +124 -0
- package/test/helpers.js +49 -0
- package/bin/openvcs-sdk.js +0 -26
- package/lib/resolve-binary.js +0 -29
- package/scripts/postinstall.js +0 -115
package/scripts/postinstall.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const https = require("node:https");
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
const { URL } = require("node:url");
|
|
5
|
-
|
|
6
|
-
const packageJson = require("../package.json");
|
|
7
|
-
|
|
8
|
-
function targetAssetName() {
|
|
9
|
-
const { platform, arch } = process;
|
|
10
|
-
if (platform === "linux" && arch === "x64") {
|
|
11
|
-
return "openvcs-sdk-linux-x64";
|
|
12
|
-
}
|
|
13
|
-
if (platform === "darwin" && arch === "x64") {
|
|
14
|
-
return "openvcs-sdk-darwin-x64";
|
|
15
|
-
}
|
|
16
|
-
if (platform === "darwin" && arch === "arm64") {
|
|
17
|
-
return "openvcs-sdk-darwin-arm64";
|
|
18
|
-
}
|
|
19
|
-
if (platform === "win32" && arch === "x64") {
|
|
20
|
-
return "openvcs-sdk-win32-x64.exe";
|
|
21
|
-
}
|
|
22
|
-
throw new Error(`Unsupported platform/arch for @openvcs/sdk: ${platform}/${arch}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function vendorBinaryPath() {
|
|
26
|
-
return path.join(
|
|
27
|
-
__dirname,
|
|
28
|
-
"..",
|
|
29
|
-
"vendor",
|
|
30
|
-
process.platform === "win32" ? "openvcs-sdk.exe" : "openvcs-sdk"
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function releaseDownloadUrl() {
|
|
35
|
-
const envUrl = process.env.OPENVCS_SDK_BINARY_URL;
|
|
36
|
-
if (envUrl && envUrl.trim().length > 0) {
|
|
37
|
-
return envUrl;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const tag = `v${packageJson.version}`;
|
|
41
|
-
const asset = targetAssetName();
|
|
42
|
-
return `https://github.com/Open-VCS/OpenVCS-SDK/releases/download/${tag}/${asset}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function download(urlString, destinationPath) {
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
const url = new URL(urlString);
|
|
48
|
-
const request = https.get(
|
|
49
|
-
url,
|
|
50
|
-
{ headers: { "user-agent": "@openvcs/sdk-postinstall" } },
|
|
51
|
-
(response) => {
|
|
52
|
-
if (
|
|
53
|
-
response.statusCode &&
|
|
54
|
-
response.statusCode >= 300 &&
|
|
55
|
-
response.statusCode < 400 &&
|
|
56
|
-
response.headers.location
|
|
57
|
-
) {
|
|
58
|
-
response.resume();
|
|
59
|
-
download(response.headers.location, destinationPath)
|
|
60
|
-
.then(resolve)
|
|
61
|
-
.catch(reject);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (response.statusCode !== 200) {
|
|
66
|
-
response.resume();
|
|
67
|
-
reject(new Error(`Download failed with status ${response.statusCode} for ${urlString}`));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const file = fs.createWriteStream(destinationPath);
|
|
72
|
-
response.pipe(file);
|
|
73
|
-
file.on("finish", () => {
|
|
74
|
-
file.close((closeError) => {
|
|
75
|
-
if (closeError) {
|
|
76
|
-
reject(closeError);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
resolve();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
file.on("error", (error) => {
|
|
83
|
-
response.destroy();
|
|
84
|
-
reject(error);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
request.on("error", reject);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function main() {
|
|
94
|
-
const destination = vendorBinaryPath();
|
|
95
|
-
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
96
|
-
|
|
97
|
-
const localBinary = process.env.OPENVCS_SDK_LOCAL_BINARY;
|
|
98
|
-
if (localBinary && localBinary.trim().length > 0) {
|
|
99
|
-
fs.copyFileSync(localBinary, destination);
|
|
100
|
-
} else {
|
|
101
|
-
const url = releaseDownloadUrl();
|
|
102
|
-
process.stdout.write(`@openvcs/sdk downloading ${url}\n`);
|
|
103
|
-
await download(url, destination);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (process.platform !== "win32") {
|
|
107
|
-
fs.chmodSync(destination, 0o755);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
main().catch((error) => {
|
|
112
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
113
|
-
process.stderr.write(`@openvcs/sdk postinstall failed: ${detail}\n`);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
});
|