@postxl/cli 1.8.3 → 1.9.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/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 +331 -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 +5 -2
|
@@ -0,0 +1,331 @@
|
|
|
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.GenerateTsParseError = void 0;
|
|
37
|
+
exports.parseGenerateTs = parseGenerateTs;
|
|
38
|
+
exports.addGenerator = addGenerator;
|
|
39
|
+
exports.removeGenerator = removeGenerator;
|
|
40
|
+
exports.configureGenerator = configureGenerator;
|
|
41
|
+
exports.saveGenerateTs = saveGenerateTs;
|
|
42
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const ts_morph_1 = require("ts-morph");
|
|
45
|
+
const generators_registry_1 = require("./generators-registry");
|
|
46
|
+
class GenerateTsParseError extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = 'GenerateTsParseError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.GenerateTsParseError = GenerateTsParseError;
|
|
53
|
+
/**
|
|
54
|
+
* Read and parse a project's `generate.ts`. Returns the array literal that
|
|
55
|
+
* holds the generator list along with a structured view of each entry.
|
|
56
|
+
*
|
|
57
|
+
* Refuses (throws {@link GenerateTsParseError}) when the file is too custom
|
|
58
|
+
* for safe automated edits — anything beyond `export default function () {
|
|
59
|
+
* return [<calls>] }` (or the equivalent `export default () => [...]`).
|
|
60
|
+
*/
|
|
61
|
+
async function parseGenerateTs(projectPath) {
|
|
62
|
+
const filePath = path.join(projectPath, 'generate.ts');
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
content = await fs.readFile(filePath, 'utf8');
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
throw new GenerateTsParseError(`Cannot find generate.ts at ${filePath}.`);
|
|
69
|
+
}
|
|
70
|
+
const project = new ts_morph_1.Project({ useInMemoryFileSystem: false, skipAddingFilesFromTsConfig: true });
|
|
71
|
+
const sourceFile = project.createSourceFile(filePath, content, { overwrite: true });
|
|
72
|
+
const arrayLiteral = locateGeneratorArrayLiteral(sourceFile);
|
|
73
|
+
const entries = [];
|
|
74
|
+
for (const element of arrayLiteral.getElements()) {
|
|
75
|
+
entries.push(classifyArrayElement(element));
|
|
76
|
+
}
|
|
77
|
+
return { filePath, sourceFile, arrayLiteral, entries, project };
|
|
78
|
+
}
|
|
79
|
+
function locateGeneratorArrayLiteral(sourceFile) {
|
|
80
|
+
const defaultExport = sourceFile.getDefaultExportSymbol();
|
|
81
|
+
if (!defaultExport) {
|
|
82
|
+
throw new GenerateTsParseError('generate.ts has no default export. The `pxl generators` command can only edit files that export a default function returning an array of generator calls.');
|
|
83
|
+
}
|
|
84
|
+
// Walk to the function that's actually being default-exported.
|
|
85
|
+
const exportAssignment = sourceFile.getExportAssignment((ea) => !ea.isExportEquals());
|
|
86
|
+
let body;
|
|
87
|
+
if (exportAssignment) {
|
|
88
|
+
const expr = exportAssignment.getExpression();
|
|
89
|
+
body = arrayLiteralFromExpression(expr);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// `export default function generate() {...}` form.
|
|
93
|
+
const fn = sourceFile.getFunction((f) => f.isDefaultExport());
|
|
94
|
+
if (fn) {
|
|
95
|
+
body = arrayLiteralFromFunction(fn);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!body || !ts_morph_1.Node.isArrayLiteralExpression(body)) {
|
|
99
|
+
throw new GenerateTsParseError('Could not locate the array literal of generators in generate.ts. Expected `export default function generate() { return [...] }` or an arrow form.');
|
|
100
|
+
}
|
|
101
|
+
return body;
|
|
102
|
+
}
|
|
103
|
+
function arrayLiteralFromExpression(expr) {
|
|
104
|
+
if (ts_morph_1.Node.isArrowFunction(expr)) {
|
|
105
|
+
const fnBody = expr.getBody();
|
|
106
|
+
if (ts_morph_1.Node.isArrayLiteralExpression(fnBody)) {
|
|
107
|
+
return fnBody;
|
|
108
|
+
}
|
|
109
|
+
if (ts_morph_1.Node.isBlock(fnBody)) {
|
|
110
|
+
return arrayLiteralFromBlock(fnBody);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (ts_morph_1.Node.isFunctionExpression(expr)) {
|
|
114
|
+
return arrayLiteralFromBlock(expr.getBody());
|
|
115
|
+
}
|
|
116
|
+
if (ts_morph_1.Node.isArrayLiteralExpression(expr)) {
|
|
117
|
+
return expr;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
function arrayLiteralFromFunction(fn) {
|
|
122
|
+
const block = fn.getBody();
|
|
123
|
+
if (!block || !ts_morph_1.Node.isBlock(block)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return arrayLiteralFromBlock(block);
|
|
127
|
+
}
|
|
128
|
+
function arrayLiteralFromBlock(block) {
|
|
129
|
+
const ret = block.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ReturnStatement);
|
|
130
|
+
if (!ret) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
const arg = ret.getExpression();
|
|
134
|
+
if (!arg || !ts_morph_1.Node.isArrayLiteralExpression(arg)) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
// Refuse if there are statements other than the single return.
|
|
138
|
+
const block2 = ret.getParent();
|
|
139
|
+
if (block2 && ts_morph_1.Node.isBlock(block2)) {
|
|
140
|
+
const stmts = block2.getStatements().filter((s) => !ts_morph_1.Node.isReturnStatement(s));
|
|
141
|
+
if (stmts.length > 0) {
|
|
142
|
+
throw new GenerateTsParseError('generate.ts contains statements beyond a single `return [...]`. Refusing to edit — please update the file manually.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return arg;
|
|
146
|
+
}
|
|
147
|
+
function classifyArrayElement(node) {
|
|
148
|
+
if (ts_morph_1.Node.isIdentifier(node)) {
|
|
149
|
+
const reg = (0, generators_registry_1.findRegistryByMatcher)(node.getText());
|
|
150
|
+
if (reg && reg.kind === 'identifier') {
|
|
151
|
+
return { kind: 'identifier', name: reg.name, registry: reg, node };
|
|
152
|
+
}
|
|
153
|
+
return { kind: 'unknown', text: node.getText(), node };
|
|
154
|
+
}
|
|
155
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(node)) {
|
|
156
|
+
// e.g. `Frontend.configureFrontendGenerator(...)` matches in CallExpression below;
|
|
157
|
+
// a bare PropertyAccess (rare) we just record verbatim.
|
|
158
|
+
return { kind: 'unknown', text: node.getText(), node };
|
|
159
|
+
}
|
|
160
|
+
if (ts_morph_1.Node.isCallExpression(node)) {
|
|
161
|
+
const calleeText = node.getExpression().getText();
|
|
162
|
+
// Check both bare and member-access forms (e.g. `Frontend.configureFrontendGenerator`).
|
|
163
|
+
const lastSegment = calleeText.includes('.') ? calleeText.split('.').pop() : calleeText;
|
|
164
|
+
const reg = (0, generators_registry_1.findRegistryByMatcher)(lastSegment);
|
|
165
|
+
if (reg && reg.kind === 'configure') {
|
|
166
|
+
const arg = node.getArguments()[0];
|
|
167
|
+
const optionsText = arg && ts_morph_1.Node.isObjectLiteralExpression(arg) ? arg.getText() : undefined;
|
|
168
|
+
return { kind: 'configure', name: reg.name, registry: reg, optionsText, node };
|
|
169
|
+
}
|
|
170
|
+
return { kind: 'unknown', text: node.getText(), node };
|
|
171
|
+
}
|
|
172
|
+
return { kind: 'unknown', text: node.getText(), node };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Append a generator entry to the array. Inserts an import if needed.
|
|
176
|
+
* Returns true if the file was modified. No-ops (returns false) if the
|
|
177
|
+
* generator is already present.
|
|
178
|
+
*/
|
|
179
|
+
function addGenerator(parsed, name) {
|
|
180
|
+
const reg = generators_registry_1.GENERATOR_REGISTRY.find((g) => g.name === name);
|
|
181
|
+
if (!reg) {
|
|
182
|
+
return { changed: false, reason: `Unknown generator name "${name}".` };
|
|
183
|
+
}
|
|
184
|
+
if (parsed.entries.some((e) => e.kind !== 'unknown' && e.name === name)) {
|
|
185
|
+
return { changed: false, reason: `Generator "${name}" is already enabled.` };
|
|
186
|
+
}
|
|
187
|
+
ensureImport(parsed.sourceFile, reg);
|
|
188
|
+
const insertionText = reg.kind === 'identifier' ? reg.identifier : `${reg.configureFn}(${reg.defaultOptions()})`;
|
|
189
|
+
parsed.arrayLiteral.addElement(insertionText);
|
|
190
|
+
return { changed: true };
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Remove the entry whose name matches. Removes the import too if no other
|
|
194
|
+
* reference remains in the source.
|
|
195
|
+
*/
|
|
196
|
+
function removeGenerator(parsed, name) {
|
|
197
|
+
const reg = generators_registry_1.GENERATOR_REGISTRY.find((g) => g.name === name);
|
|
198
|
+
if (!reg) {
|
|
199
|
+
return { changed: false, reason: `Unknown generator name "${name}".` };
|
|
200
|
+
}
|
|
201
|
+
const idx = parsed.entries.findIndex((e) => e.kind !== 'unknown' && e.name === name);
|
|
202
|
+
if (idx === -1) {
|
|
203
|
+
return { changed: false, reason: `Generator "${name}" is not enabled.` };
|
|
204
|
+
}
|
|
205
|
+
parsed.arrayLiteral.removeElement(idx);
|
|
206
|
+
// Refresh: re-classify so subsequent edits in the same session see the new state.
|
|
207
|
+
refreshEntries(parsed);
|
|
208
|
+
// Remove the now-unused import binding if no other reference remains.
|
|
209
|
+
const importedSymbol = reg.kind === 'identifier' ? reg.identifier : reg.configureFn;
|
|
210
|
+
pruneImport(parsed.sourceFile, importedSymbol);
|
|
211
|
+
return { changed: true };
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Replace the options object of a configure-style generator. The options text
|
|
215
|
+
* must parse as a single object-literal expression — we validate it through
|
|
216
|
+
* ts-morph before substituting so a malformed `--options` flag can't
|
|
217
|
+
* silently corrupt `generate.ts`.
|
|
218
|
+
*/
|
|
219
|
+
function configureGenerator(parsed, name, optionsObjectLiteral) {
|
|
220
|
+
const entry = parsed.entries.find((e) => e.kind === 'configure' && e.name === name);
|
|
221
|
+
if (!entry) {
|
|
222
|
+
return { changed: false, reason: `Generator "${name}" is not enabled or is not a configurable generator.` };
|
|
223
|
+
}
|
|
224
|
+
const trimmed = optionsObjectLiteral.trim();
|
|
225
|
+
if (!isValidObjectLiteral(parsed.project, trimmed)) {
|
|
226
|
+
return {
|
|
227
|
+
changed: false,
|
|
228
|
+
reason: `Options must be a valid TypeScript object literal expression (e.g. \`{ adapters: ['log'] }\`).`,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const args = entry.node.getArguments();
|
|
232
|
+
if (args.length === 0) {
|
|
233
|
+
entry.node.addArgument(trimmed);
|
|
234
|
+
return { changed: true };
|
|
235
|
+
}
|
|
236
|
+
// Guard: classifyArrayElement records `kind: 'configure'` even when the
|
|
237
|
+
// first argument is something other than an object literal (e.g. a passed
|
|
238
|
+
// variable like `configureFoo(opts)`). In that case `optionsText` is
|
|
239
|
+
// undefined — replacing the node would silently rewrite the wrong thing,
|
|
240
|
+
// so we refuse and tell the user to edit manually.
|
|
241
|
+
const target = args[0];
|
|
242
|
+
if (!target || !ts_morph_1.Node.isObjectLiteralExpression(target)) {
|
|
243
|
+
return {
|
|
244
|
+
changed: false,
|
|
245
|
+
reason: `Generator "${name}" is configured with a non-literal argument; please edit generate.ts manually.`,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
target.replaceWithText(trimmed);
|
|
249
|
+
return { changed: true };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Parse `text` in isolation and confirm it is a single ObjectLiteralExpression
|
|
253
|
+
* with no trailing tokens. Anything else (statements, multiple expressions, a
|
|
254
|
+
* non-object-literal expression, parse errors) is rejected.
|
|
255
|
+
*/
|
|
256
|
+
function isValidObjectLiteral(project, text) {
|
|
257
|
+
const tempPath = `/__configure_options_${Math.random().toString(36).slice(2)}.ts`;
|
|
258
|
+
let scratch;
|
|
259
|
+
try {
|
|
260
|
+
scratch = project.createSourceFile(tempPath, `const __pxl_options = ${text}\n`, { overwrite: true });
|
|
261
|
+
const stmts = scratch.getStatements();
|
|
262
|
+
if (stmts.length !== 1) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
const stmt = stmts[0];
|
|
266
|
+
if (!stmt || !ts_morph_1.Node.isVariableStatement(stmt)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const decls = stmt.getDeclarationList().getDeclarations();
|
|
270
|
+
const init = decls[0]?.getInitializer();
|
|
271
|
+
if (!init || !ts_morph_1.Node.isObjectLiteralExpression(init)) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
// Ensure no syntax errors in the scratch file.
|
|
275
|
+
return scratch.getPreEmitDiagnostics().length === 0;
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
scratch?.delete();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function refreshEntries(parsed) {
|
|
285
|
+
parsed.entries = parsed.arrayLiteral.getElements().map(classifyArrayElement);
|
|
286
|
+
}
|
|
287
|
+
function ensureImport(sourceFile, reg) {
|
|
288
|
+
const importedSymbol = reg.kind === 'identifier' ? reg.identifier : reg.configureFn;
|
|
289
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
290
|
+
if (decl.getModuleSpecifierValue() !== reg.importFrom) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const named = decl.getNamedImports();
|
|
294
|
+
if (named.some((n) => n.getName() === importedSymbol)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
decl.addNamedImport(importedSymbol);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
sourceFile.addImportDeclaration({
|
|
301
|
+
moduleSpecifier: reg.importFrom,
|
|
302
|
+
namedImports: [importedSymbol],
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
function pruneImport(sourceFile, importedSymbol) {
|
|
306
|
+
// If the symbol is still referenced outside import declarations, leave it
|
|
307
|
+
// alone. We deliberately skip identifiers nested under `ImportDeclaration`
|
|
308
|
+
// so we don't count the import itself as a use.
|
|
309
|
+
const stillUsed = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier).some((id) => {
|
|
310
|
+
if (id.getText() !== importedSymbol) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
return !id.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ImportDeclaration);
|
|
314
|
+
});
|
|
315
|
+
if (stillUsed) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
319
|
+
const named = decl.getNamedImports().find((n) => n.getName() === importedSymbol);
|
|
320
|
+
if (named) {
|
|
321
|
+
named.remove();
|
|
322
|
+
if (decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport()) {
|
|
323
|
+
decl.remove();
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function saveGenerateTs(parsed) {
|
|
330
|
+
await parsed.sourceFile.save();
|
|
331
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recognized PostXL generator names (kebab-case) used by `pxl generators`,
|
|
3
|
+
* mapped to the import specifier and call shape the editor will emit when
|
|
4
|
+
* adding them to `generate.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The shape `'identifier'` denotes a plain reference (e.g. `backendGenerator`),
|
|
7
|
+
* while `'configure'` denotes a callable factory (e.g.
|
|
8
|
+
* `configureBackendMailGenerator(opts)`). The configure form is what makes a
|
|
9
|
+
* dedicated `pxl generators` command earn its keep — hand-editing the JSON
|
|
10
|
+
* argument list of these calls is exactly the painful bit.
|
|
11
|
+
*/
|
|
12
|
+
export type RegistryEntry = {
|
|
13
|
+
kind: 'identifier';
|
|
14
|
+
name: string;
|
|
15
|
+
identifier: string;
|
|
16
|
+
importFrom: '@postxl/generators';
|
|
17
|
+
importMember?: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'configure';
|
|
20
|
+
name: string;
|
|
21
|
+
configureFn: string;
|
|
22
|
+
importFrom: '@postxl/generators';
|
|
23
|
+
defaultOptions: () => string;
|
|
24
|
+
describeOptions?: (objectLiteralText: string) => string;
|
|
25
|
+
};
|
|
26
|
+
export declare const GENERATOR_REGISTRY: RegistryEntry[];
|
|
27
|
+
/**
|
|
28
|
+
* Reverse mapping: a top-level call expression in `generate.ts` is matched
|
|
29
|
+
* against this list to figure out which registry entry it belongs to. Both
|
|
30
|
+
* the identifier and the configure-fn match.
|
|
31
|
+
*/
|
|
32
|
+
export declare function findRegistryByMatcher(text: string): RegistryEntry | undefined;
|
|
33
|
+
export declare function findRegistryByName(name: string): RegistryEntry | undefined;
|
|
34
|
+
export declare const RECOGNIZED_NAMES: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Predefined archetypes used by `pxl generators preset <preset>`. Each preset
|
|
37
|
+
* lists the kebab-case names that should be enabled; everything else is left
|
|
38
|
+
* alone.
|
|
39
|
+
*/
|
|
40
|
+
export declare const PRESETS: Record<string, string[]>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRESETS = exports.RECOGNIZED_NAMES = exports.GENERATOR_REGISTRY = void 0;
|
|
4
|
+
exports.findRegistryByMatcher = findRegistryByMatcher;
|
|
5
|
+
exports.findRegistryByName = findRegistryByName;
|
|
6
|
+
exports.GENERATOR_REGISTRY = [
|
|
7
|
+
{ kind: 'identifier', name: 'backend-core', identifier: 'backendGenerator', importFrom: '@postxl/generators' },
|
|
8
|
+
{
|
|
9
|
+
kind: 'identifier',
|
|
10
|
+
name: 'backend-database-prisma',
|
|
11
|
+
identifier: 'databasePrismaGenerator',
|
|
12
|
+
importFrom: '@postxl/generators',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
kind: 'identifier',
|
|
16
|
+
name: 'backend-actions',
|
|
17
|
+
identifier: 'backendActionsGenerator',
|
|
18
|
+
importFrom: '@postxl/generators',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
kind: 'identifier',
|
|
22
|
+
name: 'backend-authentication',
|
|
23
|
+
identifier: 'backendAuthenticationGenerator',
|
|
24
|
+
importFrom: '@postxl/generators',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
kind: 'identifier',
|
|
28
|
+
name: 'backend-repositories',
|
|
29
|
+
identifier: 'backendRepositoriesGenerator',
|
|
30
|
+
importFrom: '@postxl/generators',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
kind: 'identifier',
|
|
34
|
+
name: 'backend-router-trpc',
|
|
35
|
+
identifier: 'backendTrpcRouterGenerator',
|
|
36
|
+
importFrom: '@postxl/generators',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
kind: 'identifier',
|
|
40
|
+
name: 'backend-rest-api',
|
|
41
|
+
identifier: 'backendRestApiGenerator',
|
|
42
|
+
importFrom: '@postxl/generators',
|
|
43
|
+
},
|
|
44
|
+
{ kind: 'identifier', name: 'backend-s3', identifier: 'backendS3Generator', importFrom: '@postxl/generators' },
|
|
45
|
+
{ kind: 'identifier', name: 'backend-ai', identifier: 'backendAiGenerator', importFrom: '@postxl/generators' },
|
|
46
|
+
{
|
|
47
|
+
kind: 'identifier',
|
|
48
|
+
name: 'backend-import',
|
|
49
|
+
identifier: 'backendImportGenerator',
|
|
50
|
+
importFrom: '@postxl/generators',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
kind: 'identifier',
|
|
54
|
+
name: 'backend-data-management',
|
|
55
|
+
identifier: 'backendDataManagementGenerator',
|
|
56
|
+
importFrom: '@postxl/generators',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: 'configure',
|
|
60
|
+
name: 'backend-mail',
|
|
61
|
+
configureFn: 'configureBackendMailGenerator',
|
|
62
|
+
importFrom: '@postxl/generators',
|
|
63
|
+
defaultOptions: () => `{ adapters: ['log'], renderers: ['simple'] }`,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
kind: 'identifier',
|
|
67
|
+
name: 'frontend-admin',
|
|
68
|
+
identifier: 'frontendAdminGenerator',
|
|
69
|
+
importFrom: '@postxl/generators',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
kind: 'identifier',
|
|
73
|
+
name: 'frontend-forms',
|
|
74
|
+
identifier: 'frontendFormsGenerator',
|
|
75
|
+
importFrom: '@postxl/generators',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
kind: 'identifier',
|
|
79
|
+
name: 'frontend-tables',
|
|
80
|
+
identifier: 'frontendTablesGenerator',
|
|
81
|
+
importFrom: '@postxl/generators',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
kind: 'identifier',
|
|
85
|
+
name: 'frontend-trpc-client',
|
|
86
|
+
identifier: 'frontendTrpcClientGenerator',
|
|
87
|
+
importFrom: '@postxl/generators',
|
|
88
|
+
},
|
|
89
|
+
{ kind: 'identifier', name: 'e2e', identifier: 'e2eGenerator', importFrom: '@postxl/generators' },
|
|
90
|
+
{
|
|
91
|
+
kind: 'configure',
|
|
92
|
+
name: 'devops',
|
|
93
|
+
configureFn: 'configureDevopsGenerator',
|
|
94
|
+
importFrom: '@postxl/generators',
|
|
95
|
+
defaultOptions: () => `{ useDatabase: true, keycloakComponents: [], useS3: false, useBitbucket: false }`,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* Reverse mapping: a top-level call expression in `generate.ts` is matched
|
|
100
|
+
* against this list to figure out which registry entry it belongs to. Both
|
|
101
|
+
* the identifier and the configure-fn match.
|
|
102
|
+
*/
|
|
103
|
+
function findRegistryByMatcher(text) {
|
|
104
|
+
for (const entry of exports.GENERATOR_REGISTRY) {
|
|
105
|
+
if (entry.kind === 'identifier' && entry.identifier === text) {
|
|
106
|
+
return entry;
|
|
107
|
+
}
|
|
108
|
+
if (entry.kind === 'configure' && entry.configureFn === text) {
|
|
109
|
+
return entry;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
function findRegistryByName(name) {
|
|
115
|
+
return exports.GENERATOR_REGISTRY.find((e) => e.name === name);
|
|
116
|
+
}
|
|
117
|
+
exports.RECOGNIZED_NAMES = exports.GENERATOR_REGISTRY.map((e) => e.name);
|
|
118
|
+
/**
|
|
119
|
+
* Predefined archetypes used by `pxl generators preset <preset>`. Each preset
|
|
120
|
+
* lists the kebab-case names that should be enabled; everything else is left
|
|
121
|
+
* alone.
|
|
122
|
+
*/
|
|
123
|
+
exports.PRESETS = {
|
|
124
|
+
full: exports.GENERATOR_REGISTRY.map((e) => e.name),
|
|
125
|
+
'admin-only': [
|
|
126
|
+
'backend-core',
|
|
127
|
+
'backend-database-prisma',
|
|
128
|
+
'backend-actions',
|
|
129
|
+
'backend-authentication',
|
|
130
|
+
'backend-repositories',
|
|
131
|
+
'backend-router-trpc',
|
|
132
|
+
'frontend-admin',
|
|
133
|
+
'frontend-forms',
|
|
134
|
+
'frontend-tables',
|
|
135
|
+
'frontend-trpc-client',
|
|
136
|
+
],
|
|
137
|
+
'api-only': [
|
|
138
|
+
'backend-core',
|
|
139
|
+
'backend-database-prisma',
|
|
140
|
+
'backend-actions',
|
|
141
|
+
'backend-authentication',
|
|
142
|
+
'backend-repositories',
|
|
143
|
+
'backend-router-trpc',
|
|
144
|
+
'backend-rest-api',
|
|
145
|
+
],
|
|
146
|
+
minimal: ['backend-core', 'backend-database-prisma', 'backend-repositories'],
|
|
147
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type LockEntry, type PosixPath } from '@postxl/generator';
|
|
2
|
+
/**
|
|
3
|
+
* Per-file status of a generated file relative to the lock file and disk.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the state model in `sync.ts` but without a virtual (in-memory) layer
|
|
6
|
+
* — we read only the lock file and disk so this can run without invoking
|
|
7
|
+
* generators. The categorization is deterministic from `(lock, disk)`:
|
|
8
|
+
*
|
|
9
|
+
* - clean : disk hash === lock hash
|
|
10
|
+
* - modified : disk hash !== lock hash, lock entry is not ejected
|
|
11
|
+
* - ejected : lock entry is the `"ejected"` sentinel
|
|
12
|
+
* - orphan : lock has an entry but the file is missing on disk
|
|
13
|
+
* - untracked-generated : file is present on disk in a directory that holds
|
|
14
|
+
* tracked files (a "generated path") but has no
|
|
15
|
+
* lock entry of its own
|
|
16
|
+
*/
|
|
17
|
+
export type FileStatusState = 'clean' | 'modified' | 'ejected' | 'orphan' | 'untracked-generated';
|
|
18
|
+
export type FileStatus = {
|
|
19
|
+
path: PosixPath;
|
|
20
|
+
state: FileStatusState;
|
|
21
|
+
lockfileHash: LockEntry | undefined;
|
|
22
|
+
diskHash: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
export type ProjectStatus = {
|
|
25
|
+
projectPath: string;
|
|
26
|
+
files: FileStatus[];
|
|
27
|
+
counts: Record<FileStatusState, number>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Compute the status of every file mentioned in the lock file plus any file
|
|
31
|
+
* that lives in a "generated path" but has no lock entry.
|
|
32
|
+
*
|
|
33
|
+
* "Generated paths" are derived from the lock file itself: every directory
|
|
34
|
+
* that contains at least one tracked file is considered a generated path.
|
|
35
|
+
* This avoids hard-coding allowlists like `backend/` or `frontend/` and stays
|
|
36
|
+
* accurate as generators move output around.
|
|
37
|
+
*/
|
|
38
|
+
export declare function computeProjectStatus(params: {
|
|
39
|
+
projectPath: string;
|
|
40
|
+
}): Promise<ProjectStatus>;
|
|
41
|
+
/**
|
|
42
|
+
* Filter for the `pxl status` flags. Each flag narrows results to a single
|
|
43
|
+
* state; no flags returns everything.
|
|
44
|
+
*/
|
|
45
|
+
export type StatusFilter = {
|
|
46
|
+
modified?: boolean;
|
|
47
|
+
ejected?: boolean;
|
|
48
|
+
orphan?: boolean;
|
|
49
|
+
untracked?: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare function filterStatus(status: ProjectStatus, filter: StatusFilter): FileStatus[];
|
|
52
|
+
/**
|
|
53
|
+
* Exit code for `pxl status` (and reused by `pxl doctor`):
|
|
54
|
+
* - 0 if every file is `clean` or `ejected`
|
|
55
|
+
* - 1 if any file is `modified`, `orphan`, or `untracked-generated`
|
|
56
|
+
*/
|
|
57
|
+
export declare function statusExitCode(status: ProjectStatus): 0 | 1;
|