@postxl/cli 1.2.0 → 1.3.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/dist/generate.command.js
CHANGED
|
@@ -42,10 +42,10 @@ const util_1 = require("util");
|
|
|
42
42
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
43
43
|
const fs = __importStar(require("node:fs/promises"));
|
|
44
44
|
const path = __importStar(require("node:path"));
|
|
45
|
-
const zod_validation_error_1 = require("zod-validation-error");
|
|
46
45
|
const generator_1 = require("@postxl/generator");
|
|
47
46
|
const schema_1 = require("@postxl/schema");
|
|
48
47
|
const utils_1 = require("@postxl/utils");
|
|
48
|
+
const log_schema_error_1 = require("./helpers/log-schema-error");
|
|
49
49
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
50
50
|
function register(program) {
|
|
51
51
|
program
|
|
@@ -235,9 +235,9 @@ async function getSchema(params) {
|
|
|
235
235
|
const jsonSchema = JSON.parse((await fs.readFile(schemaPath)).toString());
|
|
236
236
|
const schema = schema_1.zProjectSchema.safeParse(jsonSchema);
|
|
237
237
|
if (!schema.success) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
console.log('\nError parsing postxl-schema.json:\n');
|
|
239
|
+
(0, log_schema_error_1.logSchemaValidationError)(schema.error);
|
|
240
|
+
process.exit(1);
|
|
241
241
|
}
|
|
242
242
|
return schema.data;
|
|
243
243
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logSchemaValidationError = logSchemaValidationError;
|
|
4
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
5
|
+
const utils_1 = require("@postxl/utils");
|
|
6
|
+
function logSchemaValidationError(error, options = {}) {
|
|
7
|
+
console.log((0, utils_1.red)('✗ Schema validation failed!\n'));
|
|
8
|
+
console.log('❌ Validation Errors:');
|
|
9
|
+
console.log('─'.repeat(50));
|
|
10
|
+
// Show formatted error
|
|
11
|
+
const formattedError = (0, zod_validation_error_1.fromZodError)(error);
|
|
12
|
+
console.log(formattedError.message);
|
|
13
|
+
console.log();
|
|
14
|
+
// Show detailed error if verbose
|
|
15
|
+
if (options.verbose) {
|
|
16
|
+
console.log('📄 Detailed Error Object:');
|
|
17
|
+
console.log('─'.repeat(50));
|
|
18
|
+
console.log(JSON.stringify(error, null, 2));
|
|
19
|
+
console.log();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log((0, utils_1.yellow)('💡 Tip: Use --verbose flag to see the detailed error object'));
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const create_project_command_1 = require("./create-project.command");
|
|
6
6
|
const generate_command_1 = require("./generate.command");
|
|
7
|
+
const validate_command_1 = require("./validate.command");
|
|
7
8
|
const program = new commander_1.Command();
|
|
8
9
|
program
|
|
9
10
|
//
|
|
@@ -13,4 +14,5 @@ program
|
|
|
13
14
|
// Adding all the commands
|
|
14
15
|
(0, generate_command_1.register)(program);
|
|
15
16
|
(0, create_project_command_1.register)(program);
|
|
17
|
+
(0, validate_command_1.register)(program);
|
|
16
18
|
program.parse(process.argv);
|
|
@@ -0,0 +1,146 @@
|
|
|
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 schema_1 = require("@postxl/schema");
|
|
40
|
+
const utils_1 = require("@postxl/utils");
|
|
41
|
+
const log_schema_error_1 = require("./helpers/log-schema-error");
|
|
42
|
+
function register(program) {
|
|
43
|
+
program
|
|
44
|
+
.command('validate')
|
|
45
|
+
.argument('[path]', 'Path to project directory or schema file. If directory, looks for postxl-schema.json. Default is current directory', process.cwd())
|
|
46
|
+
.summary('Validates the PostXL schema.')
|
|
47
|
+
.description(`Validates the PostXL schema.
|
|
48
|
+
|
|
49
|
+
This reads the schema from the specified file or from postxl-schema.json in the specified directory.`)
|
|
50
|
+
.option('-v, --verbose', 'shows detailed error information')
|
|
51
|
+
.action(async (inputPath, options) => {
|
|
52
|
+
if (!path.isAbsolute(inputPath)) {
|
|
53
|
+
inputPath = path.join(process.cwd(), inputPath);
|
|
54
|
+
}
|
|
55
|
+
// Check if input path exists
|
|
56
|
+
let schemaPath;
|
|
57
|
+
try {
|
|
58
|
+
const stats = await fs.stat(inputPath);
|
|
59
|
+
if (stats.isDirectory()) {
|
|
60
|
+
// If it's a directory, look for postxl-schema.json
|
|
61
|
+
schemaPath = path.join(inputPath, 'postxl-schema.json');
|
|
62
|
+
}
|
|
63
|
+
else if (stats.isFile()) {
|
|
64
|
+
// If it's a file, use it directly
|
|
65
|
+
schemaPath = inputPath;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
program.error(`Path ${inputPath} is neither a file nor a directory!`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
program.error(`Cannot find path ${inputPath}!`);
|
|
73
|
+
}
|
|
74
|
+
// Check if schema file exists
|
|
75
|
+
try {
|
|
76
|
+
await fs.access(schemaPath);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
program.error(`Cannot find schema file at ${schemaPath}`);
|
|
80
|
+
}
|
|
81
|
+
// Read and parse JSON
|
|
82
|
+
let jsonSchema;
|
|
83
|
+
try {
|
|
84
|
+
const content = await fs.readFile(schemaPath, 'utf-8');
|
|
85
|
+
jsonSchema = JSON.parse(content);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
program.error(`Error reading or parsing JSON from ${schemaPath}: ${error.message}`);
|
|
89
|
+
}
|
|
90
|
+
// Validate schema
|
|
91
|
+
const result = schema_1.zProjectSchema.safeParse(jsonSchema);
|
|
92
|
+
if (result.success) {
|
|
93
|
+
// Success - show summary
|
|
94
|
+
const schema = result.data;
|
|
95
|
+
console.log((0, utils_1.green)('✓ Schema validation successful!\n'));
|
|
96
|
+
console.log('📋 Schema Summary:');
|
|
97
|
+
console.log('─'.repeat(50));
|
|
98
|
+
console.log(`Name: ${schema.name}`);
|
|
99
|
+
console.log(`Slug: ${schema.slug}`);
|
|
100
|
+
console.log(`Version: ${schema.version}`);
|
|
101
|
+
console.log(`Type: ${schema.projectType}`);
|
|
102
|
+
console.log(`Description: ${schema.description}`);
|
|
103
|
+
console.log();
|
|
104
|
+
console.log(`🗄️ Database Schemas (${schema.databaseSchemas.length}):`);
|
|
105
|
+
schema.databaseSchemas.forEach((name) => console.log(` • ${name}`));
|
|
106
|
+
console.log(` Default: ${schema.defaultDatabaseSchema}`);
|
|
107
|
+
console.log();
|
|
108
|
+
console.log(`📦 Models (${schema.modelNames.length}):`);
|
|
109
|
+
if (schema.modelNames.length > 0) {
|
|
110
|
+
schema.modelNames.forEach((name) => {
|
|
111
|
+
const model = schema.models.get(name);
|
|
112
|
+
if (model) {
|
|
113
|
+
const fieldCount = model.fields.size;
|
|
114
|
+
const seedCount = model.seed?.length ?? 0;
|
|
115
|
+
const seedInfo = seedCount > 0 ? ` [${seedCount} seed records]` : '';
|
|
116
|
+
console.log(` • ${name} (${fieldCount} fields)${seedInfo}`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log(' (none)');
|
|
122
|
+
}
|
|
123
|
+
console.log();
|
|
124
|
+
console.log(`🏷️ Enums (${schema.enumNames.length}):`);
|
|
125
|
+
if (schema.enumNames.length > 0) {
|
|
126
|
+
schema.enumNames.forEach((name) => {
|
|
127
|
+
const enumDef = schema.enums.get(name);
|
|
128
|
+
if (enumDef) {
|
|
129
|
+
const memberCount = enumDef.members.size;
|
|
130
|
+
console.log(` • ${name} (${memberCount} members)`);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.log(' (none)');
|
|
136
|
+
}
|
|
137
|
+
console.log();
|
|
138
|
+
console.log((0, utils_1.green)('✓ All validation checks passed!'));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// Failure - show detailed errors
|
|
142
|
+
(0, log_schema_error_1.logSchemaValidationError)(result.error, options);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Command-line interface for PostXL code generation framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"commander": "14.0.2",
|
|
45
45
|
"dotenv": "17.2.3",
|
|
46
46
|
"zod-validation-error": "3.4.0",
|
|
47
|
-
"@postxl/generator": "^1.1.
|
|
47
|
+
"@postxl/generator": "^1.1.1",
|
|
48
48
|
"@postxl/generators": "^1.3.0",
|
|
49
|
-
"@postxl/schema": "^1.1.
|
|
49
|
+
"@postxl/schema": "^1.1.1",
|
|
50
50
|
"@postxl/utils": "^1.1.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|