@varavel/vdl 0.4.0-alpha.2 → 0.4.0-alpha.4
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.js +49 -0
- package/index.js +1 -2
- package/install.js +74 -14
- package/package.json +11 -9
package/bin.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("node:child_process");
|
|
4
|
+
const { getBinaryPath } = require("./index.js");
|
|
5
|
+
const { install } = require("./install.js");
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
let binPath;
|
|
9
|
+
try {
|
|
10
|
+
binPath = getBinaryPath();
|
|
11
|
+
} catch (_) {
|
|
12
|
+
try {
|
|
13
|
+
await install();
|
|
14
|
+
binPath = getBinaryPath();
|
|
15
|
+
} catch (installError) {
|
|
16
|
+
console.error(installError.message);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
|
|
23
|
+
// Spawn vdl
|
|
24
|
+
const child = spawn(binPath, args, {
|
|
25
|
+
stdio: ["inherit", "inherit", "inherit"],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Propagate OS signals
|
|
29
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
30
|
+
signals.forEach((sig) => {
|
|
31
|
+
process.on(sig, () => {
|
|
32
|
+
if (child.pid) child.kill(sig);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
child.on("exit", (code) => {
|
|
37
|
+
process.exit(code || 0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
child.on("error", (err) => {
|
|
41
|
+
console.error(err.message);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main().catch((err) => {
|
|
47
|
+
console.error(err.message);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ function getBinaryPath() {
|
|
|
14
14
|
if (!fs.existsSync(binaryPath)) {
|
|
15
15
|
throw new Error(
|
|
16
16
|
`VDL binary not found at ${binaryPath}. ` +
|
|
17
|
-
`Installation may have failed. Try reinstalling: npm install @varavel/vdl`,
|
|
17
|
+
`Installation may have failed. Try reinstalling: npm install --global @varavel/vdl`,
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -33,7 +33,6 @@ function getVersion() {
|
|
|
33
33
|
module.exports = {
|
|
34
34
|
getBinaryPath,
|
|
35
35
|
getVersion,
|
|
36
|
-
binaryPath: getBinaryPath(),
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
// If run directly, print the binary path
|
package/install.js
CHANGED
|
@@ -4,6 +4,7 @@ const { execSync } = require("node:child_process");
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
const https = require("node:https");
|
|
7
|
+
const crypto = require("node:crypto");
|
|
7
8
|
|
|
8
9
|
const PLATFORM_MAP = {
|
|
9
10
|
darwin: "darwin",
|
|
@@ -64,19 +65,67 @@ function getBinaryName() {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @returns {string}
|
|
68
|
+
* Gets the release filename for the current platform/arch.
|
|
69
|
+
* @returns {string} Filename (e.g., vdl_linux_amd64.tar.gz)
|
|
69
70
|
*/
|
|
70
|
-
function
|
|
71
|
-
const version = getVersion();
|
|
71
|
+
function getReleaseFilename() {
|
|
72
72
|
const platform = getPlatform();
|
|
73
73
|
const arch = getArch();
|
|
74
74
|
const ext = platform === "windows" ? "zip" : "tar.gz";
|
|
75
|
-
|
|
75
|
+
return `vdl_${platform}_${arch}.${ext}`;
|
|
76
|
+
}
|
|
76
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Constructs the GitHub release download URL for the current platform.
|
|
80
|
+
* @returns {string} Download URL
|
|
81
|
+
*/
|
|
82
|
+
function getDownloadURL() {
|
|
83
|
+
const version = getVersion();
|
|
84
|
+
const filename = getReleaseFilename();
|
|
77
85
|
return `https://github.com/varavelio/vdl/releases/download/v${version}/${filename}`;
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Constructs the GitHub release checksums URL.
|
|
90
|
+
* @returns {string} Checksums URL
|
|
91
|
+
*/
|
|
92
|
+
function getChecksumsURL() {
|
|
93
|
+
const version = getVersion();
|
|
94
|
+
return `https://github.com/varavelio/vdl/releases/download/v${version}/checksums.txt`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Verifies the SHA256 checksum of the downloaded buffer.
|
|
99
|
+
* @param {Buffer} binaryBuffer - The downloaded file buffer
|
|
100
|
+
* @param {Buffer} checksumsBuffer - The downloaded checksums.txt buffer
|
|
101
|
+
* @param {string} filename - The expected filename in checksums.txt
|
|
102
|
+
* @throws {Error} If checksum verification fails
|
|
103
|
+
*/
|
|
104
|
+
function verifyChecksum(binaryBuffer, checksumsBuffer, filename) {
|
|
105
|
+
const checksums = checksumsBuffer.toString("utf8");
|
|
106
|
+
const expectedLine = checksums
|
|
107
|
+
.split("\n")
|
|
108
|
+
.find((line) => line.trim().endsWith(filename));
|
|
109
|
+
|
|
110
|
+
if (!expectedLine) {
|
|
111
|
+
throw new Error(`Checksum for ${filename} not found in checksums.txt`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Checksums file format is: <hash> <filename>
|
|
115
|
+
const expectedHash = expectedLine.split(/\s+/)[0].trim();
|
|
116
|
+
|
|
117
|
+
const calculatedHash = crypto
|
|
118
|
+
.createHash("sha256")
|
|
119
|
+
.update(binaryBuffer)
|
|
120
|
+
.digest("hex");
|
|
121
|
+
|
|
122
|
+
if (expectedHash !== calculatedHash) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Checksum verification failed for ${filename}.\nExpected: ${expectedHash}\nCalculated: ${calculatedHash}`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
80
129
|
/**
|
|
81
130
|
* Ensures the bin directory exists and returns its path.
|
|
82
131
|
* @returns {string} Absolute path to the bin directory
|
|
@@ -256,11 +305,8 @@ function download(url) {
|
|
|
256
305
|
}
|
|
257
306
|
|
|
258
307
|
const chunks = [];
|
|
259
|
-
let totalLength = 0;
|
|
260
|
-
|
|
261
308
|
response.on("data", (chunk) => {
|
|
262
309
|
chunks.push(chunk);
|
|
263
|
-
totalLength += chunk.length;
|
|
264
310
|
});
|
|
265
311
|
|
|
266
312
|
response.on("end", () => {
|
|
@@ -282,15 +328,26 @@ async function install() {
|
|
|
282
328
|
try {
|
|
283
329
|
const platform = getPlatform();
|
|
284
330
|
const binaryName = getBinaryName();
|
|
285
|
-
const
|
|
331
|
+
const filename = getReleaseFilename();
|
|
332
|
+
const downloadUrl = getDownloadURL();
|
|
333
|
+
const checksumsUrl = getChecksumsURL();
|
|
286
334
|
const binDir = ensureBinDir();
|
|
287
335
|
|
|
288
|
-
|
|
336
|
+
console.log(`VDL: Downloading ${filename}...`);
|
|
289
337
|
|
|
338
|
+
const [binaryBuffer, checksumsBuffer] = await Promise.all([
|
|
339
|
+
download(downloadUrl),
|
|
340
|
+
download(checksumsUrl),
|
|
341
|
+
]);
|
|
342
|
+
|
|
343
|
+
console.log("VDL: Verifying checksum...");
|
|
344
|
+
verifyChecksum(binaryBuffer, checksumsBuffer, filename);
|
|
345
|
+
|
|
346
|
+
console.log("VDL: Extracting...");
|
|
290
347
|
if (platform === "windows") {
|
|
291
|
-
await extractZip(
|
|
348
|
+
await extractZip(binaryBuffer, binDir, binaryName);
|
|
292
349
|
} else {
|
|
293
|
-
await extractTarGz(
|
|
350
|
+
await extractTarGz(binaryBuffer, binDir, binaryName);
|
|
294
351
|
}
|
|
295
352
|
|
|
296
353
|
const binaryPath = path.join(binDir, binaryName);
|
|
@@ -301,9 +358,12 @@ async function install() {
|
|
|
301
358
|
if (process.platform !== "win32") {
|
|
302
359
|
fs.chmodSync(binaryPath, 0o755);
|
|
303
360
|
}
|
|
361
|
+
|
|
362
|
+
console.log(`VDL: Installation complete!`);
|
|
363
|
+
console.log(`VDL: Run 'vdl --version' to verify.`);
|
|
304
364
|
} catch (error) {
|
|
305
|
-
console.error("Installation failed
|
|
306
|
-
console.error(error.message);
|
|
365
|
+
console.error("VDL: Installation failed");
|
|
366
|
+
console.error(`VDL: ${error.message}`);
|
|
307
367
|
process.exit(1);
|
|
308
368
|
}
|
|
309
369
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varavel/vdl",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.4",
|
|
4
4
|
"description": "Open-source cross-language definition engine for modern stacks. Define your data structures, APIs, contracts, and generate type-safe code for your backend and frontend instantly.",
|
|
5
5
|
"author": "Varavel",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://varavel.com/vdl",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/varavelio/vdl.git",
|
|
10
|
+
"url": "git+https://github.com/varavelio/vdl.git",
|
|
11
11
|
"directory": "installers/npm"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/varavelio/vdl/issues"
|
|
15
15
|
},
|
|
16
|
+
"type": "commonjs",
|
|
16
17
|
"main": "index.js",
|
|
17
18
|
"bin": {
|
|
18
|
-
"vdl": "bin
|
|
19
|
+
"vdl": "bin.js"
|
|
19
20
|
},
|
|
21
|
+
"files": [
|
|
22
|
+
"bin.js",
|
|
23
|
+
"install.js",
|
|
24
|
+
"index.js",
|
|
25
|
+
"package.json",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
20
28
|
"scripts": {
|
|
21
29
|
"postinstall": "node install.js"
|
|
22
30
|
},
|
|
@@ -38,11 +46,5 @@
|
|
|
38
46
|
"cpu": [
|
|
39
47
|
"x64",
|
|
40
48
|
"arm64"
|
|
41
|
-
],
|
|
42
|
-
"files": [
|
|
43
|
-
"bin/",
|
|
44
|
-
"install.js",
|
|
45
|
-
"index.js",
|
|
46
|
-
"README.md"
|
|
47
49
|
]
|
|
48
50
|
}
|