@intellegens/cornerstone-cli 0.0.26 → 0.0.27

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 CHANGED
@@ -57,7 +57,36 @@ The command will:
57
57
  3. Generate Zod schemas with proper type names
58
58
  4. Save the generated schemas in their respective namespace folders
59
59
 
60
- For example, if you have a JSON schema file named `MyCompany.ModuleA.Models.User.json`, it will:
60
+ For example, if you have a JSON schema file named `MyCompany.ModuleA.Models.UserDto.json`, it will:
61
61
 
62
62
  - Create directories: `output-dir/MyCompany/ModuleA/Models/`
63
- - Generate and save `User.ts` in that directory with the Zod schema
63
+ - Generate and save `UserDto.ts` in that directory with the Zod schema
64
+
65
+ ### OpenAPI Generator
66
+
67
+ Generates client code from OpenAPI schema files using Orval.
68
+
69
+ ```bash
70
+ # Development
71
+ npm run cli openapi-gen --input <input-file> --output <output-dir> [options]
72
+
73
+ # After building
74
+ ./dist/utils/cli/index.js openapi-gen --input <input-file> --output <output-dir> [options]
75
+ ```
76
+
77
+ Options:
78
+
79
+ - `--input, -i`: Path to the OPENAPI schema .json file
80
+ - `--output, -o`: Path to the folder where client and types will be saved
81
+ - `--prettier, -p`: Format generated code with Prettier (default: false)
82
+ - `--fetchClient, -f`: Generate fetch client (default: false)
83
+ - `--angularClient, -a`: Generate Angular client (default: false)
84
+ - `--zod, -z`: Generate Zod schemas (default: false)
85
+ - `--mock, -m`: Generate mock client (default: false)
86
+ - `--clean, -c`: Clean output folder (default: true)
87
+ - `--project, -pr`: Project name (default: 'my-project')
88
+ - `--baseUrl, -b`: Base URL for the API (default: '')
89
+
90
+ The command will generate client code based on the selected options. By default, it generates only types; additionally, you can generate fetch client, angular client or zod schemas.
91
+
92
+
@@ -0,0 +1,15 @@
1
+ import { CommandModule } from 'yargs';
2
+ interface OpenApiGeneratorArgs {
3
+ input: string;
4
+ output: string;
5
+ prettier: boolean;
6
+ zod: boolean;
7
+ fetchClient: boolean;
8
+ angularClient: boolean;
9
+ mock: boolean;
10
+ project: string;
11
+ baseUrl: string;
12
+ clean: boolean;
13
+ }
14
+ export declare const openApiGeneratorCommand: CommandModule<{}, OpenApiGeneratorArgs>;
15
+ export {};
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.openApiGeneratorCommand = void 0;
7
+ const orval_1 = require("orval");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ exports.openApiGeneratorCommand = {
10
+ command: 'openapi-gen',
11
+ describe: 'Generate Zod schemas from JSON schemas',
12
+ builder: {
13
+ input: {
14
+ alias: 'i',
15
+ type: 'string',
16
+ describe: 'Path to the OPENAPI schema .json file',
17
+ demandOption: true,
18
+ },
19
+ output: {
20
+ alias: 'o',
21
+ type: 'string',
22
+ describe: 'Path to the folder where client will be saved',
23
+ demandOption: true,
24
+ },
25
+ prettier: {
26
+ alias: 'p',
27
+ type: 'boolean',
28
+ describe: 'Format generated code with Prettier',
29
+ default: false,
30
+ },
31
+ fetchClient: {
32
+ alias: 'f',
33
+ type: 'boolean',
34
+ describe: 'Generate fetch client',
35
+ default: false,
36
+ },
37
+ angularClient: {
38
+ alias: 'a',
39
+ type: 'boolean',
40
+ describe: 'Generate Angular client',
41
+ default: false,
42
+ },
43
+ zod: {
44
+ alias: 'z',
45
+ type: 'boolean',
46
+ describe: 'Generate Zod schemas',
47
+ default: false,
48
+ },
49
+ mock: {
50
+ alias: 'm',
51
+ type: 'boolean',
52
+ describe: 'Generate mock client',
53
+ default: false,
54
+ },
55
+ clean: {
56
+ alias: 'c',
57
+ type: 'boolean',
58
+ describe: 'Clean output folder',
59
+ default: true,
60
+ },
61
+ project: {
62
+ alias: 'pr',
63
+ type: 'string',
64
+ describe: 'Project name',
65
+ default: 'my-project',
66
+ },
67
+ baseUrl: {
68
+ alias: 'b',
69
+ type: 'string',
70
+ describe: 'Base URL for the API',
71
+ default: '',
72
+ },
73
+ },
74
+ async handler(args) {
75
+ try {
76
+ // Check if input file exists
77
+ if (!fs_1.default.existsSync(args.input)) {
78
+ console.error('🔴 OpenAPI schema file not found:', args.input);
79
+ process.exit(1);
80
+ }
81
+ let configs = [];
82
+ // Add configurations based on selected options
83
+ if ((!args.fetchClient && !args.angularClient) || args.zod) {
84
+ configs.push({
85
+ input: args.input,
86
+ output: {
87
+ mode: 'tags-split',
88
+ target: './zod',
89
+ schemas: './models',
90
+ client: 'zod',
91
+ mock: args.mock,
92
+ prettier: args.prettier,
93
+ clean: args.clean,
94
+ override: {
95
+ useTypeOverInterfaces: true,
96
+ zod: {
97
+ generate: {
98
+ param: false,
99
+ body: args.zod,
100
+ response: false,
101
+ query: false,
102
+ header: false,
103
+ },
104
+ },
105
+ },
106
+ },
107
+ });
108
+ }
109
+ if (args.fetchClient) {
110
+ configs.push({
111
+ input: args.input,
112
+ output: {
113
+ mode: 'tags-split',
114
+ target: './endpoints',
115
+ schemas: './models',
116
+ client: 'fetch',
117
+ httpClient: 'fetch',
118
+ mock: args.mock,
119
+ prettier: args.prettier,
120
+ clean: args.clean,
121
+ override: {
122
+ useTypeOverInterfaces: true,
123
+ },
124
+ },
125
+ });
126
+ }
127
+ if (args.angularClient) {
128
+ configs.push({
129
+ input: args.input,
130
+ output: {
131
+ mode: 'tags-split',
132
+ target: './endpoints',
133
+ schemas: './models',
134
+ client: 'angular',
135
+ mock: args.mock,
136
+ prettier: args.prettier,
137
+ clean: args.clean,
138
+ baseUrl: args.baseUrl,
139
+ override: {
140
+ useTypeOverInterfaces: true,
141
+ },
142
+ },
143
+ });
144
+ }
145
+ if (configs.length === 0) {
146
+ console.error('🔴 No options selected. Please select at least one option.');
147
+ process.exit(1);
148
+ }
149
+ // Generate
150
+ for (const config of configs) {
151
+ await (0, orval_1.generate)(config, args.output, { projectName: args.project });
152
+ }
153
+ console.log('🟢 Schemas generated successfully!');
154
+ }
155
+ catch (error) {
156
+ console.error('🔴 Error generating schemas:', error);
157
+ if (error instanceof Error) {
158
+ console.error('🔴 Error message:', error.message);
159
+ console.error('🔴 Error stack:', error.stack);
160
+ }
161
+ process.exit(1);
162
+ }
163
+ },
164
+ };
package/index.js CHANGED
@@ -7,9 +7,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const yargs_1 = __importDefault(require("yargs"));
8
8
  const helpers_1 = require("yargs/helpers");
9
9
  const zod_schema_generator_1 = require("./commands/zod-schema-generator");
10
+ const openapi_generator_1 = require("./commands/openapi-generator");
10
11
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
11
12
  .scriptName('cornerstone-ts')
12
13
  .command(zod_schema_generator_1.zodSchemaGeneratorCommand)
14
+ .command(openapi_generator_1.openApiGeneratorCommand)
13
15
  .demandCommand(1, 'You need to specify a command')
14
16
  .strict()
15
17
  .alias('h', 'help')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-cli",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "main": "./index.js",
5
5
  "bin": {
6
6
  "cornerstone-ts": "./index.js"
@@ -18,6 +18,7 @@
18
18
  "fs-extra": "^11.3.0",
19
19
  "json-refs": "^3.0.15",
20
20
  "json-schema-to-zod": "^2.6.0",
21
+ "orval": "^7.10.0",
21
22
  "typescript": "^5.7.3",
22
23
  "yargs": "^17.7.2",
23
24
  "zod": "^3.24.2"