@dinoconfig/cli 0.0.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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +157 -0
- package/bin/codegen.d.ts +13 -0
- package/bin/codegen.d.ts.map +1 -0
- package/bin/codegen.js +95 -0
- package/bin/dinoconfig.d.ts +11 -0
- package/bin/dinoconfig.d.ts.map +1 -0
- package/bin/dinoconfig.js +55 -0
- package/bin/javagen.d.ts +12 -0
- package/bin/javagen.d.ts.map +1 -0
- package/bin/javagen.js +123 -0
- package/codegen-DZxM8r9k.js +1622 -0
- package/constants-Dvwyqn-J.js +9 -0
- package/index.d.ts +26 -0
- package/index.d.ts.map +1 -0
- package/index.js +17 -0
- package/lib/codegen.d.ts +117 -0
- package/lib/codegen.d.ts.map +1 -0
- package/lib/constants.d.ts +17 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/dependency-updater.d.ts +65 -0
- package/lib/dependency-updater.d.ts.map +1 -0
- package/lib/java-model-generator.d.ts +73 -0
- package/lib/java-model-generator.d.ts.map +1 -0
- package/lib/type-generator.d.ts +28 -0
- package/lib/type-generator.d.ts.map +1 -0
- package/package.json +87 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of the DinoConfig CLI
|
|
12
|
+
- **`codegen` command** - Generate TypeScript type definitions from DinoConfig schemas
|
|
13
|
+
- Automatic brand/config/key type generation
|
|
14
|
+
- Configurable namespace and output path
|
|
15
|
+
- Full type safety with generated interfaces
|
|
16
|
+
- **`javagen` command** - Generate Java model classes from DinoConfig schemas
|
|
17
|
+
- POJO class generation with proper types
|
|
18
|
+
- Lombok annotations support
|
|
19
|
+
- Package and output directory configuration
|
|
20
|
+
- **Programmatic API** - Use CLI functionality in build scripts
|
|
21
|
+
- `generateTypes()` function for TypeScript generation
|
|
22
|
+
- `generateJavaModels()` function for Java generation
|
|
23
|
+
- CLI entry points:
|
|
24
|
+
- `dinoconfig` - Main CLI with subcommands
|
|
25
|
+
- `dinoconfig-codegen` - Direct TypeScript generation
|
|
26
|
+
- `dinoconfig-javagen` - Direct Java generation
|
|
27
|
+
- Full TypeScript support
|
|
28
|
+
- Zero external runtime dependencies (uses `@dinoconfig/js-sdk`)
|
|
29
|
+
|
|
30
|
+
### Documentation
|
|
31
|
+
- Comprehensive README with usage examples
|
|
32
|
+
- CI/CD integration guide
|
|
33
|
+
- SDK usage examples with generated types
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present DinoConfig Team
|
|
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,157 @@
|
|
|
1
|
+
# DinoConfig CLI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@dinoconfig/cli)
|
|
4
|
+
[](https://www.npmjs.com/package/@dinoconfig/cli)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
Command-line tools for DinoConfig, including TypeScript and Java code generation from your configuration schemas.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# npm
|
|
14
|
+
npm install -g @dinoconfig/cli
|
|
15
|
+
|
|
16
|
+
# npx (no install required)
|
|
17
|
+
npx @dinoconfig/cli codegen --api-key=dino_xxx
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
### `codegen` - Generate TypeScript Types
|
|
23
|
+
|
|
24
|
+
Generate TypeScript type definitions from your DinoConfig schemas for full type safety.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Basic usage
|
|
28
|
+
npx @dinoconfig/cli codegen --api-key=dino_your-api-key
|
|
29
|
+
|
|
30
|
+
# Or use the shorthand command
|
|
31
|
+
npx dinoconfig-codegen --api-key=dino_your-api-key
|
|
32
|
+
|
|
33
|
+
# With all options
|
|
34
|
+
npx @dinoconfig/cli codegen \
|
|
35
|
+
--api-key=dino_abc123 \
|
|
36
|
+
--baseUrl=https://api.dinoconfig.com \
|
|
37
|
+
--output=./src/types/dinoconfig.d.ts \
|
|
38
|
+
--namespace=AppConfig
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Options
|
|
42
|
+
|
|
43
|
+
| Option | Description | Default |
|
|
44
|
+
|--------|-------------|---------|
|
|
45
|
+
| `--api-key=<key>` | **Required.** Your DinoConfig API key | - |
|
|
46
|
+
| `--baseUrl=<url>` | API base URL | `http://localhost:3000` |
|
|
47
|
+
| `--output=<path>` | Output file path | `./src/types/dinoconfig.d.ts` |
|
|
48
|
+
| `--namespace=<name>` | Root namespace name | `DinoConfig` |
|
|
49
|
+
| `-h, --help` | Show help | - |
|
|
50
|
+
| `-v, --version` | Show version | - |
|
|
51
|
+
|
|
52
|
+
#### Generated Output
|
|
53
|
+
|
|
54
|
+
The tool generates a TypeScript declaration file with:
|
|
55
|
+
- A namespace for each brand
|
|
56
|
+
- An interface for each config
|
|
57
|
+
- Typed properties for each config key
|
|
58
|
+
|
|
59
|
+
**Example generated code:**
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// src/types/dinoconfig.d.ts
|
|
63
|
+
export namespace DinoConfig {
|
|
64
|
+
export namespace MyBrand {
|
|
65
|
+
/** FeatureFlags configuration */
|
|
66
|
+
export interface FeatureFlags {
|
|
67
|
+
/** boolean */
|
|
68
|
+
enableDarkMode: boolean;
|
|
69
|
+
/** number */
|
|
70
|
+
maxUploadSize: number;
|
|
71
|
+
/** string[] */
|
|
72
|
+
allowedCountries: string[];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Usage with SDK
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { dinoconfigApi } from '@dinoconfig/js-sdk';
|
|
82
|
+
import { DinoConfig } from './types/dinoconfig';
|
|
83
|
+
|
|
84
|
+
const dinoconfig = await dinoconfigApi({
|
|
85
|
+
apiKey: process.env.DINOCONFIG_API_KEY!
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Full type safety with generics
|
|
89
|
+
const flags = await dinoconfig.configs.get<DinoConfig.MyBrand.FeatureFlags>(
|
|
90
|
+
'MyBrand',
|
|
91
|
+
'FeatureFlags'
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// TypeScript knows the exact types!
|
|
95
|
+
flags.data.values.enableDarkMode; // boolean ✓
|
|
96
|
+
flags.data.values.maxUploadSize; // number ✓
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Programmatic API
|
|
100
|
+
|
|
101
|
+
You can also use the CLI programmatically in your build scripts:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { generateTypes } from '@dinoconfig/cli';
|
|
105
|
+
|
|
106
|
+
async function generateConfigTypes() {
|
|
107
|
+
const result = await generateTypes({
|
|
108
|
+
apiKey: process.env.DINOCONFIG_API_KEY!,
|
|
109
|
+
baseUrl: 'https://api.dinoconfig.com',
|
|
110
|
+
output: './src/types/dinoconfig.d.ts',
|
|
111
|
+
namespace: 'DinoConfig',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (result.success) {
|
|
115
|
+
console.log(`Generated ${result.stats.configs} config types`);
|
|
116
|
+
} else {
|
|
117
|
+
console.error('Failed:', result.error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## CI/CD Integration
|
|
123
|
+
|
|
124
|
+
Add type generation to your build process:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"scripts": {
|
|
129
|
+
"generate:types": "dinoconfig-codegen --api-key=$DINOCONFIG_API_KEY",
|
|
130
|
+
"build": "npm run generate:types && tsc"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### GitHub Actions Example
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
- name: Generate DinoConfig Types
|
|
139
|
+
run: npx @dinoconfig/cli codegen --api-key=${{ secrets.DINOCONFIG_API_KEY }}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Requirements
|
|
143
|
+
|
|
144
|
+
- Node.js >= 18.0.0
|
|
145
|
+
- DinoConfig API key
|
|
146
|
+
|
|
147
|
+
## Related Packages
|
|
148
|
+
|
|
149
|
+
- [@dinoconfig/js-sdk](https://www.npmjs.com/package/@dinoconfig/js-sdk) - JavaScript/TypeScript SDK
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
Made with ❤️ by the DinoConfig Team
|
package/bin/codegen.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DinoConfig Type Generator CLI
|
|
3
|
+
*
|
|
4
|
+
* Generates TypeScript type definitions from DinoConfig schemas.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```bash
|
|
8
|
+
* npx @dinoconfig/cli codegen --api-key=dino_xxx --output=./src/types/dinoconfig.d.ts
|
|
9
|
+
* npx dinoconfig-codegen --api-key=dino_xxx
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function runCodegen(args: string[]): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../../../libs/dinoconfig-cli/src/bin/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoHH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8C9D"}
|
package/bin/codegen.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as g } from "../codegen-DZxM8r9k.js";
|
|
3
|
+
import { d as n, a as r, c, D as l, b as p } from "../constants-Dvwyqn-J.js";
|
|
4
|
+
function f(s) {
|
|
5
|
+
const e = {};
|
|
6
|
+
for (const o of s)
|
|
7
|
+
o === "--help" || o === "-h" ? e.help = !0 : o === "--version" || o === "-v" ? e.version = !0 : o.startsWith("--api-key=") ? e.apiKey = o.slice(10) : o.startsWith("--baseUrl=") || o.startsWith("--base-url=") ? e.baseUrl = o.split("=")[1] : o.startsWith("--output=") || o.startsWith("-o=") ? e.output = o.split("=")[1] : o.startsWith("--namespace=") && (e.namespace = o.slice(12));
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
|
+
function u() {
|
|
11
|
+
console.log(`
|
|
12
|
+
${n} v${r}
|
|
13
|
+
|
|
14
|
+
Generate TypeScript types from DinoConfig schemas.
|
|
15
|
+
|
|
16
|
+
USAGE:
|
|
17
|
+
npx ${n} --api-key=<key> [options]
|
|
18
|
+
npx @dinoconfig/cli codegen --api-key=<key> [options]
|
|
19
|
+
|
|
20
|
+
OPTIONS:
|
|
21
|
+
--api-key=<key> Required. Your DinoConfig API key
|
|
22
|
+
--baseUrl=<url> API base URL (default: ${l})
|
|
23
|
+
--output=<path> Output file path (default: ${c})
|
|
24
|
+
--namespace=<name> Root namespace name (default: ${p})
|
|
25
|
+
-h, --help Show this help message
|
|
26
|
+
-v, --version Show version number
|
|
27
|
+
|
|
28
|
+
EXAMPLES:
|
|
29
|
+
# Generate types with default settings
|
|
30
|
+
npx ${n} --api-key=dino_abc123
|
|
31
|
+
|
|
32
|
+
# Generate types to custom path
|
|
33
|
+
npx ${n} --api-key=dino_abc123 --output=./types/config.d.ts
|
|
34
|
+
|
|
35
|
+
# Use production API
|
|
36
|
+
npx ${n} --api-key=dino_abc123 --baseUrl=https://api.dinoconfig.com
|
|
37
|
+
|
|
38
|
+
GENERATED OUTPUT:
|
|
39
|
+
The tool generates a TypeScript declaration file with:
|
|
40
|
+
- A namespace for each brand
|
|
41
|
+
- An interface for each config
|
|
42
|
+
- Typed properties for each config key
|
|
43
|
+
|
|
44
|
+
Example generated code:
|
|
45
|
+
export namespace DinoConfig {
|
|
46
|
+
export namespace MyBrand {
|
|
47
|
+
export interface FeatureFlags {
|
|
48
|
+
enableDarkMode: boolean;
|
|
49
|
+
maxUsers: number;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Usage with the SDK:
|
|
55
|
+
import { DinoConfig } from './types/dinoconfig';
|
|
56
|
+
|
|
57
|
+
const flags = await dinoconfig.configs.get<DinoConfig.MyBrand.FeatureFlags>(
|
|
58
|
+
'MyBrand', 'FeatureFlags'
|
|
59
|
+
);
|
|
60
|
+
flags.data.values.enableDarkMode; // boolean ✓
|
|
61
|
+
`);
|
|
62
|
+
}
|
|
63
|
+
function d(s, e, o) {
|
|
64
|
+
console.log(`
|
|
65
|
+
🦖 ${n} v${r}
|
|
66
|
+
`), console.log(` Base URL: ${s}`), console.log(` Output: ${e}`), console.log(` Namespace: ${o}`), console.log("");
|
|
67
|
+
}
|
|
68
|
+
function h(s, e) {
|
|
69
|
+
console.log(`
|
|
70
|
+
✅ Types generated successfully!
|
|
71
|
+
`), console.log(" Usage in your code:"), console.log(""), console.log(` import { ${e} } from '${s.replace(/\.d\.ts$/, "")}';`), console.log(""), console.log(` const config = await dinoconfig.configs.get<${e}.BrandName.ConfigName>(`), console.log(" 'BrandName', 'ConfigName'"), console.log(" );"), console.log("");
|
|
72
|
+
}
|
|
73
|
+
async function y(s) {
|
|
74
|
+
const e = f(s);
|
|
75
|
+
e.help && (u(), process.exit(0)), e.version && (console.log(`${n} v${r}`), process.exit(0)), e.apiKey || (console.error(`Error: --api-key is required
|
|
76
|
+
`), console.error("Run with --help for usage information"), process.exit(1));
|
|
77
|
+
const o = e.baseUrl ?? l, t = e.output ?? c, i = e.namespace ?? p;
|
|
78
|
+
d(o, t, i), console.log(" → Initializing SDK..."), console.log(" → Fetching configuration schemas...");
|
|
79
|
+
const a = await g({
|
|
80
|
+
apiKey: e.apiKey,
|
|
81
|
+
baseUrl: o,
|
|
82
|
+
output: t,
|
|
83
|
+
namespace: i
|
|
84
|
+
});
|
|
85
|
+
a.success || (console.error(`
|
|
86
|
+
❌ Error: ${a.error}`), process.exit(1)), console.log(` → Found ${a.stats?.brands} brand(s)`), console.log(` → Found ${a.stats?.configs} config(s) with ${a.stats?.keys} key(s)`), console.log(" → Generating TypeScript types..."), console.log(` → Writing to ${t}...`), h(t, i);
|
|
87
|
+
}
|
|
88
|
+
process.argv[1]?.includes("codegen") && y(process.argv.slice(2)).catch((s) => {
|
|
89
|
+
const e = s instanceof Error ? s.message : "Unknown error";
|
|
90
|
+
console.error(`
|
|
91
|
+
❌ Error:`, e), process.exit(1);
|
|
92
|
+
});
|
|
93
|
+
export {
|
|
94
|
+
y as runCodegen
|
|
95
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dinoconfig.d.ts","sourceRoot":"","sources":["../../../../libs/dinoconfig-cli/src/bin/dinoconfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { C as o, a as s } from "../constants-Dvwyqn-J.js";
|
|
3
|
+
function r() {
|
|
4
|
+
console.log(`
|
|
5
|
+
${o} v${s}
|
|
6
|
+
|
|
7
|
+
DinoConfig Command Line Interface
|
|
8
|
+
|
|
9
|
+
USAGE:
|
|
10
|
+
npx ${o} <command> [options]
|
|
11
|
+
|
|
12
|
+
COMMANDS:
|
|
13
|
+
codegen Generate TypeScript types from DinoConfig schemas
|
|
14
|
+
javagen Generate Java model classes from DinoConfig schemas
|
|
15
|
+
|
|
16
|
+
OPTIONS:
|
|
17
|
+
-h, --help Show this help message
|
|
18
|
+
-v, --version Show version number
|
|
19
|
+
|
|
20
|
+
EXAMPLES:
|
|
21
|
+
# Generate TypeScript types
|
|
22
|
+
npx ${o} codegen --api-key=dino_abc123
|
|
23
|
+
|
|
24
|
+
# Generate Java models
|
|
25
|
+
npx ${o} javagen --api-key=dino_abc123
|
|
26
|
+
|
|
27
|
+
# Show command help
|
|
28
|
+
npx ${o} codegen --help
|
|
29
|
+
npx ${o} javagen --help
|
|
30
|
+
|
|
31
|
+
For more information, visit: https://docs.dinoconfig.com
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
function i(n) {
|
|
35
|
+
const e = n instanceof Error ? n.message : "Unknown error";
|
|
36
|
+
console.error("Error:", e), process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
async function c() {
|
|
39
|
+
const n = process.argv.slice(2), e = n[0];
|
|
40
|
+
switch ((!e || e === "--help" || e === "-h") && (r(), process.exit(0)), (e === "--version" || e === "-v") && (console.log(`${o} v${s}`), process.exit(0)), e) {
|
|
41
|
+
case "codegen": {
|
|
42
|
+
const { runCodegen: a } = await import("./codegen.js");
|
|
43
|
+
await a(n.slice(1));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case "javagen": {
|
|
47
|
+
const { runJavagen: a } = await import("./javagen.js");
|
|
48
|
+
await a(n.slice(1));
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
default:
|
|
52
|
+
console.error(`Unknown command: ${e}`), console.error(`Run '${o} --help' for usage information`), process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
c().catch(i);
|
package/bin/javagen.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DinoConfig Java Model Generator CLI
|
|
3
|
+
*
|
|
4
|
+
* Generates Java POJO model classes from DinoConfig schemas.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```bash
|
|
8
|
+
* npx @dinoconfig/cli javagen --api-key=dino_xxx --output=./libs/dinoconfig-java-sdk/lib/src/main/java
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function runJavagen(args: string[]): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=javagen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javagen.d.ts","sourceRoot":"","sources":["../../../../libs/dinoconfig-cli/src/bin/javagen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoLH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD9D"}
|
package/bin/javagen.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { g } from "../codegen-DZxM8r9k.js";
|
|
3
|
+
import { a as c, C as i, D as l } from "../constants-Dvwyqn-J.js";
|
|
4
|
+
const r = "./libs/dinoconfig-java-sdk/lib/src/main/java/com/dinoconfig/sdk/generated";
|
|
5
|
+
function p(a) {
|
|
6
|
+
const o = {};
|
|
7
|
+
for (const e of a)
|
|
8
|
+
e === "--help" || e === "-h" ? o.help = !0 : e === "--version" || e === "-v" ? o.version = !0 : e.startsWith("--api-key=") ? o.apiKey = e.slice(10) : e.startsWith("--baseUrl=") || e.startsWith("--base-url=") ? o.baseUrl = e.split("=")[1] : e.startsWith("--output=") || e.startsWith("-o=") ? o.output = e.split("=")[1] : e.startsWith("--package=") || e.startsWith("-p=") ? o.package = e.split("=")[1] : (e === "--skip-deps" || e === "--no-deps") && (o.skipDeps = !0);
|
|
9
|
+
return o;
|
|
10
|
+
}
|
|
11
|
+
function d() {
|
|
12
|
+
console.log(`
|
|
13
|
+
DinoConfig Java Model Generator v${c}
|
|
14
|
+
|
|
15
|
+
Generate Java POJO model classes from DinoConfig schemas.
|
|
16
|
+
|
|
17
|
+
USAGE:
|
|
18
|
+
npx ${i} javagen --api-key=<key> [options]
|
|
19
|
+
|
|
20
|
+
OPTIONS:
|
|
21
|
+
--api-key=<key> Required. Your DinoConfig API key
|
|
22
|
+
--baseUrl=<url> API base URL (default: ${l})
|
|
23
|
+
--output=<path> Output directory path (default: ${r})
|
|
24
|
+
--package=<pkg> Base package for generated classes (auto-derived from output path)
|
|
25
|
+
--skip-deps Skip automatic dependency update in build file
|
|
26
|
+
-h, --help Show this help message
|
|
27
|
+
-v, --version Show version number
|
|
28
|
+
|
|
29
|
+
EXAMPLES:
|
|
30
|
+
# Generate Java models with default settings
|
|
31
|
+
npx ${i} javagen --api-key=dino_abc123
|
|
32
|
+
|
|
33
|
+
# Generate Java models to custom path (package auto-derived from path)
|
|
34
|
+
npx ${i} javagen --api-key=dino_abc123 --output=./src/main/java/org/example/models
|
|
35
|
+
# This will use package: org.example.models
|
|
36
|
+
|
|
37
|
+
# Generate with explicit package
|
|
38
|
+
npx ${i} javagen --api-key=dino_abc123 --output=./src/main/java/org/example/models --package=org.example.config
|
|
39
|
+
|
|
40
|
+
# Skip automatic dependency updates
|
|
41
|
+
npx ${i} javagen --api-key=dino_abc123 --skip-deps
|
|
42
|
+
|
|
43
|
+
PACKAGE RESOLUTION:
|
|
44
|
+
The base package for generated classes is determined in this order:
|
|
45
|
+
1. Explicit --package option (if provided)
|
|
46
|
+
2. Auto-derived from --output path (looks for src/main/java/ pattern)
|
|
47
|
+
3. Default: com.dinoconfig.sdk.generated
|
|
48
|
+
|
|
49
|
+
GENERATED OUTPUT:
|
|
50
|
+
The tool generates Java POJO classes:
|
|
51
|
+
- Each brand gets its own subpackage
|
|
52
|
+
- Each config gets its own class with typed fields
|
|
53
|
+
- Classes follow Java best practices (immutable, Jackson annotations, etc.)
|
|
54
|
+
- Automatically adds Jackson dependency to your build.gradle or pom.xml
|
|
55
|
+
|
|
56
|
+
Example with --output=./src/main/java/org/example/models:
|
|
57
|
+
org/example/models/
|
|
58
|
+
mybrand/
|
|
59
|
+
FeatureFlags.java (package org.example.models.mybrand)
|
|
60
|
+
AppSettings.java
|
|
61
|
+
|
|
62
|
+
DEPENDENCIES:
|
|
63
|
+
Generated models require Jackson for JSON serialization:
|
|
64
|
+
|
|
65
|
+
Gradle:
|
|
66
|
+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
|
|
67
|
+
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.16.1'
|
|
68
|
+
|
|
69
|
+
Maven:
|
|
70
|
+
<dependency>
|
|
71
|
+
<groupId>com.fasterxml.jackson.core</groupId>
|
|
72
|
+
<artifactId>jackson-databind</artifactId>
|
|
73
|
+
<version>2.16.1</version>
|
|
74
|
+
</dependency>
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
function u(a, o, e) {
|
|
78
|
+
console.log(`
|
|
79
|
+
🦖 DinoConfig Java Model Generator v${c}
|
|
80
|
+
`), console.log(` Base URL: ${a}`), console.log(` Output: ${o}`), console.log(e ? ` Package: ${e} (explicit)` : " Package: (auto-derived from output path)"), console.log("");
|
|
81
|
+
}
|
|
82
|
+
function f(a, o, e, n) {
|
|
83
|
+
if (console.log(`
|
|
84
|
+
✅ Java models generated successfully!
|
|
85
|
+
`), o && (console.log(` Generated ${o.brands} brand(s)`), console.log(` Generated ${o.configs} config class(es) with ${o.keys} field(s)`)), console.log(` Output directory: ${a}`), n && console.log(` Base package: ${n}`), e) {
|
|
86
|
+
if (console.log(""), e.success && e.addedDependencies && e.addedDependencies.length > 0) {
|
|
87
|
+
console.log(` 📦 Dependencies added to ${e.buildFilePath}:`);
|
|
88
|
+
for (const t of e.addedDependencies)
|
|
89
|
+
console.log(` + ${t}`);
|
|
90
|
+
} else if (e.success && e.existingDependencies && e.existingDependencies.length > 0)
|
|
91
|
+
console.log(` 📦 Dependencies already present in ${e.buildFilePath}`);
|
|
92
|
+
else if (!e.success && e.error && (console.log(` ⚠️ Could not update dependencies: ${e.error}`), e.warnings)) {
|
|
93
|
+
console.log(""), console.log(" Please add manually:");
|
|
94
|
+
for (const t of e.warnings)
|
|
95
|
+
console.log(` ${t}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
console.log(""), console.log(" Usage in your Java code:"), console.log(""), console.log(` import ${n ?? "com.dinoconfig.sdk.generated"}.brandname.ConfigName;`), console.log("");
|
|
99
|
+
}
|
|
100
|
+
async function m(a) {
|
|
101
|
+
const o = p(a);
|
|
102
|
+
o.help && (d(), process.exit(0)), o.version && (console.log(`DinoConfig Java Model Generator v${c}`), process.exit(0)), o.apiKey || (console.error(`Error: --api-key is required
|
|
103
|
+
`), console.error("Run with --help for usage information"), process.exit(1));
|
|
104
|
+
const e = o.baseUrl ?? l, n = o.output ?? r;
|
|
105
|
+
u(e, n, o.package), console.log(" → Initializing SDK..."), console.log(" → Fetching configuration schemas...");
|
|
106
|
+
const s = await g({
|
|
107
|
+
apiKey: o.apiKey,
|
|
108
|
+
baseUrl: e,
|
|
109
|
+
output: n,
|
|
110
|
+
package: o.package,
|
|
111
|
+
skipDependencyUpdate: o.skipDeps
|
|
112
|
+
});
|
|
113
|
+
s.success || (console.error(`
|
|
114
|
+
❌ Error: ${s.error}`), process.exit(1)), console.log(` → Found ${s.stats?.brands} brand(s)`), console.log(` → Found ${s.stats?.configs} config(s) with ${s.stats?.keys} key(s)`), console.log(` → Using package: ${s.basePackage}`), console.log(" → Generating Java model classes..."), console.log(` → Writing to ${n}...`), o.skipDeps || (s.dependencyUpdate?.success && s.dependencyUpdate.addedDependencies?.length ? console.log(" → Updating project dependencies...") : s.dependencyUpdate?.success && console.log(" → Dependencies already present")), f(n, s.stats, s.dependencyUpdate, s.basePackage);
|
|
115
|
+
}
|
|
116
|
+
process.argv[1]?.includes("javagen") && m(process.argv.slice(2)).catch((a) => {
|
|
117
|
+
const o = a instanceof Error ? a.message : "Unknown error";
|
|
118
|
+
console.error(`
|
|
119
|
+
❌ Error:`, o), process.exit(1);
|
|
120
|
+
});
|
|
121
|
+
export {
|
|
122
|
+
m as runJavagen
|
|
123
|
+
};
|