@varavel/vdl 0.0.0-dev

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/README.md +56 -0
  2. package/index.js +42 -0
  3. package/install.js +312 -0
  4. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Varavel Definition Language (VDL)
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @varavel/vdl
9
+ ```
10
+
11
+ Or as a dev dependency:
12
+
13
+ ```bash
14
+ npm install --save-dev @varavel/vdl
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ After installation, the `vdl` command will be available:
20
+
21
+ ```bash
22
+ vdl --help # See available commands
23
+ ```
24
+
25
+ ## Programmatic Usage
26
+
27
+ You can also use this package programmatically in Node.js:
28
+
29
+ ```javascript
30
+ const vdl = require("@varavel/vdl");
31
+ const { execSync } = require("child_process");
32
+
33
+ // Get the path to the binary
34
+ console.log(vdl.binaryPath);
35
+
36
+ // Execute VDL commands
37
+ execSync(`"${vdl.binaryPath}" version`, { stdio: "inherit" });
38
+ ```
39
+
40
+ ## Supported Platforms
41
+
42
+ - **macOS**: x64, ARM64 (Apple Silicon)
43
+ - **Linux**: x64, ARM64
44
+ - **Windows**: x64, ARM64
45
+
46
+ ## How It Works
47
+
48
+ This package downloads the appropriate pre-compiled VDL binary for your platform during installation. The binary is fetched from the [official GitHub releases](https://github.com/varavelio/vdl/releases).
49
+
50
+ ## Documentation
51
+
52
+ Visit https://varavel.com/vdl for full documentation.
53
+
54
+ ## License
55
+
56
+ MIT
package/index.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("node:path");
4
+ const fs = require("node:fs");
5
+
6
+ /**
7
+ * Get the path to the installed VDL binary
8
+ * @returns {string} Absolute path to the vdl binary
9
+ */
10
+ function getBinaryPath() {
11
+ const binaryName = process.platform === "win32" ? "vdl.exe" : "vdl";
12
+ const binaryPath = path.join(__dirname, "bin", binaryName);
13
+
14
+ if (!fs.existsSync(binaryPath)) {
15
+ throw new Error(
16
+ `VDL binary not found at ${binaryPath}. ` +
17
+ `Installation may have failed. Try reinstalling: npm install @varavel/vdl`,
18
+ );
19
+ }
20
+
21
+ return binaryPath;
22
+ }
23
+
24
+ /**
25
+ * Get the version of the installed VDL package (without v prefix)
26
+ * @returns {string} Version string
27
+ */
28
+ function getVersion() {
29
+ const packageJson = require("./package.json");
30
+ return packageJson.version;
31
+ }
32
+
33
+ module.exports = {
34
+ getBinaryPath,
35
+ getVersion,
36
+ binaryPath: getBinaryPath(),
37
+ };
38
+
39
+ // If run directly, print the binary path
40
+ if (require.main === module) {
41
+ console.log(getBinaryPath());
42
+ }
package/install.js ADDED
@@ -0,0 +1,312 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+ const https = require("node:https");
7
+
8
+ const PLATFORM_MAP = {
9
+ darwin: "darwin",
10
+ linux: "linux",
11
+ win32: "windows",
12
+ };
13
+
14
+ const ARCH_MAP = {
15
+ x64: "amd64",
16
+ arm64: "arm64",
17
+ };
18
+
19
+ /**
20
+ * Gets the platform name in VDL release format.
21
+ * @returns {string} Platform name (darwin, linux, or windows)
22
+ * @throws {Error} If the platform is not supported
23
+ */
24
+ function getPlatform() {
25
+ const platform = PLATFORM_MAP[process.platform];
26
+ if (!platform) {
27
+ throw new Error(
28
+ `Unsupported platform: ${process.platform}. VDL supports darwin, linux, and win32.`,
29
+ );
30
+ }
31
+ return platform;
32
+ }
33
+
34
+ /**
35
+ * Gets the architecture name in VDL release format.
36
+ * @returns {string} Architecture name (amd64 or arm64)
37
+ * @throws {Error} If the architecture is not supported
38
+ */
39
+ function getArch() {
40
+ const arch = ARCH_MAP[process.arch];
41
+ if (!arch) {
42
+ throw new Error(
43
+ `Unsupported architecture: ${process.arch}. VDL supports x64 and arm64.`,
44
+ );
45
+ }
46
+ return arch;
47
+ }
48
+
49
+ /**
50
+ * Gets the version from package.json.
51
+ * @returns {string} Version string without 'v' prefix
52
+ */
53
+ function getVersion() {
54
+ const packageJson = require("./package.json");
55
+ return packageJson.version.replace(/^v/, "");
56
+ }
57
+
58
+ /**
59
+ * Gets the binary name for the current platform.
60
+ * @returns {string} Binary name (vdl.exe for Windows, vdl for others)
61
+ */
62
+ function getBinaryName() {
63
+ return process.platform === "win32" ? "vdl.exe" : "vdl";
64
+ }
65
+
66
+ /**
67
+ * Constructs the GitHub release download URL for the current platform.
68
+ * @returns {string} Download URL
69
+ */
70
+ function getDownloadURL() {
71
+ const version = getVersion();
72
+ const platform = getPlatform();
73
+ const arch = getArch();
74
+ const ext = platform === "windows" ? "zip" : "tar.gz";
75
+ const filename = `vdl_${platform}_${arch}.${ext}`;
76
+
77
+ return `https://github.com/varavelio/vdl/releases/download/v${version}/${filename}`;
78
+ }
79
+
80
+ /**
81
+ * Ensures the bin directory exists and returns its path.
82
+ * @returns {string} Absolute path to the bin directory
83
+ */
84
+ function ensureBinDir() {
85
+ const binDir = path.join(__dirname, "bin");
86
+ if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
87
+ return binDir;
88
+ }
89
+
90
+ /**
91
+ * Extracts a tar.gz archive and locates the VDL binary.
92
+ * @param {Buffer} buffer - Archive buffer
93
+ * @param {string} binDir - Target bin directory
94
+ * @param {string} binaryName - Expected binary name
95
+ * @returns {Promise<void>}
96
+ * @throws {Error} If extraction fails or binary not found
97
+ */
98
+ function extractTarGz(buffer, binDir, binaryName) {
99
+ return new Promise((resolve, reject) => {
100
+ const now = Date.now().toString();
101
+ const tempTar = path.join(binDir, `${now}_temp.tar.gz`);
102
+ const tempDir = path.join(binDir, `${now}_temp_extract`);
103
+
104
+ try {
105
+ fs.writeFileSync(tempTar, buffer);
106
+
107
+ if (!fs.existsSync(tempDir)) {
108
+ fs.mkdirSync(tempDir, { recursive: true });
109
+ }
110
+
111
+ execSync(`tar -xzf "${tempTar}" -C "${tempDir}"`, {
112
+ stdio: "pipe",
113
+ });
114
+
115
+ let binaryFound = false;
116
+ const searchPaths = [
117
+ path.join(tempDir, binaryName),
118
+ path.join(tempDir, "vdl", binaryName),
119
+ ];
120
+
121
+ for (const searchPath of searchPaths) {
122
+ if (fs.existsSync(searchPath)) {
123
+ const destPath = path.join(binDir, binaryName);
124
+ fs.copyFileSync(searchPath, destPath);
125
+ fs.chmodSync(destPath, 0o755);
126
+ binaryFound = true;
127
+ break;
128
+ }
129
+ }
130
+
131
+ if (!binaryFound) {
132
+ const files = execSync(`find "${tempDir}" -type f`, {
133
+ encoding: "utf8",
134
+ });
135
+ reject(
136
+ new Error(
137
+ `Binary ${binaryName} not found in archive.\nFound files:\n${files}`,
138
+ ),
139
+ );
140
+ } else {
141
+ resolve();
142
+ }
143
+ } catch (error) {
144
+ reject(new Error(`Failed to extract tar.gz: ${error.message}`));
145
+ } finally {
146
+ try {
147
+ if (fs.existsSync(tempTar)) {
148
+ fs.unlinkSync(tempTar);
149
+ }
150
+ if (fs.existsSync(tempDir)) {
151
+ fs.rmSync(tempDir, { recursive: true, force: true });
152
+ }
153
+ } catch (_) {}
154
+ }
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Extracts a zip archive and locates the VDL binary.
160
+ * @param {Buffer} buffer - Archive buffer
161
+ * @param {string} binDir - Target bin directory
162
+ * @param {string} binaryName - Expected binary name
163
+ * @returns {Promise<void>}
164
+ * @throws {Error} If extraction fails or binary not found
165
+ */
166
+ function extractZip(buffer, binDir, binaryName) {
167
+ return new Promise((resolve, reject) => {
168
+ const now = Date.now().toString();
169
+ const tempZip = path.join(binDir, `${now}_temp.zip`);
170
+ const tempDir = path.join(binDir, `${now}_temp_extract`);
171
+
172
+ try {
173
+ fs.writeFileSync(tempZip, buffer);
174
+
175
+ if (!fs.existsSync(tempDir)) {
176
+ fs.mkdirSync(tempDir, { recursive: true });
177
+ }
178
+
179
+ if (process.platform === "win32") {
180
+ execSync(
181
+ `powershell -command "Expand-Archive -Path '${tempZip}' -DestinationPath '${tempDir}' -Force"`,
182
+ { stdio: "pipe" },
183
+ );
184
+ } else {
185
+ execSync(`unzip -q "${tempZip}" -d "${tempDir}"`, { stdio: "pipe" });
186
+ }
187
+
188
+ let binaryFound = false;
189
+ const searchPaths = [
190
+ path.join(tempDir, binaryName),
191
+ path.join(tempDir, "vdl", binaryName),
192
+ ];
193
+
194
+ for (const searchPath of searchPaths) {
195
+ if (fs.existsSync(searchPath)) {
196
+ const destPath = path.join(binDir, binaryName);
197
+ fs.copyFileSync(searchPath, destPath);
198
+ if (process.platform !== "win32") {
199
+ fs.chmodSync(destPath, 0o755);
200
+ }
201
+ binaryFound = true;
202
+ break;
203
+ }
204
+ }
205
+
206
+ if (!binaryFound) {
207
+ reject(new Error(`Binary ${binaryName} not found after extraction`));
208
+ } else {
209
+ resolve();
210
+ }
211
+ } catch (error) {
212
+ reject(new Error(`Failed to extract zip: ${error.message}`));
213
+ } finally {
214
+ try {
215
+ if (fs.existsSync(tempZip)) {
216
+ fs.unlinkSync(tempZip);
217
+ }
218
+ if (fs.existsSync(tempDir)) {
219
+ fs.rmSync(tempDir, { recursive: true, force: true });
220
+ }
221
+ } catch (_) {}
222
+ }
223
+ });
224
+ }
225
+
226
+ /**
227
+ * Downloads a file from the given URL with redirect support.
228
+ * @param {string} url - URL to download from
229
+ * @returns {Promise<Buffer>} Downloaded file as buffer
230
+ * @throws {Error} If download fails
231
+ */
232
+ function download(url) {
233
+ return new Promise((resolve, reject) => {
234
+ https
235
+ .get(url, (response) => {
236
+ if (
237
+ response.statusCode === 301 ||
238
+ response.statusCode === 302 ||
239
+ response.statusCode === 307 ||
240
+ response.statusCode === 308
241
+ ) {
242
+ return download(response.headers.location)
243
+ .then(resolve)
244
+ .catch(reject);
245
+ }
246
+
247
+ if (response.statusCode !== 200) {
248
+ reject(
249
+ new Error(
250
+ `Failed to download: HTTP ${response.statusCode}\n` +
251
+ `URL: ${url}\n` +
252
+ `This usually means the binary for your platform hasn't been released yet.`,
253
+ ),
254
+ );
255
+ return;
256
+ }
257
+
258
+ const chunks = [];
259
+ let totalLength = 0;
260
+
261
+ response.on("data", (chunk) => {
262
+ chunks.push(chunk);
263
+ totalLength += chunk.length;
264
+ });
265
+
266
+ response.on("end", () => {
267
+ resolve(Buffer.concat(chunks));
268
+ });
269
+
270
+ response.on("error", reject);
271
+ })
272
+ .on("error", reject);
273
+ });
274
+ }
275
+
276
+ /**
277
+ * Main installation routine.
278
+ * Downloads and installs the VDL binary for the current platform.
279
+ * @returns {Promise<void>}
280
+ */
281
+ async function install() {
282
+ try {
283
+ const platform = getPlatform();
284
+ const binaryName = getBinaryName();
285
+ const url = getDownloadURL();
286
+ const binDir = ensureBinDir();
287
+
288
+ const buffer = await download(url);
289
+
290
+ if (platform === "windows") {
291
+ await extractZip(buffer, binDir, binaryName);
292
+ } else {
293
+ await extractTarGz(buffer, binDir, binaryName);
294
+ }
295
+
296
+ const binaryPath = path.join(binDir, binaryName);
297
+ if (!fs.existsSync(binaryPath)) {
298
+ throw new Error(`Binary not found at ${binaryPath} after installation`);
299
+ }
300
+
301
+ if (process.platform !== "win32") {
302
+ fs.chmodSync(binaryPath, 0o755);
303
+ }
304
+ } catch (error) {
305
+ console.error("Installation failed:");
306
+ console.error(error.message);
307
+ process.exit(1);
308
+ }
309
+ }
310
+
311
+ if (require.main === module) install();
312
+ module.exports = { install };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@varavel/vdl",
3
+ "version": "0.0.0-dev",
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
+ "author": "Varavel",
6
+ "license": "MIT",
7
+ "homepage": "https://varavel.com/vdl",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/varavelio/vdl.git",
11
+ "directory": "installers/npm"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/varavelio/vdl/issues"
15
+ },
16
+ "main": "index.js",
17
+ "bin": {
18
+ "vdl": "bin/vdl"
19
+ },
20
+ "scripts": {
21
+ "postinstall": "node install.js"
22
+ },
23
+ "keywords": [
24
+ "rpc",
25
+ "schema",
26
+ "codegen",
27
+ "api",
28
+ "varavel"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ],
42
+ "files": [
43
+ "bin/",
44
+ "install.js",
45
+ "index.js",
46
+ "README.md"
47
+ ]
48
+ }