@postxl/cli 1.10.2 → 1.11.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
|
@@ -57,14 +57,19 @@ function register(program) {
|
|
|
57
57
|
.description(`Generates the project.
|
|
58
58
|
|
|
59
59
|
This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the generators specified in ${(0, utils_1.yellow)('generate.ts')}.`)
|
|
60
|
-
.option('-d, --diff', 'shows diff between
|
|
61
|
-
.option('
|
|
62
|
-
|
|
60
|
+
.option('-d, --diff', 'shows diff between each modified file and its generated content')
|
|
61
|
+
.option('--modified', 'lists files edited on disk (what `pxl status` calls modified) and any ejected ones')
|
|
62
|
+
// `-e, --ejected` listed files the developer had edited, which `pxl status`
|
|
63
|
+
// calls `modified` -- while `pxl status -e` filters the actual `"ejected"`
|
|
64
|
+
// sentinel. Same flag, two commands, opposite meanings. Kept as a working
|
|
65
|
+
// alias so existing scripts do not break.
|
|
66
|
+
.option('-e, --ejected', 'deprecated alias for --modified')
|
|
67
|
+
.option('-f, --force', 'overwrites modified files (ejected files are still skipped -- force respects the sentinel)')
|
|
63
68
|
.option('-i, --ignore-errors', 'ignores errors during generation')
|
|
64
69
|
.option('--dry-run', 'compute the changes that would be made without writing or updating the lockfile')
|
|
65
70
|
.option('-m, --model <names...>', 'regenerate only for the given models (accepts multiple, e.g. -m Country City)')
|
|
66
71
|
.option('-n, --no-fix', 'does not attempt to fix linting errors')
|
|
67
|
-
.option('--no-three-way', 'skips reconstructing the previous generation for three-way merges (faster;
|
|
72
|
+
.option('--no-three-way', 'skips reconstructing the previous generation for three-way merges (faster; modified files fall back to the 2-way merge)')
|
|
68
73
|
.option('-p, --pattern <glob>', 'filters files by glob pattern (e.g., "**/*.ts" or "backend/libs/**")')
|
|
69
74
|
.option('-q, --quiet', 'does not print errors')
|
|
70
75
|
.option('-s, --skip-lint', 'skips linting')
|
|
@@ -94,7 +99,7 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
|
|
|
94
99
|
const verb = options.dryRun ? 'Would generate' : 'Generating';
|
|
95
100
|
console.log(`${verb} project from ${projectPath} to ${targetPath}`);
|
|
96
101
|
if (options.force) {
|
|
97
|
-
console.log((0, utils_1.yellow)('Warning: Forcing generation of
|
|
102
|
+
console.log((0, utils_1.yellow)('Warning: Forcing generation of modified files!'));
|
|
98
103
|
}
|
|
99
104
|
if (options.dryRun) {
|
|
100
105
|
console.log((0, utils_1.yellow)('Dry run: no files will be written and the lockfile will not be updated.'));
|
|
@@ -153,8 +158,8 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
|
|
|
153
158
|
...(baseVfs ? { baseVfs } : {}),
|
|
154
159
|
});
|
|
155
160
|
(0, generator_1.logSyncResult)(result, {
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
showModifiedStats: options.modified ?? options.ejected ?? false,
|
|
162
|
+
showModifiedDiff: options.diff ?? false,
|
|
158
163
|
});
|
|
159
164
|
// A 2-way merge conflicts far more eagerly than diff3 does. Without
|
|
160
165
|
// this note a conflict list produced without a base reads as "these
|
|
@@ -176,7 +181,7 @@ This reads the schema from ${(0, utils_1.yellow)('schema.json')} and runs the ge
|
|
|
176
181
|
if (!options.dryRun && result.success) {
|
|
177
182
|
await (0, base_snapshot_1.writeBaseSnapshot)(targetPath, {
|
|
178
183
|
schemaSnapshot: rawSchema,
|
|
179
|
-
generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(),
|
|
184
|
+
generatorVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
|
|
180
185
|
});
|
|
181
186
|
}
|
|
182
187
|
return g;
|
|
@@ -232,7 +237,7 @@ function hasMergeConflicts(result) {
|
|
|
232
237
|
async function maybeReconstructBaseVfs(params) {
|
|
233
238
|
const { manager, targetPath, options, targetModelNames } = params;
|
|
234
239
|
// `--no-three-way` opts out of base reconstruction entirely (fast iteration);
|
|
235
|
-
//
|
|
240
|
+
// modified files then fall back to the 2-way merge.
|
|
236
241
|
if (options.threeWay === false) {
|
|
237
242
|
return undefined;
|
|
238
243
|
}
|
|
@@ -240,8 +245,20 @@ async function maybeReconstructBaseVfs(params) {
|
|
|
240
245
|
if (!snapshot) {
|
|
241
246
|
return undefined;
|
|
242
247
|
}
|
|
248
|
+
// Reported before every check below, all of which decide whether reconstructing a base is worth
|
|
249
|
+
// the second generation - a question independent of whether the generator changed. It used to sit
|
|
250
|
+
// after them, so the clean-project skip below swallowed it: on a tree with nothing modified, a
|
|
251
|
+
// generator change rewrote every tracked file and said nothing, which is the one run where this
|
|
252
|
+
// note is the only warning there is.
|
|
253
|
+
const driftNote = (0, base_snapshot_1.generatorDriftNote)({
|
|
254
|
+
snapshotVersion: snapshot.generatorVersion,
|
|
255
|
+
currentVersion: (0, base_snapshot_1.resolveGeneratorVersion)(targetPath),
|
|
256
|
+
});
|
|
257
|
+
if (driftNote) {
|
|
258
|
+
console.log((0, utils_1.yellow)(driftNote));
|
|
259
|
+
}
|
|
243
260
|
// The base is only ever consulted to merge files that were edited on disk.
|
|
244
|
-
// When nothing is
|
|
261
|
+
// When nothing is modified, reconstructing it (a second full generation +
|
|
245
262
|
// lint + format) would be wasted work, so skip it — the common, clean-project
|
|
246
263
|
// case pays nothing.
|
|
247
264
|
if (!(await (0, base_snapshot_1.hasLocallyEditedFiles)(targetPath))) {
|
|
@@ -251,13 +268,6 @@ async function maybeReconstructBaseVfs(params) {
|
|
|
251
268
|
if (!parsed.success) {
|
|
252
269
|
return undefined;
|
|
253
270
|
}
|
|
254
|
-
const currentGeneratorVersion = (0, base_snapshot_1.resolveGeneratorVersion)();
|
|
255
|
-
if (snapshot.generatorVersion !== 'unknown' &&
|
|
256
|
-
currentGeneratorVersion !== 'unknown' &&
|
|
257
|
-
snapshot.generatorVersion !== currentGeneratorVersion) {
|
|
258
|
-
console.log((0, utils_1.yellow)(`Note: @postxl/generators changed since the last generation (${snapshot.generatorVersion} → ${currentGeneratorVersion}). ` +
|
|
259
|
-
`Any ejected file whose generated output changed with it has no reproducible ancestor and falls back to a 2-way merge.`));
|
|
260
|
-
}
|
|
261
271
|
try {
|
|
262
272
|
const baseContext = (0, generator_1.prepareBaseContext)(parsed.data, {
|
|
263
273
|
...options,
|
|
@@ -8,19 +8,43 @@ export declare function writeBaseSnapshot(targetPath: string, snapshot: BaseSnap
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns true if any tracked generated file has been edited on disk (its content
|
|
10
10
|
* no longer matches its lock-file checksum) — i.e. the project has at least one
|
|
11
|
-
* "
|
|
11
|
+
* "modified" file that a regeneration could need to merge.
|
|
12
12
|
*
|
|
13
13
|
* The three-way merge base is only ever consulted for such files (the
|
|
14
14
|
* `MergeConflict` sync state requires a disk file that diverges from both the
|
|
15
15
|
* lock and the fresh output). When nothing is edited on disk, reconstructing the
|
|
16
16
|
* base would be pure wasted work, so the caller can skip the second generation
|
|
17
|
-
* pass entirely.
|
|
17
|
+
* pass entirely. Ejected entries (the `"ejected"` sentinel) are
|
|
18
18
|
* skipped because sync never merges them.
|
|
19
19
|
*/
|
|
20
20
|
export declare function hasLocallyEditedFiles(targetPath: string): Promise<boolean>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* The warning to print when the generator itself changed since the last generation, or
|
|
23
|
+
* `undefined` when it did not (or when either side is unrecorded — drift detection is advisory,
|
|
24
|
+
* so an unknown version is never reported as a change).
|
|
25
|
+
*
|
|
26
|
+
* Takes only the two versions, deliberately. This says something about the *generator*, not about
|
|
27
|
+
* the merge, so it must not be reachable only on runs that reconstruct a base: a clean project
|
|
28
|
+
* skips reconstruction as wasted work, and that is precisely the run where a generator change
|
|
29
|
+
* rewrites every tracked file with nothing else to signal it. Callers print it before any of the
|
|
30
|
+
* checks that decide whether a base is worth rebuilding.
|
|
31
|
+
*/
|
|
32
|
+
export declare function generatorDriftNote(params: {
|
|
33
|
+
snapshotVersion: string;
|
|
34
|
+
currentVersion: string;
|
|
35
|
+
}): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Best-effort read of the `@postxl/generators` version that will actually generate, used to
|
|
38
|
+
* detect generator drift between the snapshot and the current run. Falls back to `'unknown'`
|
|
39
|
+
* if it cannot be resolved (drift detection is advisory only).
|
|
40
|
+
*
|
|
41
|
+
* Resolved from `targetPath`, not from this file. The CLI never imports `@postxl/generators`
|
|
42
|
+
* itself — the project's `generate.ts` does, and that is compiled to `<project>/dist/generate.js`
|
|
43
|
+
* and imported from there, so the copy under the *project* is the one whose output lands on disk.
|
|
44
|
+
* A consumer's lockfile may also nest an older copy under `@postxl/cli`; resolving from here would
|
|
45
|
+
* report that one, which generates nothing. Worse, it would be reported on both sides of the drift
|
|
46
|
+
* comparison, so a genuine generator change between two runs would compare equal and the warning
|
|
47
|
+
* would never fire. Falls back to this file's resolution when the project has no copy of its own,
|
|
48
|
+
* which keeps the monorepo and any workspace-linked setup working as before.
|
|
25
49
|
*/
|
|
26
|
-
export declare function resolveGeneratorVersion(): string;
|
|
50
|
+
export declare function resolveGeneratorVersion(targetPath?: string): string;
|
|
@@ -37,6 +37,7 @@ exports.baseSnapshotPath = baseSnapshotPath;
|
|
|
37
37
|
exports.readBaseSnapshot = readBaseSnapshot;
|
|
38
38
|
exports.writeBaseSnapshot = writeBaseSnapshot;
|
|
39
39
|
exports.hasLocallyEditedFiles = hasLocallyEditedFiles;
|
|
40
|
+
exports.generatorDriftNote = generatorDriftNote;
|
|
40
41
|
exports.resolveGeneratorVersion = resolveGeneratorVersion;
|
|
41
42
|
/**
|
|
42
43
|
* Base-snapshot management for the generator's three-way (diff3) merge.
|
|
@@ -91,13 +92,13 @@ async function writeBaseSnapshot(targetPath, snapshot) {
|
|
|
91
92
|
/**
|
|
92
93
|
* Returns true if any tracked generated file has been edited on disk (its content
|
|
93
94
|
* no longer matches its lock-file checksum) — i.e. the project has at least one
|
|
94
|
-
* "
|
|
95
|
+
* "modified" file that a regeneration could need to merge.
|
|
95
96
|
*
|
|
96
97
|
* The three-way merge base is only ever consulted for such files (the
|
|
97
98
|
* `MergeConflict` sync state requires a disk file that diverges from both the
|
|
98
99
|
* lock and the fresh output). When nothing is edited on disk, reconstructing the
|
|
99
100
|
* base would be pure wasted work, so the caller can skip the second generation
|
|
100
|
-
* pass entirely.
|
|
101
|
+
* pass entirely. Ejected entries (the `"ejected"` sentinel) are
|
|
101
102
|
* skipped because sync never merges them.
|
|
102
103
|
*/
|
|
103
104
|
async function hasLocallyEditedFiles(targetPath) {
|
|
@@ -131,17 +132,52 @@ async function hasLocallyEditedFiles(targetPath) {
|
|
|
131
132
|
return false;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
135
|
+
* The warning to print when the generator itself changed since the last generation, or
|
|
136
|
+
* `undefined` when it did not (or when either side is unrecorded — drift detection is advisory,
|
|
137
|
+
* so an unknown version is never reported as a change).
|
|
138
|
+
*
|
|
139
|
+
* Takes only the two versions, deliberately. This says something about the *generator*, not about
|
|
140
|
+
* the merge, so it must not be reachable only on runs that reconstruct a base: a clean project
|
|
141
|
+
* skips reconstruction as wasted work, and that is precisely the run where a generator change
|
|
142
|
+
* rewrites every tracked file with nothing else to signal it. Callers print it before any of the
|
|
143
|
+
* checks that decide whether a base is worth rebuilding.
|
|
137
144
|
*/
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return pkg.version ?? 'unknown';
|
|
145
|
+
function generatorDriftNote(params) {
|
|
146
|
+
const { snapshotVersion, currentVersion } = params;
|
|
147
|
+
if (snapshotVersion === 'unknown' || currentVersion === 'unknown' || snapshotVersion === currentVersion) {
|
|
148
|
+
return undefined;
|
|
143
149
|
}
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
return (`Note: @postxl/generators changed since the last generation (${snapshotVersion} → ${currentVersion}). ` +
|
|
151
|
+
`Files it generates differently will be rewritten; any modified file whose output changed with it ` +
|
|
152
|
+
`has no reproducible ancestor and falls back to a 2-way merge.`);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Best-effort read of the `@postxl/generators` version that will actually generate, used to
|
|
156
|
+
* detect generator drift between the snapshot and the current run. Falls back to `'unknown'`
|
|
157
|
+
* if it cannot be resolved (drift detection is advisory only).
|
|
158
|
+
*
|
|
159
|
+
* Resolved from `targetPath`, not from this file. The CLI never imports `@postxl/generators`
|
|
160
|
+
* itself — the project's `generate.ts` does, and that is compiled to `<project>/dist/generate.js`
|
|
161
|
+
* and imported from there, so the copy under the *project* is the one whose output lands on disk.
|
|
162
|
+
* A consumer's lockfile may also nest an older copy under `@postxl/cli`; resolving from here would
|
|
163
|
+
* report that one, which generates nothing. Worse, it would be reported on both sides of the drift
|
|
164
|
+
* comparison, so a genuine generator change between two runs would compare equal and the warning
|
|
165
|
+
* would never fire. Falls back to this file's resolution when the project has no copy of its own,
|
|
166
|
+
* which keeps the monorepo and any workspace-linked setup working as before.
|
|
167
|
+
*/
|
|
168
|
+
function resolveGeneratorVersion(targetPath) {
|
|
169
|
+
const bases = targetPath ? [path.resolve(targetPath, 'noop.js'), __filename] : [__filename];
|
|
170
|
+
for (const base of bases) {
|
|
171
|
+
try {
|
|
172
|
+
const require = (0, node_module_1.createRequire)(base);
|
|
173
|
+
const pkg = require('@postxl/generators/package.json');
|
|
174
|
+
if (pkg.version) {
|
|
175
|
+
return pkg.version;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Not resolvable from this base — try the next one.
|
|
180
|
+
}
|
|
146
181
|
}
|
|
182
|
+
return 'unknown';
|
|
147
183
|
}
|
|
@@ -94,6 +94,13 @@ exports.GENERATOR_REGISTRY = [
|
|
|
94
94
|
importFrom: '@postxl/generators',
|
|
95
95
|
defaultOptions: () => `{ useDatabase: true, keycloakComponents: [], useS3: false, useBitbucket: false }`,
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
kind: 'configure',
|
|
99
|
+
name: 'skailify',
|
|
100
|
+
configureFn: 'configureSkailifyGenerator',
|
|
101
|
+
importFrom: '@postxl/generators',
|
|
102
|
+
defaultOptions: () => `{}`,
|
|
103
|
+
},
|
|
97
104
|
];
|
|
98
105
|
/**
|
|
99
106
|
* Reverse mapping: a top-level call expression in `generate.ts` is matched
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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,9 +45,9 @@
|
|
|
45
45
|
"dotenv": "17.4.2",
|
|
46
46
|
"ts-morph": "26.0.0",
|
|
47
47
|
"zod-validation-error": "5.0.0",
|
|
48
|
-
"@postxl/generator": "^1.
|
|
49
|
-
"@postxl/generators": "^3.
|
|
50
|
-
"@postxl/schema": "^2.
|
|
48
|
+
"@postxl/generator": "^1.8.0",
|
|
49
|
+
"@postxl/generators": "^3.2.1",
|
|
50
|
+
"@postxl/schema": "^2.3.0",
|
|
51
51
|
"@postxl/utils": "^1.4.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {},
|