@maayn/veld 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Adhamzineldin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Veld — npm package
2
+
3
+ > Contract-first, multi-stack API code generator.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install veld
9
+ # or
10
+ npx veld generate
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ After installing, the `veld` CLI is available:
16
+
17
+ ```bash
18
+ veld init # Scaffold a new project
19
+ veld generate # Generate from veld.config.json
20
+ veld generate --dry-run # Preview what would be generated
21
+ veld watch # Auto-regenerate on file changes
22
+ veld validate # Check contracts for errors
23
+ veld clean # Remove generated output
24
+ veld openapi # Export OpenAPI 3.0 spec
25
+ ```
26
+
27
+ ## How it works
28
+
29
+ This npm package is a thin wrapper around the Veld Go binary. On `npm install`,
30
+ a postinstall script downloads the correct pre-built binary for your platform
31
+ from [GitHub Releases](https://github.com/veld-dev/veld/releases).
32
+
33
+ **Supported platforms:**
34
+ - Linux (x64, arm64)
35
+ - macOS (x64, Apple Silicon)
36
+ - Windows (x64)
37
+
38
+ If the download fails (e.g. behind a corporate proxy), the installer falls back
39
+ to `go install github.com/veld-dev/veld/cmd/veld@latest`.
40
+
41
+ ## Alternative installation
42
+
43
+ ```bash
44
+ # Go (no npm needed)
45
+ go install github.com/veld-dev/veld/cmd/veld@latest
46
+
47
+ # Homebrew
48
+ brew install veld
49
+
50
+ # pip
51
+ pip install veld
52
+
53
+ # Composer (PHP)
54
+ composer require veld-dev/veld
55
+ ```
56
+
57
+ ## Links
58
+
59
+ - [Documentation](https://github.com/veld-dev/veld)
60
+ - [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=veld-dev.veld-vscode)
61
+ - [JetBrains Plugin](https://plugins.jetbrains.com/plugin/veld)
62
+
63
+ ## License
64
+
65
+ MIT
66
+
package/bin/veld.js ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Veld CLI — npm wrapper
5
+ *
6
+ * This thin wrapper spawns the platform-specific Veld binary that was
7
+ * downloaded during `npm install` (postinstall). All CLI arguments are
8
+ * forwarded as-is.
9
+ */
10
+
11
+ "use strict";
12
+
13
+ const { execFileSync } = require("child_process");
14
+ const path = require("path");
15
+ const fs = require("fs");
16
+ const os = require("os");
17
+
18
+ function getBinaryName() {
19
+ return os.platform() === "win32" ? "veld.exe" : "veld";
20
+ }
21
+
22
+ function getBinaryPath() {
23
+ // Check local node_modules/.veld-bin first (postinstall puts it here)
24
+ const localBin = path.join(__dirname, "..", "bin-platform", getBinaryName());
25
+ if (fs.existsSync(localBin)) {
26
+ return localBin;
27
+ }
28
+
29
+ // Fallback: check if veld is on PATH
30
+ const envPath = os.platform() === "win32" ? "veld.exe" : "veld";
31
+ return envPath;
32
+ }
33
+
34
+ try {
35
+ const binary = getBinaryPath();
36
+ const args = process.argv.slice(2);
37
+
38
+ const result = execFileSync(binary, args, {
39
+ stdio: "inherit",
40
+ env: process.env,
41
+ });
42
+
43
+ process.exit(0);
44
+ } catch (err) {
45
+ if (err.status !== undefined) {
46
+ process.exit(err.status);
47
+ }
48
+ console.error("Error: Could not run veld binary.");
49
+ console.error("Try reinstalling: npm install veld");
50
+ console.error("");
51
+ console.error("Or install manually:");
52
+ console.error(" go install github.com/veld-dev/veld/cmd/veld@latest");
53
+ console.error("");
54
+ console.error(err.message);
55
+ process.exit(1);
56
+ }
57
+
package/install.js ADDED
@@ -0,0 +1,185 @@
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 VERSION = "0.1.0";
24
+ const GITHUB_REPO = "veld-dev/veld";
25
+ const BASE_URL = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}`;
26
+
27
+ function getPlatformKey() {
28
+ const platform = os.platform();
29
+ const arch = os.arch();
30
+
31
+ const platformMap = {
32
+ linux: "linux",
33
+ darwin: "darwin",
34
+ win32: "windows",
35
+ };
36
+
37
+ const archMap = {
38
+ x64: "amd64",
39
+ arm64: "arm64",
40
+ };
41
+
42
+ const p = platformMap[platform];
43
+ const a = archMap[arch];
44
+
45
+ if (!p || !a) {
46
+ return null;
47
+ }
48
+
49
+ return `${p}-${a}`;
50
+ }
51
+
52
+ function getBinaryName() {
53
+ return os.platform() === "win32" ? "veld.exe" : "veld";
54
+ }
55
+
56
+ function getDownloadUrl(platformKey) {
57
+ const ext = os.platform() === "win32" ? ".zip" : ".tar.gz";
58
+ return `${BASE_URL}/veld-${platformKey}${ext}`;
59
+ }
60
+
61
+ function download(url) {
62
+ return new Promise((resolve, reject) => {
63
+ const get = url.startsWith("https") ? https.get : http.get;
64
+ get(url, (res) => {
65
+ // Follow redirects (GitHub sends 302)
66
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
67
+ return download(res.headers.location).then(resolve).catch(reject);
68
+ }
69
+ if (res.statusCode !== 200) {
70
+ reject(new Error(`HTTP ${res.statusCode} downloading ${url}`));
71
+ return;
72
+ }
73
+ const chunks = [];
74
+ res.on("data", (chunk) => chunks.push(chunk));
75
+ res.on("end", () => resolve(Buffer.concat(chunks)));
76
+ res.on("error", reject);
77
+ }).on("error", reject);
78
+ });
79
+ }
80
+
81
+ async function extractTarGz(buffer, destDir) {
82
+ // Write to temp file and use tar
83
+ const tmpFile = path.join(os.tmpdir(), `veld-${Date.now()}.tar.gz`);
84
+ fs.writeFileSync(tmpFile, buffer);
85
+ fs.mkdirSync(destDir, { recursive: true });
86
+ try {
87
+ execSync(`tar -xzf "${tmpFile}" -C "${destDir}"`, { stdio: "pipe" });
88
+ } finally {
89
+ fs.unlinkSync(tmpFile);
90
+ }
91
+ }
92
+
93
+ async function extractZip(buffer, destDir) {
94
+ // Write to temp file and use PowerShell / unzip
95
+ const tmpFile = path.join(os.tmpdir(), `veld-${Date.now()}.zip`);
96
+ fs.writeFileSync(tmpFile, buffer);
97
+ fs.mkdirSync(destDir, { recursive: true });
98
+ try {
99
+ if (os.platform() === "win32") {
100
+ execSync(
101
+ `powershell -Command "Expand-Archive -Force -Path '${tmpFile}' -DestinationPath '${destDir}'"`,
102
+ { stdio: "pipe" }
103
+ );
104
+ } else {
105
+ execSync(`unzip -o "${tmpFile}" -d "${destDir}"`, { stdio: "pipe" });
106
+ }
107
+ } finally {
108
+ fs.unlinkSync(tmpFile);
109
+ }
110
+ }
111
+
112
+ async function tryGoInstall() {
113
+ console.log("Attempting fallback: go install github.com/veld-dev/veld/cmd/veld@latest");
114
+ try {
115
+ execSync("go install github.com/veld-dev/veld/cmd/veld@latest", {
116
+ stdio: "inherit",
117
+ });
118
+ console.log("✓ Installed veld via go install");
119
+ return true;
120
+ } catch {
121
+ return false;
122
+ }
123
+ }
124
+
125
+ async function main() {
126
+ const platformKey = getPlatformKey();
127
+
128
+ if (!platformKey) {
129
+ console.warn(
130
+ `Warning: Unsupported platform ${os.platform()}-${os.arch()}.`
131
+ );
132
+ console.warn("Attempting go install fallback...");
133
+ if (await tryGoInstall()) return;
134
+ console.warn("Install veld manually: go install github.com/veld-dev/veld/cmd/veld@latest");
135
+ return;
136
+ }
137
+
138
+ const url = getDownloadUrl(platformKey);
139
+ const destDir = path.join(__dirname, "bin-platform");
140
+ const binaryName = getBinaryName();
141
+ const binaryPath = path.join(destDir, binaryName);
142
+
143
+ // Skip if already downloaded
144
+ if (fs.existsSync(binaryPath)) {
145
+ console.log(`✓ veld binary already exists at ${binaryPath}`);
146
+ return;
147
+ }
148
+
149
+ console.log(`Downloading veld ${VERSION} for ${platformKey}...`);
150
+ console.log(` ${url}`);
151
+
152
+ try {
153
+ const buffer = await download(url);
154
+
155
+ if (os.platform() === "win32") {
156
+ await extractZip(buffer, destDir);
157
+ } else {
158
+ await extractTarGz(buffer, destDir);
159
+ }
160
+
161
+ // Make binary executable on Unix
162
+ if (os.platform() !== "win32") {
163
+ fs.chmodSync(binaryPath, 0o755);
164
+ }
165
+
166
+ if (fs.existsSync(binaryPath)) {
167
+ console.log(`✓ veld ${VERSION} installed successfully`);
168
+ } else {
169
+ throw new Error("Binary not found after extraction");
170
+ }
171
+ } catch (err) {
172
+ console.warn(`Warning: Could not download pre-built binary: ${err.message}`);
173
+ console.warn("");
174
+
175
+ if (await tryGoInstall()) return;
176
+
177
+ console.warn("Install veld manually:");
178
+ console.warn(" go install github.com/veld-dev/veld/cmd/veld@latest");
179
+ console.warn("");
180
+ console.warn("Or download from: https://github.com/veld-dev/veld/releases");
181
+ }
182
+ }
183
+
184
+ main();
185
+
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@maayn/veld",
3
+ "version": "0.1.1",
4
+ "description": "Contract-first, multi-stack API code generator. Write .veld contracts once, generate typed frontend SDKs and backend service interfaces.",
5
+ "keywords": [
6
+ "veld",
7
+ "api",
8
+ "code-generation",
9
+ "contract-first",
10
+ "typescript",
11
+ "sdk",
12
+ "schema"
13
+ ],
14
+ "homepage": "https://github.com/veld-dev/veld",
15
+ "bugs": {
16
+ "url": "https://github.com/veld-dev/veld/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/veld-dev/veld.git"
21
+ },
22
+ "license": "MIT",
23
+ "bin": {
24
+ "veld": "./bin/veld.js"
25
+ },
26
+ "scripts": {
27
+ "postinstall": "node install.js"
28
+ },
29
+ "engines": {
30
+ "node": ">=16"
31
+ },
32
+ "files": [
33
+ "bin/",
34
+ "install.js",
35
+ "README.md",
36
+ "LICENSE"
37
+ ]
38
+ }