@maayn/veld 0.3.6 → 0.3.7
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/veld.js +42 -24
- package/binaries/darwin-amd64/veld +0 -0
- package/binaries/darwin-arm64/veld +0 -0
- package/binaries/linux-amd64/veld +0 -0
- package/binaries/linux-arm64/veld +0 -0
- package/binaries/windows-amd64/veld.exe +0 -0
- package/install.js +222 -0
- package/package.json +5 -1
package/bin/veld.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Veld CLI — npm wrapper
|
|
5
5
|
*
|
|
6
6
|
* This wrapper uses the bundled binary for the current platform.
|
|
7
|
-
*
|
|
7
|
+
* The binary is downloaded by the postinstall script (install.js).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const { spawnSync } = require("child_process");
|
|
13
13
|
const path = require("path");
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const os = require("os");
|
|
@@ -44,7 +44,7 @@ function getBinaryName() {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function getBinaryPath() {
|
|
47
|
-
// Use bundled binary for this platform
|
|
47
|
+
// 1. Use bundled binary for this platform (downloaded by postinstall)
|
|
48
48
|
const platformKey = getPlatformKey();
|
|
49
49
|
if (platformKey) {
|
|
50
50
|
const bundledBin = path.join(__dirname, "..", "binaries", platformKey, getBinaryName());
|
|
@@ -53,32 +53,50 @@ function getBinaryPath() {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
// 2. Check if veld binary was placed at package root (single-binary layout)
|
|
57
|
+
const rootBin = path.join(__dirname, "..", getBinaryName());
|
|
58
|
+
if (fs.existsSync(rootBin)) {
|
|
59
|
+
return rootBin;
|
|
60
|
+
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// 3. Not found — return null so we can show a helpful error
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
stdio: "inherit",
|
|
67
|
-
env: process.env,
|
|
68
|
-
});
|
|
66
|
+
const binary = getBinaryPath();
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (err.status !== undefined) {
|
|
73
|
-
process.exit(err.status);
|
|
74
|
-
}
|
|
75
|
-
console.error("Error: Could not run veld binary.");
|
|
76
|
-
console.error("Try reinstalling: npm install @maayn/veld");
|
|
68
|
+
if (!binary) {
|
|
69
|
+
console.error("Error: Veld binary not found for your platform.");
|
|
77
70
|
console.error("");
|
|
78
|
-
console.error("
|
|
79
|
-
console.error("
|
|
71
|
+
console.error("The postinstall script may have failed. Try:");
|
|
72
|
+
console.error(" npm rebuild @maayn/veld");
|
|
80
73
|
console.error("");
|
|
81
|
-
console.error(
|
|
74
|
+
console.error("Or install the binary manually:");
|
|
75
|
+
console.error(" go install github.com/Adhamzineldin/Veld/cmd/veld@latest");
|
|
76
|
+
console.error(" pip install maayn-veld");
|
|
77
|
+
console.error(" brew install maayn-veld/tap/maayn-veld");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const args = process.argv.slice(2);
|
|
82
|
+
|
|
83
|
+
// Use spawnSync with shell:false to avoid opening a new terminal window on Windows.
|
|
84
|
+
// stdio:"inherit" ensures stdin is passed through for interactive commands (e.g. veld init).
|
|
85
|
+
const result = spawnSync(binary, args, {
|
|
86
|
+
stdio: "inherit",
|
|
87
|
+
env: process.env,
|
|
88
|
+
shell: false,
|
|
89
|
+
windowsHide: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (result.error) {
|
|
93
|
+
if (result.error.code === "ENOENT") {
|
|
94
|
+
console.error("Error: Veld binary not found at: " + binary);
|
|
95
|
+
console.error("Try reinstalling: npm install @maayn/veld");
|
|
96
|
+
} else {
|
|
97
|
+
console.error("Error running veld:", result.error.message);
|
|
98
|
+
}
|
|
82
99
|
process.exit(1);
|
|
83
100
|
}
|
|
84
101
|
|
|
102
|
+
process.exit(result.status || 0);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/install.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Veld CLI — postinstall script
|
|
3
|
+
*
|
|
4
|
+
* Downloads the correct pre-built Veld binary for the current platform
|
|
5
|
+
* from GitHub Releases. Falls back to `go install` if the download fails.
|
|
6
|
+
*
|
|
7
|
+
* Supported platforms:
|
|
8
|
+
* - linux-amd64, linux-arm64
|
|
9
|
+
* - darwin-amd64, darwin-arm64
|
|
10
|
+
* - windows-amd64
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
"use strict";
|
|
14
|
+
|
|
15
|
+
const https = require("https");
|
|
16
|
+
const http = require("http");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const path = require("path");
|
|
19
|
+
const os = require("os");
|
|
20
|
+
const { execSync } = require("child_process");
|
|
21
|
+
const zlib = require("zlib");
|
|
22
|
+
|
|
23
|
+
const GITHUB_REPO = "Adhamzineldin/Veld";
|
|
24
|
+
const GITHUB_API = `https://api.github.com/repos/${GITHUB_REPO}/releases/latest`;
|
|
25
|
+
|
|
26
|
+
async function getLatestVersion() {
|
|
27
|
+
// Allow override via environment variable
|
|
28
|
+
if (process.env.VELD_VERSION) {
|
|
29
|
+
return process.env.VELD_VERSION.replace(/^v/, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const https = require("https");
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
https.get(GITHUB_API, { timeout: 10000 }, (res) => {
|
|
36
|
+
let data = "";
|
|
37
|
+
res.on("data", (chunk) => (data += chunk));
|
|
38
|
+
res.on("end", () => {
|
|
39
|
+
try {
|
|
40
|
+
const json = JSON.parse(data);
|
|
41
|
+
const tag = json.tag_name || "";
|
|
42
|
+
resolve(tag.replace(/^v/, "") || "latest");
|
|
43
|
+
} catch {
|
|
44
|
+
resolve("latest");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
res.on("error", () => resolve("latest"));
|
|
48
|
+
}).on("error", () => resolve("latest"));
|
|
49
|
+
});
|
|
50
|
+
} catch {
|
|
51
|
+
return "latest";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getBaseUrl(version) {
|
|
56
|
+
if (version === "latest") {
|
|
57
|
+
return `https://github.com/${GITHUB_REPO}/releases/latest/download`;
|
|
58
|
+
}
|
|
59
|
+
return `https://github.com/${GITHUB_REPO}/releases/download/v${version}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getPlatformKey() {
|
|
63
|
+
const platform = os.platform();
|
|
64
|
+
const arch = os.arch();
|
|
65
|
+
|
|
66
|
+
const platformMap = {
|
|
67
|
+
linux: "linux",
|
|
68
|
+
darwin: "darwin",
|
|
69
|
+
win32: "windows",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const archMap = {
|
|
73
|
+
x64: "amd64",
|
|
74
|
+
arm64: "arm64",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const p = platformMap[platform];
|
|
78
|
+
const a = archMap[arch];
|
|
79
|
+
|
|
80
|
+
if (!p || !a) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return `${p}-${a}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getBinaryName() {
|
|
88
|
+
return os.platform() === "win32" ? "veld.exe" : "veld";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getDownloadUrl(platformKey, version) {
|
|
92
|
+
const ext = os.platform() === "win32" ? ".zip" : ".tar.gz";
|
|
93
|
+
const baseUrl = getBaseUrl(version);
|
|
94
|
+
return `${baseUrl}/veld-${platformKey}${ext}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function download(url) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const get = url.startsWith("https") ? https.get : http.get;
|
|
100
|
+
get(url, (res) => {
|
|
101
|
+
// Follow redirects (GitHub sends 302)
|
|
102
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
103
|
+
return download(res.headers.location).then(resolve).catch(reject);
|
|
104
|
+
}
|
|
105
|
+
if (res.statusCode !== 200) {
|
|
106
|
+
reject(new Error(`HTTP ${res.statusCode} downloading ${url}`));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const chunks = [];
|
|
110
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
111
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
112
|
+
res.on("error", reject);
|
|
113
|
+
}).on("error", reject);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function extractTarGz(buffer, destDir) {
|
|
118
|
+
// Write to temp file and use tar
|
|
119
|
+
const tmpFile = path.join(os.tmpdir(), `veld-${Date.now()}.tar.gz`);
|
|
120
|
+
fs.writeFileSync(tmpFile, buffer);
|
|
121
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
122
|
+
try {
|
|
123
|
+
execSync(`tar -xzf "${tmpFile}" -C "${destDir}"`, { stdio: "pipe" });
|
|
124
|
+
} finally {
|
|
125
|
+
fs.unlinkSync(tmpFile);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function extractZip(buffer, destDir) {
|
|
130
|
+
// Write to temp file and use PowerShell / unzip
|
|
131
|
+
const tmpFile = path.join(os.tmpdir(), `veld-${Date.now()}.zip`);
|
|
132
|
+
fs.writeFileSync(tmpFile, buffer);
|
|
133
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
134
|
+
try {
|
|
135
|
+
if (os.platform() === "win32") {
|
|
136
|
+
execSync(
|
|
137
|
+
`powershell -Command "Expand-Archive -Force -Path '${tmpFile}' -DestinationPath '${destDir}'"`,
|
|
138
|
+
{ stdio: "pipe" }
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
execSync(`unzip -o "${tmpFile}" -d "${destDir}"`, { stdio: "pipe" });
|
|
142
|
+
}
|
|
143
|
+
} finally {
|
|
144
|
+
fs.unlinkSync(tmpFile);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function tryGoInstall() {
|
|
149
|
+
console.log("Attempting fallback: go install github.com/Adhamzineldin/Veld/cmd/veld@latest");
|
|
150
|
+
try {
|
|
151
|
+
execSync("go install github.com/Adhamzineldin/Veld/cmd/veld@latest", {
|
|
152
|
+
stdio: "inherit",
|
|
153
|
+
});
|
|
154
|
+
console.log("✓ Installed veld via go install");
|
|
155
|
+
return true;
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function main() {
|
|
162
|
+
const platformKey = getPlatformKey();
|
|
163
|
+
|
|
164
|
+
if (!platformKey) {
|
|
165
|
+
console.warn(
|
|
166
|
+
`Warning: Unsupported platform ${os.platform()}-${os.arch()}.`
|
|
167
|
+
);
|
|
168
|
+
console.warn("Attempting go install fallback...");
|
|
169
|
+
if (await tryGoInstall()) return;
|
|
170
|
+
console.warn("Install veld manually: go install github.com/Adhamzineldin/Veld/cmd/veld@latest");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const version = await getLatestVersion();
|
|
175
|
+
const url = getDownloadUrl(platformKey, version);
|
|
176
|
+
const destDir = path.join(__dirname, "binaries", platformKey);
|
|
177
|
+
const binaryName = getBinaryName();
|
|
178
|
+
const binaryPath = path.join(destDir, binaryName);
|
|
179
|
+
|
|
180
|
+
// Skip if already downloaded
|
|
181
|
+
if (fs.existsSync(binaryPath)) {
|
|
182
|
+
console.log(`✓ veld binary already exists at ${binaryPath}`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(`Downloading veld ${version} for ${platformKey}...`);
|
|
187
|
+
console.log(` ${url}`);
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const buffer = await download(url);
|
|
191
|
+
|
|
192
|
+
if (os.platform() === "win32") {
|
|
193
|
+
await extractZip(buffer, destDir);
|
|
194
|
+
} else {
|
|
195
|
+
await extractTarGz(buffer, destDir);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Make binary executable on Unix
|
|
199
|
+
if (os.platform() !== "win32") {
|
|
200
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (fs.existsSync(binaryPath)) {
|
|
204
|
+
console.log(`✓ veld ${version} installed successfully`);
|
|
205
|
+
} else {
|
|
206
|
+
throw new Error("Binary not found after extraction");
|
|
207
|
+
}
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.warn(`Warning: Could not download pre-built binary: ${err.message}`);
|
|
210
|
+
console.warn("");
|
|
211
|
+
|
|
212
|
+
if (await tryGoInstall()) return;
|
|
213
|
+
|
|
214
|
+
console.warn("Install veld manually:");
|
|
215
|
+
console.warn(" go install github.com/Adhamzineldin/Veld/cmd/veld@latest");
|
|
216
|
+
console.warn("");
|
|
217
|
+
console.warn("Or download from: https://github.com/Adhamzineldin/Veld/releases");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
main();
|
|
222
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maayn/veld",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Contract-first, multi-stack API code generator. Write .veld contracts once, generate typed frontend SDKs and backend service interfaces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veld",
|
|
@@ -23,12 +23,16 @@
|
|
|
23
23
|
"bin": {
|
|
24
24
|
"veld": "./bin/veld.js"
|
|
25
25
|
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"postinstall": "node install.js"
|
|
28
|
+
},
|
|
26
29
|
"engines": {
|
|
27
30
|
"node": ">=16"
|
|
28
31
|
},
|
|
29
32
|
"files": [
|
|
30
33
|
"bin/",
|
|
31
34
|
"binaries/",
|
|
35
|
+
"install.js",
|
|
32
36
|
"README.md",
|
|
33
37
|
"LICENSE"
|
|
34
38
|
]
|