sparktype 0.1.0
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 +60 -0
- package/bin/sparktype.js +71 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# sparktype
|
|
2
|
+
|
|
3
|
+
Generate static types from OpenAPI specifications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g sparktype
|
|
9
|
+
# or
|
|
10
|
+
npx sparktype generate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Generate types using typegen.jsonc in current directory
|
|
17
|
+
sparktype generate
|
|
18
|
+
|
|
19
|
+
# Specify config file
|
|
20
|
+
sparktype generate --config ./path/to/typegen.jsonc
|
|
21
|
+
|
|
22
|
+
# Initialize a new config file
|
|
23
|
+
sparktype init
|
|
24
|
+
|
|
25
|
+
# Validate config file
|
|
26
|
+
sparktype validate
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
Create a `typegen.jsonc` file:
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
{
|
|
35
|
+
"specs": {
|
|
36
|
+
"api": {
|
|
37
|
+
"path": "./openapi.yaml"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"outputs": [
|
|
41
|
+
{
|
|
42
|
+
"path": "./src/types/api.ts",
|
|
43
|
+
"format": "typescript",
|
|
44
|
+
"spec": "api"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Supported Output Formats
|
|
51
|
+
|
|
52
|
+
- `typescript` - TypeScript interfaces
|
|
53
|
+
- `zod` - Zod schemas with inferred types
|
|
54
|
+
- `python` - Python TypedDict classes
|
|
55
|
+
- `go` - Go structs with JSON tags
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
For full documentation, visit: https://github.com/hntrl/sparktype
|
|
60
|
+
|
package/bin/sparktype.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
|
|
5
|
+
// Supported platforms - the package name is @sparktype/${platform}-${arch}
|
|
6
|
+
const SUPPORTED_PLATFORMS = new Set([
|
|
7
|
+
"darwin-arm64",
|
|
8
|
+
"darwin-x64",
|
|
9
|
+
"linux-arm64",
|
|
10
|
+
"linux-x64",
|
|
11
|
+
"win32-x64",
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function getBinaryPath() {
|
|
15
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
16
|
+
|
|
17
|
+
if (!SUPPORTED_PLATFORMS.has(platformKey)) {
|
|
18
|
+
console.error(`Unsupported platform: ${platformKey}`);
|
|
19
|
+
console.error("");
|
|
20
|
+
console.error("Supported platforms:");
|
|
21
|
+
for (const p of SUPPORTED_PLATFORMS) {
|
|
22
|
+
console.error(` - ${p}`);
|
|
23
|
+
}
|
|
24
|
+
console.error("");
|
|
25
|
+
console.error("You can download the binary directly from:");
|
|
26
|
+
console.error(" https://github.com/hntrl/sparktype/releases/latest");
|
|
27
|
+
console.error("");
|
|
28
|
+
console.error("Or install via Go:");
|
|
29
|
+
console.error(
|
|
30
|
+
" go install github.com/hntrl/sparktype/cmd/sparktype@latest"
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pkgName = `@sparktype/${platformKey}`;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// The platform package exports the binary path
|
|
39
|
+
return require(pkgName);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error(`Failed to load platform package: ${pkgName}`);
|
|
42
|
+
console.error("");
|
|
43
|
+
console.error("This usually means the package wasn't installed correctly.");
|
|
44
|
+
console.error("Try reinstalling:");
|
|
45
|
+
console.error(" npm uninstall sparktype && npm install sparktype");
|
|
46
|
+
console.error("");
|
|
47
|
+
console.error("If the problem persists, you can:");
|
|
48
|
+
console.error(
|
|
49
|
+
" 1. Download directly: https://github.com/hntrl/sparktype/releases/latest"
|
|
50
|
+
);
|
|
51
|
+
console.error(
|
|
52
|
+
" 2. Install via Go: go install github.com/hntrl/sparktype/cmd/sparktype@latest"
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const binaryPath = getBinaryPath();
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
execFileSync(binaryPath, process.argv.slice(2), {
|
|
62
|
+
stdio: "inherit",
|
|
63
|
+
});
|
|
64
|
+
} catch (err) {
|
|
65
|
+
// execFileSync throws on non-zero exit codes
|
|
66
|
+
if (err.status !== undefined) {
|
|
67
|
+
process.exit(err.status);
|
|
68
|
+
}
|
|
69
|
+
console.error("Failed to run sparktype:", err.message);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sparktype",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate static types from OpenAPI specifications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openapi",
|
|
7
|
+
"typescript",
|
|
8
|
+
"zod",
|
|
9
|
+
"codegen",
|
|
10
|
+
"types",
|
|
11
|
+
"schema"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/hntrl/sparktype",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/hntrl/sparktype/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/hntrl/sparktype.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "hntrl",
|
|
23
|
+
"bin": {
|
|
24
|
+
"sparktype": "bin/sparktype.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/"
|
|
28
|
+
],
|
|
29
|
+
"optionalDependencies": {
|
|
30
|
+
"@sparktype/darwin-arm64": "0.1.0",
|
|
31
|
+
"@sparktype/darwin-x64": "0.1.0",
|
|
32
|
+
"@sparktype/linux-arm64": "0.1.0",
|
|
33
|
+
"@sparktype/linux-x64": "0.1.0",
|
|
34
|
+
"@sparktype/win32-x64": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=16"
|
|
38
|
+
}
|
|
39
|
+
}
|