@intellegens/cornerstone-cli 0.0.9999-alpha-7 → 0.0.9999-alpha-10

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
@@ -7,7 +7,7 @@ A command-line interface (CLI) with various utilities. The CLI is built using ya
7
7
  1. Install dependencies:
8
8
 
9
9
  ```bash
10
- npm install
10
+ pnpm install
11
11
  ```
12
12
 
13
13
  ### Available scripts
@@ -15,19 +15,19 @@ npm install
15
15
  2. `build`: Compiles the TypeScript code
16
16
 
17
17
  ```bash
18
- npm run build
18
+ pnpm run build
19
19
  ```
20
20
 
21
21
  3. `cli`: Runs the CLI in development mode using tsx
22
22
 
23
23
  ```bash
24
- npm run cli <command> [options]
24
+ pnpm run cli <command> [options]
25
25
  ```
26
26
 
27
27
  ### Install and run
28
28
 
29
29
  ```sh
30
- npm install -g @intellegens/cornerstone-cli
30
+ pnpm install -g @intellegens/cornerstone-cli
31
31
  cornerstone-ts <command> [options]
32
32
  ```
33
33
 
@@ -39,7 +39,7 @@ Generates Zod schemas from JSON schema files, preserving namespace structure.
39
39
 
40
40
  ```bash
41
41
  # Development
42
- npm run cli zod-gen --input <input-dir> --output <output-dir>
42
+ pnpm run cli zod-gen --input <input-dir> --output <output-dir>
43
43
 
44
44
  # After building
45
45
  ./dist/utils/cli/index.js zod-gen --input <input-dir> --output <output-dir>
@@ -68,7 +68,7 @@ Generates client code from OpenAPI schema files using Orval.
68
68
 
69
69
  ```bash
70
70
  # Development
71
- npm run cli openapi-gen --input <input-file> --output <output-dir> [options]
71
+ pnpm run cli openapi-gen --input <input-file> --output <output-dir> [options]
72
72
 
73
73
  # After building
74
74
  ./dist/utils/cli/index.js openapi-gen --input <input-file> --output <output-dir> [options]
File without changes
File without changes
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
- import { zodSchemaGeneratorCommand } from './commands/zod-schema-generator';
5
- import { openApiGeneratorCommand } from './commands/openapi-generator';
4
+ import { zodSchemaGeneratorCommand } from './commands/zod-schema-generator.js';
5
+ import { openApiGeneratorCommand } from './commands/openapi-generator.js';
6
6
  yargs(hideBin(process.argv))
7
7
  .scriptName('cornerstone-ts')
8
8
  .command(zodSchemaGeneratorCommand)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-cli",
3
- "version": "0.0.9999-alpha-7",
3
+ "version": "0.0.9999-alpha-10",
4
4
  "private": false,
5
5
  "publishable": true,
6
6
  "main": "./index.js",
@@ -16,27 +16,28 @@
16
16
  "bin": {
17
17
  "cornerstone-ts": "./index.js"
18
18
  },
19
- "scripts": {
20
- "clean": "npx --yes rimraf '{dist}'",
21
- "test": "echo 'TBD'",
22
- "coverage": "echo 'TBD'",
23
- "build": "npm run clean && tsc && tsc-alias",
24
- "start": "tsx ./src/index.ts"
25
- },
26
19
  "dependencies": {
20
+ "@orval/core": "^7.16.0",
27
21
  "fs-extra": "^11.3.0",
28
22
  "json-refs": "^3.0.15",
29
23
  "json-schema-to-zod": "^2.6.0",
30
24
  "orval": "^7.10.0",
31
- "typescript": "^5.7.3",
25
+ "typescript": "~5.9.3",
32
26
  "yargs": "^17.7.2",
33
27
  "zod": "^3.24.2"
34
28
  },
35
29
  "devDependencies": {
36
30
  "@types/fs-extra": "^11.0.4",
37
- "@types/node": "^22.13.4",
31
+ "@types/node": "^22.13.9",
38
32
  "@types/yargs": "^17.0.33",
39
33
  "tsc-alias": "^1.8.11",
40
34
  "tsx": "^4.19.2"
35
+ },
36
+ "scripts": {
37
+ "clean": "pnpx rimraf '{dist}'",
38
+ "test": "echo 'TBD'",
39
+ "coverage": "echo 'TBD'",
40
+ "build": "pnpm run clean && tsc && tsc-alias",
41
+ "start": "tsx ./src/index.ts"
41
42
  }
42
- }
43
+ }
@@ -0,0 +1,185 @@
1
+ import { generate } from 'orval';
2
+ import { CommandModule } from 'yargs';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { OptionsExport } from '@orval/core';
6
+
7
+ interface OpenApiGeneratorArgs {
8
+ input: string;
9
+ output: string;
10
+ prettier: boolean;
11
+ zod: boolean;
12
+ fetchClient: boolean;
13
+ angularClient: boolean;
14
+ mock: boolean;
15
+ project: string;
16
+ baseUrl: string;
17
+ clean: boolean;
18
+ }
19
+
20
+ export const openApiGeneratorCommand: CommandModule<{}, OpenApiGeneratorArgs> = {
21
+ command: 'openapi-gen',
22
+ describe: 'Generate Zod schemas from JSON schemas',
23
+
24
+ builder: {
25
+ input: {
26
+ alias: 'i',
27
+ type: 'string',
28
+ describe: 'Path to the OPENAPI schema .json file',
29
+ demandOption: true,
30
+ },
31
+ output: {
32
+ alias: 'o',
33
+ type: 'string',
34
+ describe: 'Path to the folder where client will be saved',
35
+ demandOption: true,
36
+ },
37
+ prettier: {
38
+ alias: 'p',
39
+ type: 'boolean',
40
+ describe: 'Format generated code with Prettier',
41
+ default: false,
42
+ },
43
+ fetchClient: {
44
+ alias: 'f',
45
+ type: 'boolean',
46
+ describe: 'Generate fetch client',
47
+ default: false,
48
+ },
49
+ angularClient: {
50
+ alias: 'a',
51
+ type: 'boolean',
52
+ describe: 'Generate Angular client',
53
+ default: false,
54
+ },
55
+ zod: {
56
+ alias: 'z',
57
+ type: 'boolean',
58
+ describe: 'Generate Zod schemas',
59
+ default: false,
60
+ },
61
+ mock: {
62
+ alias: 'm',
63
+ type: 'boolean',
64
+ describe: 'Generate mock client',
65
+ default: false,
66
+ },
67
+ clean: {
68
+ alias: 'c',
69
+ type: 'boolean',
70
+ describe: 'Clean output folder',
71
+ default: true,
72
+ },
73
+ project: {
74
+ alias: 'pr',
75
+ type: 'string',
76
+ describe: 'Project name',
77
+ default: 'my-project',
78
+ },
79
+ baseUrl: {
80
+ alias: 'b',
81
+ type: 'string',
82
+ describe: 'Base URL for the API',
83
+ default: '',
84
+ },
85
+ },
86
+
87
+ async handler(args: OpenApiGeneratorArgs) {
88
+ try {
89
+ const absoluteInputPath = path.resolve(args.input);
90
+ const absoluteOutputPath = path.resolve(args.output);
91
+ // Check if input file exists
92
+ if (!fs.existsSync(absoluteInputPath)) {
93
+ console.error('🔴 OpenAPI schema file not found:', absoluteInputPath);
94
+ process.exit(1);
95
+ }
96
+
97
+ let configs: OptionsExport[] = [];
98
+
99
+ // Add configurations based on selected options
100
+ if ((!args.fetchClient && !args.angularClient) || args.zod) {
101
+ configs.push({
102
+ input: absoluteInputPath,
103
+ output: {
104
+ mode: 'tags-split',
105
+ target: './zod',
106
+ schemas: './models',
107
+ client: 'zod',
108
+ mock: args.mock,
109
+ prettier: args.prettier,
110
+ clean: args.clean,
111
+ override: {
112
+ useTypeOverInterfaces: true,
113
+ zod: {
114
+ generate: {
115
+ param: false,
116
+ body: args.zod,
117
+ response: false,
118
+ query: false,
119
+ header: false,
120
+ },
121
+ },
122
+ },
123
+ },
124
+ });
125
+ }
126
+
127
+ if (args.fetchClient) {
128
+ configs.push({
129
+ input: absoluteInputPath,
130
+ output: {
131
+ mode: 'tags-split',
132
+ target: './endpoints',
133
+ schemas: './models',
134
+ client: 'fetch',
135
+ httpClient: 'fetch',
136
+ mock: args.mock,
137
+ prettier: args.prettier,
138
+ clean: args.clean,
139
+ override: {
140
+ useTypeOverInterfaces: true,
141
+ },
142
+ },
143
+ });
144
+ }
145
+
146
+ if (args.angularClient) {
147
+ configs.push({
148
+ input: absoluteInputPath,
149
+ output: {
150
+ mode: 'tags-split',
151
+ target: './endpoints',
152
+ schemas: './models',
153
+ client: 'angular',
154
+ mock: args.mock,
155
+ prettier: args.prettier,
156
+ clean: args.clean,
157
+ baseUrl: args.baseUrl,
158
+ override: {
159
+ useTypeOverInterfaces: true,
160
+ },
161
+ },
162
+ });
163
+ }
164
+
165
+ if (configs.length === 0) {
166
+ console.error('🔴 No options selected. Please select at least one option.');
167
+ process.exit(1);
168
+ }
169
+
170
+ // Generate
171
+ for (const config of configs) {
172
+ await generate(config, absoluteOutputPath, { projectName: args.project });
173
+ }
174
+
175
+ console.log('🟢 Schemas generated successfully!');
176
+ } catch (error) {
177
+ console.error('🔴 Error generating schemas:', error);
178
+ if (error instanceof Error) {
179
+ console.error('🔴 Error message:', error.message);
180
+ console.error('🔴 Error stack:', error.stack);
181
+ }
182
+ process.exit(1);
183
+ }
184
+ },
185
+ };
@@ -0,0 +1,116 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { jsonSchemaToZod } from 'json-schema-to-zod';
4
+ import { resolveRefs } from 'json-refs';
5
+ import { CommandModule } from 'yargs';
6
+
7
+ interface ZodSchemaGeneratorArgs {
8
+ input: string;
9
+ output: string;
10
+ }
11
+
12
+ export const zodSchemaGeneratorCommand: CommandModule<
13
+ {},
14
+ ZodSchemaGeneratorArgs
15
+ > = {
16
+ command: 'zod-gen',
17
+ describe: 'Generate Zod schemas from JSON schemas',
18
+
19
+ builder: {
20
+ input: {
21
+ alias: 'i',
22
+ type: 'string',
23
+ describe: 'Path to the folder containing JSON schemas',
24
+ demandOption: true,
25
+ },
26
+ output: {
27
+ alias: 'o',
28
+ type: 'string',
29
+ describe: 'Path to the folder where Zod schemas will be saved',
30
+ demandOption: true,
31
+ },
32
+ },
33
+
34
+ async handler(args: ZodSchemaGeneratorArgs) {
35
+ try {
36
+ const { input: inputPath, output: outputPath } = args;
37
+
38
+ if (!fs.existsSync(inputPath)) {
39
+ console.warn('🟡 Input directory not found.');
40
+ process.exit(0);
41
+ }
42
+
43
+ const files = fs
44
+ .readdirSync(inputPath)
45
+ .filter((file) => file.endsWith('.json'));
46
+
47
+ if (files.length === 0) {
48
+ console.warn('🟡 No JSON schema files found in the input directory.');
49
+ process.exit(0);
50
+ }
51
+
52
+ if (!fs.existsSync(outputPath)) {
53
+ fs.emptyDirSync(outputPath);
54
+ } else {
55
+ fs.mkdirSync(outputPath, { recursive: true });
56
+ }
57
+
58
+ var exports: Record<string, string> = {};
59
+ for (const file of files) {
60
+ const filePath = path.join(inputPath, file);
61
+ const schemaContent = fs.readFileSync(filePath, 'utf-8');
62
+ const schema = JSON.parse(schemaContent);
63
+
64
+ const fullName = path.basename(file, '.json');
65
+ const parts = fullName.split('.');
66
+
67
+ // Last part is the type name, everything before is namespace
68
+ const typeName = parts[parts.length - 1];
69
+ const namespaceParts = parts.slice(0, -1);
70
+
71
+ // Create the namespace folder structure
72
+ const namespaceDir = path.join(outputPath, ...namespaceParts);
73
+ fs.mkdirSync(namespaceDir, { recursive: true });
74
+
75
+ const { resolved } = await resolveRefs(schema);
76
+ // Convert JSON Schema to Zod
77
+ const zodSchema = jsonSchemaToZod(resolved, {
78
+ withJsdocs: true,
79
+ module: 'esm',
80
+ type: true,
81
+ name: typeName,
82
+ depth: 5,
83
+ });
84
+
85
+ // Generate TypeScript file
86
+ const fileName = `${typeName}.ts`;
87
+ const outputFilePath = path.join(namespaceDir, fileName);
88
+ const outputTypePath = path.join(namespaceDir, typeName);
89
+
90
+ fs.writeFileSync(outputFilePath, zodSchema, 'utf-8');
91
+ console.log(`- Generated Zod schema: ${outputFilePath}`);
92
+
93
+ // Register for (re)export
94
+ exports[typeName] = path.relative(outputPath, outputTypePath);
95
+ }
96
+
97
+ // Write (re)export file
98
+ let exportFileContent = '';
99
+ for (const typeName in exports) {
100
+ const typePath = `./${exports[typeName]}`.replace(/\\/g, '/');
101
+ exportFileContent += `export * from '${typePath}'; // .NET ${typeName} class\n`;
102
+ }
103
+ fs.writeFileSync(
104
+ path.join(outputPath, './index.ts'),
105
+ exportFileContent,
106
+ 'utf-8',
107
+ );
108
+
109
+ // Prompt done
110
+ console.log('🟢 Zod schemas generated successfully!');
111
+ } catch (error) {
112
+ console.error('🔴 Error generating Zod schemas:', error);
113
+ process.exit(1);
114
+ }
115
+ },
116
+ };
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
4
+ import { zodSchemaGeneratorCommand } from './commands/zod-schema-generator.js';
5
+ import { openApiGeneratorCommand } from './commands/openapi-generator.js';
6
+
7
+ yargs(hideBin(process.argv))
8
+ .scriptName('cornerstone-ts')
9
+ .command(zodSchemaGeneratorCommand)
10
+ .command(openApiGeneratorCommand)
11
+ .demandCommand(1, 'You need to specify a command')
12
+ .strict()
13
+ .alias('h', 'help')
14
+ .parse();
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist"
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }
package/LICENSE.md DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2025 Intellegens
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.