@postxl/cli 1.8.3 → 1.9.1
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/custom-block.command.d.ts +2 -0
- package/dist/custom-block.command.js +185 -0
- package/dist/doctor.command.d.ts +2 -0
- package/dist/doctor.command.js +234 -0
- package/dist/generate.command.js +7 -1
- package/dist/generators.command.d.ts +2 -0
- package/dist/generators.command.js +233 -0
- package/dist/helpers/cli-helpers.d.ts +18 -0
- package/dist/helpers/cli-helpers.js +89 -0
- package/dist/helpers/generate-ts-editor.d.ts +76 -0
- package/dist/helpers/generate-ts-editor.js +339 -0
- package/dist/helpers/generators-registry.d.ts +40 -0
- package/dist/helpers/generators-registry.js +147 -0
- package/dist/helpers/project-status.d.ts +57 -0
- package/dist/helpers/project-status.js +175 -0
- package/dist/helpers/schema-rename.d.ts +91 -0
- package/dist/helpers/schema-rename.js +408 -0
- package/dist/index.js +15 -0
- package/dist/info.command.d.ts +2 -0
- package/dist/info.command.js +202 -0
- package/dist/schema-rename.command.d.ts +2 -0
- package/dist/schema-rename.command.js +149 -0
- package/dist/schema-show.command.d.ts +2 -0
- package/dist/schema-show.command.js +137 -0
- package/dist/status.command.d.ts +2 -0
- package/dist/status.command.js +235 -0
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -7,8 +7,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
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
|
+
const custom_block_command_1 = require("./custom-block.command");
|
|
11
|
+
const doctor_command_1 = require("./doctor.command");
|
|
10
12
|
const generate_command_1 = require("./generate.command");
|
|
11
13
|
const generate_types_command_1 = require("./generate-types.command");
|
|
14
|
+
const generators_command_1 = require("./generators.command");
|
|
15
|
+
const info_command_1 = require("./info.command");
|
|
16
|
+
const schema_rename_command_1 = require("./schema-rename.command");
|
|
17
|
+
const schema_show_command_1 = require("./schema-show.command");
|
|
18
|
+
const status_command_1 = require("./status.command");
|
|
12
19
|
const validate_command_1 = require("./validate.command");
|
|
13
20
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
14
21
|
const { version } = require(node_path_1.default.join(__dirname, '..', 'package.json'));
|
|
@@ -23,4 +30,12 @@ program
|
|
|
23
30
|
(0, generate_types_command_1.register)(program);
|
|
24
31
|
(0, create_project_command_1.register)(program);
|
|
25
32
|
(0, validate_command_1.register)(program);
|
|
33
|
+
(0, status_command_1.register)(program);
|
|
34
|
+
(0, generators_command_1.register)(program);
|
|
35
|
+
(0, info_command_1.register)(program);
|
|
36
|
+
(0, custom_block_command_1.register)(program);
|
|
37
|
+
// schema show registers the `schema` parent — schemaRenameCommand reuses it.
|
|
38
|
+
(0, schema_show_command_1.register)(program);
|
|
39
|
+
(0, schema_rename_command_1.register)(program);
|
|
40
|
+
(0, doctor_command_1.register)(program);
|
|
26
41
|
program.parse(process.argv);
|
|
@@ -0,0 +1,202 @@
|
|
|
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 cli_helpers_1 = require("./helpers/cli-helpers");
|
|
42
|
+
const generate_ts_editor_1 = require("./helpers/generate-ts-editor");
|
|
43
|
+
const load_project_schema_1 = require("./helpers/load-project-schema");
|
|
44
|
+
const project_status_1 = require("./helpers/project-status");
|
|
45
|
+
function register(program) {
|
|
46
|
+
program
|
|
47
|
+
.command('info')
|
|
48
|
+
.argument('[path]', 'Path to project directory. Default is current directory', process.cwd())
|
|
49
|
+
.summary('One-shot project orientation.')
|
|
50
|
+
.description(`Summarizes the PostXL project at the given path: schema, generators, and generated state.
|
|
51
|
+
|
|
52
|
+
Composes the same data shown by \`pxl validate\`, \`pxl status\`, and \`pxl generators list\`.`)
|
|
53
|
+
.option('-j, --json', 'machine-readable output')
|
|
54
|
+
.action(async (inputPath, options) => {
|
|
55
|
+
const projectPath = await (0, cli_helpers_1.resolveProjectPath)(inputPath, program);
|
|
56
|
+
const [schemaInfo, status, generatorsInfo, envChecks, cliVersion] = await Promise.all([
|
|
57
|
+
loadSchemaInfo(projectPath, program),
|
|
58
|
+
(0, project_status_1.computeProjectStatus)({ projectPath }),
|
|
59
|
+
loadGeneratorsInfo(projectPath),
|
|
60
|
+
checkEnvFiles(projectPath),
|
|
61
|
+
getCliVersion(),
|
|
62
|
+
]);
|
|
63
|
+
if (options.json) {
|
|
64
|
+
process.stdout.write(JSON.stringify({
|
|
65
|
+
project: schemaInfo
|
|
66
|
+
? {
|
|
67
|
+
name: schemaInfo.schema.name,
|
|
68
|
+
slug: schemaInfo.schema.slug,
|
|
69
|
+
version: schemaInfo.schema.version,
|
|
70
|
+
projectType: schemaInfo.schema.projectType,
|
|
71
|
+
models: schemaInfo.modelStats,
|
|
72
|
+
enums: schemaInfo.enumStats,
|
|
73
|
+
}
|
|
74
|
+
: null,
|
|
75
|
+
cliVersion,
|
|
76
|
+
generators: generatorsInfo,
|
|
77
|
+
status: {
|
|
78
|
+
counts: status.counts,
|
|
79
|
+
tracked: status.counts.clean + status.counts.modified + status.counts.ejected + status.counts.orphan,
|
|
80
|
+
},
|
|
81
|
+
env: envChecks,
|
|
82
|
+
}, null, 2) + '\n');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
printInfoText({ projectPath, schemaInfo, status, generatorsInfo, envChecks, cliVersion });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function loadSchemaInfo(projectPath, program) {
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = await (0, load_project_schema_1.loadAndMergeRawSchema)({ projectPath, program });
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const result = schema_1.zProjectSchema.safeParse(raw);
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
// For inline-vs-split counts we go back to the original file.
|
|
101
|
+
const originalRaw = JSON.parse(await fs.readFile(path.join(projectPath, 'postxl-schema.json'), 'utf8'));
|
|
102
|
+
const inlineModels = originalRaw.models ? Object.keys(originalRaw.models).length : 0;
|
|
103
|
+
const inlineEnums = originalRaw.enums ? Object.keys(originalRaw.enums).length : 0;
|
|
104
|
+
const totalModels = result.data.modelNames.length;
|
|
105
|
+
const totalEnums = result.data.enumNames.length;
|
|
106
|
+
return {
|
|
107
|
+
schema: result.data,
|
|
108
|
+
modelStats: { total: totalModels, inline: inlineModels, split: Math.max(0, totalModels - inlineModels) },
|
|
109
|
+
enumStats: { total: totalEnums, inline: inlineEnums, split: Math.max(0, totalEnums - inlineEnums) },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function loadGeneratorsInfo(projectPath) {
|
|
113
|
+
try {
|
|
114
|
+
const parsed = await (0, generate_ts_editor_1.parseGenerateTs)(projectPath);
|
|
115
|
+
const enabled = parsed.entries.filter((e) => e.kind !== 'unknown').length;
|
|
116
|
+
return { kind: 'parsed', enabled, total: parsed.entries.length };
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
if (e instanceof generate_ts_editor_1.GenerateTsParseError) {
|
|
120
|
+
return { kind: 'unparsable', reason: e.message };
|
|
121
|
+
}
|
|
122
|
+
if (e.code === 'ENOENT') {
|
|
123
|
+
return { kind: 'missing' };
|
|
124
|
+
}
|
|
125
|
+
return { kind: 'unparsable', reason: String(e) };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function checkEnvFiles(projectPath) {
|
|
129
|
+
const candidates = [
|
|
130
|
+
{ rel: 'backend/apps/api/.env', required: true },
|
|
131
|
+
{ rel: 'backend/.env', required: false },
|
|
132
|
+
{ rel: '.env', required: false },
|
|
133
|
+
];
|
|
134
|
+
const results = [];
|
|
135
|
+
for (const c of candidates) {
|
|
136
|
+
const exists = await (0, cli_helpers_1.fileExists)(path.join(projectPath, c.rel));
|
|
137
|
+
results.push({ path: c.rel, present: exists, required: c.required });
|
|
138
|
+
}
|
|
139
|
+
return results;
|
|
140
|
+
}
|
|
141
|
+
async function getCliVersion() {
|
|
142
|
+
try {
|
|
143
|
+
const pkg = JSON.parse(await fs.readFile(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
144
|
+
return pkg.version;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return 'unknown';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function printInfoText(params) {
|
|
151
|
+
const { projectPath, schemaInfo, status, generatorsInfo, envChecks, cliVersion } = params;
|
|
152
|
+
const projectName = path.basename(projectPath);
|
|
153
|
+
if (schemaInfo) {
|
|
154
|
+
const { schema, modelStats, enumStats } = schemaInfo;
|
|
155
|
+
console.log(`Project: ${schema.name} (${schema.projectType})`);
|
|
156
|
+
console.log(`Slug: ${schema.slug} Version: ${schema.version} PostXL CLI: ${cliVersion}`);
|
|
157
|
+
console.log();
|
|
158
|
+
const splitModelsLabel = modelStats.split > 0 ? ` + ${modelStats.split} split files (schema/*.model.json)` : '';
|
|
159
|
+
console.log(`Schema: postxl-schema.json${splitModelsLabel}`);
|
|
160
|
+
console.log(` Models: ${modelStats.total} (${modelStats.inline} inline, ${modelStats.split} split)`);
|
|
161
|
+
console.log(` Enums: ${enumStats.total} (${enumStats.inline} inline, ${enumStats.split} split)`);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
console.log(`Project: ${projectName}`);
|
|
165
|
+
console.log(`PostXL CLI: ${cliVersion}`);
|
|
166
|
+
console.log((0, utils_1.yellow)('Schema: postxl-schema.json missing or invalid (run `pxl validate` for details)'));
|
|
167
|
+
}
|
|
168
|
+
console.log();
|
|
169
|
+
switch (generatorsInfo.kind) {
|
|
170
|
+
case 'parsed':
|
|
171
|
+
console.log(`Generators (${generatorsInfo.enabled} enabled${generatorsInfo.total !== generatorsInfo.enabled
|
|
172
|
+
? `, ${generatorsInfo.total - generatorsInfo.enabled} unrecognized`
|
|
173
|
+
: ''}): see \`pxl generators list\` for details`);
|
|
174
|
+
break;
|
|
175
|
+
case 'unparsable':
|
|
176
|
+
console.log((0, utils_1.yellow)(`Generators: generate.ts could not be parsed (${generatorsInfo.reason})`));
|
|
177
|
+
break;
|
|
178
|
+
case 'missing':
|
|
179
|
+
console.log((0, utils_1.yellow)('Generators: no generate.ts found'));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
console.log();
|
|
183
|
+
console.log('Generated state:');
|
|
184
|
+
const tracked = status.counts.clean + status.counts.modified + status.counts.ejected + status.counts.orphan;
|
|
185
|
+
console.log(` Tracked: ${tracked} files`);
|
|
186
|
+
console.log(` Modified: ${color(status.counts.modified, utils_1.red)}`);
|
|
187
|
+
console.log(` Ejected: ${status.counts.ejected}`);
|
|
188
|
+
console.log(` Orphans: ${color(status.counts.orphan, utils_1.yellow)}`);
|
|
189
|
+
if (status.counts['untracked-generated'] > 0) {
|
|
190
|
+
console.log(` Untracked-generated: ${(0, utils_1.yellow)(String(status.counts['untracked-generated']))}`);
|
|
191
|
+
}
|
|
192
|
+
console.log();
|
|
193
|
+
console.log('Environment:');
|
|
194
|
+
for (const env of envChecks) {
|
|
195
|
+
const statusLabel = env.present ? (0, utils_1.green)('present') : env.required ? (0, utils_1.red)('missing') : (0, utils_1.gray)('missing');
|
|
196
|
+
const note = env.required && !env.present ? ` ${(0, utils_1.gray)('← required for backend startup')}` : '';
|
|
197
|
+
console.log(` ${env.path}: ${statusLabel}${note}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function color(n, fn) {
|
|
201
|
+
return n > 0 ? fn(String(n)) : String(n);
|
|
202
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 path = __importStar(require("node:path"));
|
|
38
|
+
const utils_1 = require("@postxl/utils");
|
|
39
|
+
const cli_helpers_1 = require("./helpers/cli-helpers");
|
|
40
|
+
const schema_rename_1 = require("./helpers/schema-rename");
|
|
41
|
+
function register(program) {
|
|
42
|
+
// The `schema` command is registered by `schema-show.command.ts` — but
|
|
43
|
+
// `commander` lets us add subcommands by re-fetching the parent. Re-using
|
|
44
|
+
// the existing parent keeps `pxl schema --help` listing all subcommands.
|
|
45
|
+
const schemaParent = program.commands.find((c) => c.name() === 'schema') ?? program.command('schema');
|
|
46
|
+
schemaParent
|
|
47
|
+
.command('rename-model')
|
|
48
|
+
.argument('<oldName>', 'Existing model name (e.g. Country)')
|
|
49
|
+
.argument('<newName>', 'Replacement model name (e.g. Region)')
|
|
50
|
+
.argument('[path]', 'Path to project directory. Default is current directory', process.cwd())
|
|
51
|
+
.option('--dry-run', 'list the planned changes without writing')
|
|
52
|
+
.action(async (oldName, newName, inputPath, options) => {
|
|
53
|
+
const projectPath = await (0, cli_helpers_1.resolveProjectPath)(inputPath, program);
|
|
54
|
+
let plan;
|
|
55
|
+
try {
|
|
56
|
+
plan = await (0, schema_rename_1.planRenameModel)({ projectPath, oldName, newName });
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
program.error(e.message, { exitCode: 2 });
|
|
60
|
+
}
|
|
61
|
+
await reportAndApplyPlan({
|
|
62
|
+
plan,
|
|
63
|
+
projectPath,
|
|
64
|
+
dryRun: !!options.dryRun,
|
|
65
|
+
action: `rename-model ${oldName} → ${newName}`,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
schemaParent
|
|
69
|
+
.command('rename-field')
|
|
70
|
+
.argument('<oldRef>', 'Existing field reference in the form Model.fieldName')
|
|
71
|
+
.argument('<newRef>', 'Replacement field reference in the form Model.fieldName')
|
|
72
|
+
.argument('[path]', 'Path to project directory. Default is current directory', process.cwd())
|
|
73
|
+
.option('--dry-run', 'list the planned changes without writing')
|
|
74
|
+
.action(async (oldRef, newRef, inputPath, options) => {
|
|
75
|
+
const projectPath = await (0, cli_helpers_1.resolveProjectPath)(inputPath, program);
|
|
76
|
+
const oldParts = oldRef.split('.');
|
|
77
|
+
const newParts = newRef.split('.');
|
|
78
|
+
if (oldParts.length !== 2 || newParts.length !== 2) {
|
|
79
|
+
program.error('rename-field arguments must be of the form "Model.fieldName"', { exitCode: 2 });
|
|
80
|
+
}
|
|
81
|
+
if (oldParts[0] !== newParts[0]) {
|
|
82
|
+
program.error('rename-field cannot move a field to a different model. Use a separate workflow.', {
|
|
83
|
+
exitCode: 2,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
let plan;
|
|
87
|
+
try {
|
|
88
|
+
plan = await (0, schema_rename_1.planRenameField)({
|
|
89
|
+
projectPath,
|
|
90
|
+
modelName: oldParts[0],
|
|
91
|
+
oldField: oldParts[1],
|
|
92
|
+
newField: newParts[1],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
program.error(e.message, { exitCode: 2 });
|
|
97
|
+
}
|
|
98
|
+
await reportAndApplyPlan({
|
|
99
|
+
plan,
|
|
100
|
+
projectPath,
|
|
101
|
+
dryRun: !!options.dryRun,
|
|
102
|
+
action: `rename-field ${oldRef} → ${newRef}`,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function reportAndApplyPlan(params) {
|
|
107
|
+
const { plan, projectPath, dryRun, action } = params;
|
|
108
|
+
if (plan.summary.length === 0 && plan.fileRenames.length === 0 && plan.lockfileDeletions.length === 0) {
|
|
109
|
+
console.log((0, utils_1.yellow)(`No changes for "${action}".`));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log((0, utils_1.green)(`Planned changes for ${action}:`));
|
|
113
|
+
for (const line of plan.summary) {
|
|
114
|
+
console.log(` ${line}`);
|
|
115
|
+
}
|
|
116
|
+
if (plan.fileRenames.length > 0) {
|
|
117
|
+
console.log();
|
|
118
|
+
console.log((0, utils_1.green)('File renames:'));
|
|
119
|
+
for (const r of plan.fileRenames) {
|
|
120
|
+
console.log(` ${path.relative(projectPath, r.from)} → ${path.relative(projectPath, r.to)}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (plan.lockfileDeletions.length > 0) {
|
|
124
|
+
console.log();
|
|
125
|
+
console.log((0, utils_1.green)(`Lockfile entries to drop (${plan.lockfileDeletions.length}):`));
|
|
126
|
+
for (const k of plan.lockfileDeletions.slice(0, 20)) {
|
|
127
|
+
console.log(` ${(0, utils_1.gray)(k)}`);
|
|
128
|
+
}
|
|
129
|
+
if (plan.lockfileDeletions.length > 20) {
|
|
130
|
+
console.log(` ${(0, utils_1.gray)(`… and ${plan.lockfileDeletions.length - 20} more`)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (plan.customBlockReferences.length > 0) {
|
|
134
|
+
console.log();
|
|
135
|
+
console.log((0, utils_1.yellow)(`Files with custom blocks that may reference the old name (${plan.customBlockReferences.length}):`));
|
|
136
|
+
for (const f of plan.customBlockReferences) {
|
|
137
|
+
console.log(` ${f}`);
|
|
138
|
+
}
|
|
139
|
+
console.log((0, utils_1.gray)(' These are not modified automatically. Review them after the rename.'));
|
|
140
|
+
}
|
|
141
|
+
if (dryRun) {
|
|
142
|
+
console.log();
|
|
143
|
+
console.log((0, utils_1.yellow)('Dry run: nothing was written. Re-run without --dry-run to apply.'));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await (0, schema_rename_1.applyPlan)(plan, projectPath);
|
|
147
|
+
console.log();
|
|
148
|
+
console.log((0, utils_1.green)('✓ Applied. Run `pnpm run generate -f` to regenerate affected files.'));
|
|
149
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = register;
|
|
4
|
+
const utils_1 = require("@postxl/utils");
|
|
5
|
+
const cli_helpers_1 = require("./helpers/cli-helpers");
|
|
6
|
+
const load_project_schema_1 = require("./helpers/load-project-schema");
|
|
7
|
+
function register(program) {
|
|
8
|
+
const cmd = program.command('schema').summary('Inspect or refactor the project schema.');
|
|
9
|
+
cmd
|
|
10
|
+
.command('show')
|
|
11
|
+
.argument('<name>', 'Model or enum name (e.g. User, Role)')
|
|
12
|
+
.argument('[path]', 'Path to project directory. Default is current directory', process.cwd())
|
|
13
|
+
.option('-j, --json', 'machine-readable JSON output')
|
|
14
|
+
.action(async (name, inputPath, options) => {
|
|
15
|
+
const projectPath = await (0, cli_helpers_1.resolveProjectPath)(inputPath, program);
|
|
16
|
+
const schema = await (0, load_project_schema_1.loadProjectSchema)({ projectPath, program });
|
|
17
|
+
const model = schema.models.get(name);
|
|
18
|
+
const enumDef = schema.enums.get(name);
|
|
19
|
+
if (!model && !enumDef) {
|
|
20
|
+
program.error(`No model or enum named "${name}" in this schema. Models: ${schema.modelNames.join(', ')}; Enums: ${schema.enumNames.join(', ')}`, { exitCode: 2 });
|
|
21
|
+
}
|
|
22
|
+
if (model) {
|
|
23
|
+
if (options.json) {
|
|
24
|
+
process.stdout.write(JSON.stringify(modelToJson(model, schema), null, 2) + '\n');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
printModel(model, schema);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (enumDef) {
|
|
31
|
+
if (options.json) {
|
|
32
|
+
process.stdout.write(JSON.stringify(enumToJson(enumDef), null, 2) + '\n');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
printEnum(enumDef);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function modelToJson(model, schema) {
|
|
40
|
+
return {
|
|
41
|
+
name: model.name,
|
|
42
|
+
databaseSchema: model.databaseSchema,
|
|
43
|
+
description: model.description,
|
|
44
|
+
isReadonly: model.isReadonly,
|
|
45
|
+
fields: [...model.fields.values()].map((f) => ({
|
|
46
|
+
name: f.name,
|
|
47
|
+
kind: f.kind,
|
|
48
|
+
...(f.kind !== 'id' && 'databaseType' in f ? { databaseType: f.databaseType } : {}),
|
|
49
|
+
...(f.kind !== 'id' && 'isRequired' in f ? { isRequired: f.isRequired } : {}),
|
|
50
|
+
...(f.kind !== 'id' && 'isUnique' in f ? { isUnique: f.isUnique } : {}),
|
|
51
|
+
...(f.kind === 'relation' && 'targetModel' in f ? { target: f.targetModel } : {}),
|
|
52
|
+
...(f.kind === 'enum' && 'enumName' in f ? { enumName: f.enumName } : {}),
|
|
53
|
+
})),
|
|
54
|
+
seedCount: model.seed?.length ?? 0,
|
|
55
|
+
auth: model.auth ?? null,
|
|
56
|
+
schemaTotals: { models: schema.modelNames.length, enums: schema.enumNames.length },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function enumToJson(enumDef) {
|
|
60
|
+
return {
|
|
61
|
+
name: enumDef.name,
|
|
62
|
+
databaseSchema: enumDef.databaseSchema,
|
|
63
|
+
members: [...enumDef.members.values()].map((m) => ({ value: m.value, description: m.description })),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function printModel(model, schema) {
|
|
67
|
+
console.log((0, utils_1.bold)(`Model: ${model.name}`) + (0, utils_1.gray)(` (schema: ${model.databaseSchema})`));
|
|
68
|
+
if (model.description) {
|
|
69
|
+
console.log((0, utils_1.gray)(` ${model.description}`));
|
|
70
|
+
}
|
|
71
|
+
console.log();
|
|
72
|
+
const fields = [...model.fields.values()];
|
|
73
|
+
console.log(`Fields (${fields.length}):`);
|
|
74
|
+
for (const f of fields) {
|
|
75
|
+
let summary = ` ${pad(f.name, 24)}`;
|
|
76
|
+
if (f.kind === 'id') {
|
|
77
|
+
const idType = f.type ?? 'String';
|
|
78
|
+
summary += `${pad(idType, 10)} pk`;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const dbType = 'databaseType' in f ? String(f.databaseType) : f.kind;
|
|
82
|
+
summary += pad(dbType, 10);
|
|
83
|
+
const flags = [];
|
|
84
|
+
if ('isRequired' in f && !f.isRequired) {
|
|
85
|
+
flags.push('optional');
|
|
86
|
+
}
|
|
87
|
+
if ('isUnique' in f && f.isUnique) {
|
|
88
|
+
flags.push('unique');
|
|
89
|
+
}
|
|
90
|
+
if ('isReadonly' in f && f.isReadonly) {
|
|
91
|
+
flags.push('readonly');
|
|
92
|
+
}
|
|
93
|
+
if (f.kind === 'relation' && 'targetModel' in f) {
|
|
94
|
+
flags.push(`→ ${f.targetModel}`);
|
|
95
|
+
}
|
|
96
|
+
if (f.kind === 'enum' && 'enumName' in f) {
|
|
97
|
+
flags.push(`enum ${f.enumName}`);
|
|
98
|
+
}
|
|
99
|
+
if (flags.length > 0) {
|
|
100
|
+
summary += ` ${(0, utils_1.gray)(flags.join(', '))}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log(summary);
|
|
104
|
+
}
|
|
105
|
+
console.log();
|
|
106
|
+
if (model.auth) {
|
|
107
|
+
console.log((0, utils_1.green)('Auth:'));
|
|
108
|
+
for (const [op, rule] of Object.entries(model.auth)) {
|
|
109
|
+
console.log(` ${pad(op + ':', 8)}${formatAuthRule(rule)}`);
|
|
110
|
+
}
|
|
111
|
+
console.log();
|
|
112
|
+
}
|
|
113
|
+
if (model.seed && model.seed.length > 0) {
|
|
114
|
+
console.log(`Seed records: ${model.seed.length}`);
|
|
115
|
+
}
|
|
116
|
+
if (schema.defaultDatabaseSchema && model.databaseSchema === schema.defaultDatabaseSchema) {
|
|
117
|
+
console.log((0, utils_1.gray)(`(uses default database schema)`));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function printEnum(enumDef) {
|
|
121
|
+
console.log((0, utils_1.bold)(`Enum: ${enumDef.name}`) + (0, utils_1.gray)(` (schema: ${enumDef.databaseSchema})`));
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(`Members (${enumDef.members.size}):`);
|
|
124
|
+
for (const m of enumDef.members.values()) {
|
|
125
|
+
const desc = m.description ? ` ${(0, utils_1.gray)(`"${m.description}"`)}` : '';
|
|
126
|
+
console.log(` ${m.value}${desc}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function formatAuthRule(rule) {
|
|
130
|
+
if (rule === undefined || rule === null) {
|
|
131
|
+
return (0, utils_1.yellow)('(unset)');
|
|
132
|
+
}
|
|
133
|
+
return JSON.stringify(rule);
|
|
134
|
+
}
|
|
135
|
+
function pad(s, width) {
|
|
136
|
+
return s.length >= width ? s + ' ' : s + ' '.repeat(width - s.length);
|
|
137
|
+
}
|