@postxl/cli 1.6.0 → 1.7.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.
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function register(program: Command): void;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.register = register;
37
+ const fs = __importStar(require("node:fs/promises"));
38
+ const path = __importStar(require("node:path"));
39
+ const generator_1 = require("@postxl/generator");
40
+ const generators_1 = require("@postxl/generators");
41
+ const schema_1 = require("@postxl/schema");
42
+ const utils_1 = require("@postxl/utils");
43
+ const log_schema_error_1 = require("./helpers/log-schema-error");
44
+ function register(program) {
45
+ program
46
+ .command('generate-types')
47
+ .alias('types')
48
+ .argument('[path]', 'Path to project directory or schema file. Default is current directory', process.cwd())
49
+ .requiredOption('-o, --output <path>', 'Output directory for the generated type files')
50
+ .summary('Generates only the types from a PostXL schema.')
51
+ .description(`Generates only the types from a PostXL schema.
52
+
53
+ This reads the schema and runs only the types generator. The generated type files are written to the specified output directory.`)
54
+ .option('-t, --skip-transform', 'skips formatting')
55
+ .action(async (inputPath, options) => {
56
+ if (!path.isAbsolute(inputPath)) {
57
+ inputPath = path.join(process.cwd(), inputPath);
58
+ }
59
+ // Resolve schema path
60
+ let schemaPath = '';
61
+ try {
62
+ const stats = await fs.stat(inputPath);
63
+ if (stats.isDirectory()) {
64
+ schemaPath = path.join(inputPath, 'postxl-schema.json');
65
+ }
66
+ else if (stats.isFile()) {
67
+ schemaPath = inputPath;
68
+ }
69
+ else {
70
+ program.error(`Path ${inputPath} is neither a file nor a directory!`);
71
+ }
72
+ }
73
+ catch {
74
+ program.error(`Cannot find path ${inputPath}!`);
75
+ }
76
+ try {
77
+ await fs.access(schemaPath);
78
+ }
79
+ catch {
80
+ program.error(`Cannot find schema file at ${schemaPath}`);
81
+ }
82
+ // Parse and validate schema
83
+ let jsonSchema;
84
+ try {
85
+ const content = await fs.readFile(schemaPath, 'utf-8');
86
+ jsonSchema = JSON.parse(content);
87
+ }
88
+ catch (error) {
89
+ program.error(`Error reading or parsing JSON from ${schemaPath}: ${error instanceof Error ? error.message : String(error)}`);
90
+ }
91
+ const result = schema_1.zProjectSchema.safeParse(jsonSchema);
92
+ if (!result.success) {
93
+ console.log('\nError parsing schema:\n');
94
+ (0, log_schema_error_1.logSchemaValidationError)(result.error);
95
+ process.exit(1);
96
+ }
97
+ const schema = result.data;
98
+ // Resolve output path
99
+ let outputPath = options.output;
100
+ if (!path.isAbsolute(outputPath)) {
101
+ outputPath = path.resolve(process.cwd(), outputPath);
102
+ }
103
+ console.log(`Generating types from ${schemaPath}`);
104
+ console.log(`Output directory: ${outputPath}`);
105
+ // Run standalone types generation
106
+ const vfs = await (0, generators_1.generateTypesStandalone)(schema);
107
+ // Apply formatting if not skipped
108
+ if (!options.skipTransform) {
109
+ await vfs.transform(generator_1.format, {
110
+ onError: ({ path: filePath, error }) => {
111
+ console.error((0, utils_1.yellow)(`Warning: Error formatting ${filePath}:`), error);
112
+ },
113
+ });
114
+ }
115
+ // Write VFS files to disk.
116
+ // generateTypesStandalone() returns a VFS with clean relative paths (prefix already stripped).
117
+ await fs.mkdir(outputPath, { recursive: true });
118
+ let fileCount = 0;
119
+ for (const [filePath, content] of vfs.files) {
120
+ const absolutePath = path.join(outputPath, filePath);
121
+ await fs.mkdir(path.dirname(absolutePath), { recursive: true });
122
+ await fs.writeFile(absolutePath, content);
123
+ fileCount++;
124
+ }
125
+ console.log((0, utils_1.green)(`\n${fileCount} type files written to ${outputPath}`));
126
+ });
127
+ }
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const commander_1 = require("commander");
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const create_project_command_1 = require("./create-project.command");
10
10
  const generate_command_1 = require("./generate.command");
11
+ const generate_types_command_1 = require("./generate-types.command");
11
12
  const validate_command_1 = require("./validate.command");
12
13
  // eslint-disable-next-line @typescript-eslint/no-require-imports
13
14
  const { version } = require(node_path_1.default.join(__dirname, '..', 'package.json'));
@@ -19,6 +20,7 @@ program
19
20
  .version(version);
20
21
  // Adding all the commands
21
22
  (0, generate_command_1.register)(program);
23
+ (0, generate_types_command_1.register)(program);
22
24
  (0, create_project_command_1.register)(program);
23
25
  (0, validate_command_1.register)(program);
24
26
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/cli",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Command-line interface for PostXL code generation framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "dotenv": "17.3.1",
46
46
  "zod-validation-error": "5.0.0",
47
47
  "@postxl/generator": "^1.3.7",
48
- "@postxl/generators": "^1.23.1",
48
+ "@postxl/generators": "^1.24.0",
49
49
  "@postxl/schema": "^1.8.2",
50
50
  "@postxl/utils": "^1.4.0"
51
51
  },