@intellegens/cornerstone-cli 0.0.6

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.md ADDED
@@ -0,0 +1,7 @@
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.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Cornerstone TypeScript CLI Tool(s)
2
+
3
+ A command-line interface (CLI) with various utilities. The CLI is built using yargs and supports the following commands:
4
+
5
+ ## Getting started
6
+
7
+ 1. Install dependencies:
8
+
9
+ ```bash
10
+ npm install
11
+ ```
12
+
13
+ ### Available scripts
14
+
15
+ 2. `build`: Compiles the TypeScript code
16
+
17
+ ```bash
18
+ npm run build
19
+ ```
20
+
21
+ 3. `cli`: Runs the CLI in development mode using tsx
22
+
23
+ ```bash
24
+ npm run cli <command> [options]
25
+ ```
26
+
27
+ ### Install and run
28
+
29
+ ```sh
30
+ npm install -g @intellegens/cornerstone-client
31
+ cornerstone-ts <command> [options]
32
+ ```
33
+
34
+ ## API reference
35
+
36
+ ### Zod Schema Generator
37
+
38
+ Generates Zod schemas from JSON schema files, preserving namespace structure.
39
+
40
+ ```bash
41
+ # Development
42
+ npm run cli zod-gen --input <input-dir> --output <output-dir>
43
+
44
+ # After building
45
+ ./dist/utils/cli/index.js zod-gen --input <input-dir> --output <output-dir>
46
+ ```
47
+
48
+ Options:
49
+
50
+ - `--input, -i`: Path to the folder containing JSON schemas
51
+ - `--output, -o`: Path to the folder where Zod schemas will be saved
52
+
53
+ The command will:
54
+
55
+ 1. Read JSON schema files from the input directory
56
+ 2. Create a folder structure matching the type's namespace
57
+ 3. Generate Zod schemas with proper type names
58
+ 4. Save the generated schemas in their respective namespace folders
59
+
60
+ For example, if you have a JSON schema file named `MyCompany.ModuleA.Models.User.json`, it will:
61
+
62
+ - Create directories: `output-dir/MyCompany/ModuleA/Models/`
63
+ - Generate and save `User.ts` in that directory with the Zod schema
@@ -0,0 +1,7 @@
1
+ import { CommandModule } from 'yargs';
2
+ interface ZodSchemaGeneratorArgs {
3
+ input: string;
4
+ output: string;
5
+ }
6
+ export declare const zodSchemaGeneratorCommand: CommandModule<{}, ZodSchemaGeneratorArgs>;
7
+ export {};
@@ -0,0 +1,75 @@
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.zodSchemaGeneratorCommand = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const json_schema_to_zod_1 = require("json-schema-to-zod");
10
+ const json_refs_1 = require("json-refs");
11
+ exports.zodSchemaGeneratorCommand = {
12
+ command: 'zod-gen',
13
+ describe: 'Generate Zod schemas from JSON schemas',
14
+ builder: {
15
+ input: {
16
+ alias: 'i',
17
+ type: 'string',
18
+ describe: 'Path to the folder containing JSON schemas',
19
+ demandOption: true,
20
+ },
21
+ output: {
22
+ alias: 'o',
23
+ type: 'string',
24
+ describe: 'Path to the folder where Zod schemas will be saved',
25
+ demandOption: true,
26
+ },
27
+ },
28
+ async handler(args) {
29
+ try {
30
+ const { input: inputPath, output: outputPath } = args;
31
+ if (!fs_extra_1.default.existsSync(outputPath)) {
32
+ fs_extra_1.default.mkdirSync(outputPath, { recursive: true });
33
+ }
34
+ const files = fs_extra_1.default
35
+ .readdirSync(inputPath)
36
+ .filter((file) => file.endsWith('.json'));
37
+ if (files.length === 0) {
38
+ console.error('No JSON schema files found in the input directory.');
39
+ process.exit(1);
40
+ }
41
+ for (const file of files) {
42
+ const filePath = path_1.default.join(inputPath, file);
43
+ const schemaContent = fs_extra_1.default.readFileSync(filePath, 'utf-8');
44
+ const schema = JSON.parse(schemaContent);
45
+ const fullName = path_1.default.basename(file, '.json');
46
+ const parts = fullName.split('.');
47
+ // Last part is the type name, everything before is namespace
48
+ const typeName = parts[parts.length - 1];
49
+ const namespaceParts = parts.slice(0, -1);
50
+ // Create the namespace folder structure
51
+ const namespaceDir = path_1.default.join(outputPath, ...namespaceParts);
52
+ fs_extra_1.default.mkdirSync(namespaceDir, { recursive: true });
53
+ const { resolved } = await (0, json_refs_1.resolveRefs)(schema);
54
+ // Convert JSON Schema to Zod
55
+ const zodSchema = (0, json_schema_to_zod_1.jsonSchemaToZod)(resolved, {
56
+ withJsdocs: true,
57
+ module: 'esm',
58
+ type: true,
59
+ name: typeName,
60
+ depth: 5,
61
+ });
62
+ // Generate TypeScript file
63
+ const fileName = typeName + '.ts';
64
+ const outputFilePath = path_1.default.join(namespaceDir, fileName);
65
+ fs_extra_1.default.writeFileSync(outputFilePath, zodSchema, 'utf-8');
66
+ console.log(`Generated Zod schema: ${outputFilePath}`);
67
+ }
68
+ console.log('✅ Zod schemas generated successfully!');
69
+ }
70
+ catch (error) {
71
+ console.error('❌ Error generating Zod schemas:', error);
72
+ process.exit(1);
73
+ }
74
+ }
75
+ };
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const yargs_1 = __importDefault(require("yargs"));
8
+ const helpers_1 = require("yargs/helpers");
9
+ const zod_schema_generator_1 = require("./commands/zod-schema-generator");
10
+ (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
11
+ .scriptName('cornerstone-ts')
12
+ .command(zod_schema_generator_1.zodSchemaGeneratorCommand)
13
+ .demandCommand(1, 'You need to specify a command')
14
+ .strict()
15
+ .alias('h', 'help')
16
+ .parse();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@intellegens/cornerstone-cli",
3
+ "version": "0.0.6",
4
+ "main": "./index.js",
5
+ "bin": {
6
+ "cornerstone-ts": "./index.js"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "cli": "tsx ./src/index.ts"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "description": "",
16
+ "dependencies": {
17
+ "fs-extra": "^11.3.0",
18
+ "json-refs": "^3.0.15",
19
+ "json-schema-to-zod": "^2.6.0",
20
+ "typescript": "^5.7.3",
21
+ "yargs": "^17.7.2",
22
+ "zod": "^3.24.2"
23
+ },
24
+ "devDependencies": {
25
+ "@types/fs-extra": "^11.0.4",
26
+ "@types/node": "^22.13.4",
27
+ "@types/yargs": "^17.0.33",
28
+ "prettier": "^3.5.1",
29
+ "tsx": "^4.19.2"
30
+ }
31
+ }