@wp-typia/project-tools 0.16.12 → 0.16.14
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/README.md +0 -1
- package/dist/runtime/block-generator-service-core.d.ts +8 -0
- package/dist/runtime/block-generator-service-core.js +274 -0
- package/dist/runtime/block-generator-service-spec.d.ts +104 -0
- package/dist/runtime/block-generator-service-spec.js +139 -0
- package/dist/runtime/block-generator-service.d.ts +2 -110
- package/dist/runtime/block-generator-service.js +2 -389
- package/dist/runtime/cli-diagnostics.js +76 -4
- package/dist/runtime/cli-doctor-workspace.d.ts +9 -5
- package/dist/runtime/cli-doctor-workspace.js +18 -6
- package/dist/runtime/cli-help.js +1 -1
- package/dist/runtime/cli-prompt.js +78 -19
- package/dist/runtime/cli-scaffold.d.ts +8 -1
- package/dist/runtime/cli-scaffold.js +47 -4
- package/dist/runtime/migration-maintenance-fixtures.d.ts +23 -0
- package/dist/runtime/migration-maintenance-fixtures.js +126 -0
- package/dist/runtime/migration-maintenance-verify.d.ts +26 -0
- package/dist/runtime/migration-maintenance-verify.js +262 -0
- package/dist/runtime/migration-maintenance.d.ts +2 -51
- package/dist/runtime/migration-maintenance.js +2 -380
- package/dist/runtime/migrations.d.ts +0 -3
- package/dist/runtime/scaffold-answer-resolution.d.ts +37 -0
- package/dist/runtime/scaffold-answer-resolution.js +138 -0
- package/dist/runtime/scaffold-apply-utils.d.ts +1 -7
- package/dist/runtime/scaffold-apply-utils.js +4 -105
- package/dist/runtime/scaffold-documents.d.ts +34 -0
- package/dist/runtime/scaffold-documents.js +144 -0
- package/dist/runtime/scaffold-onboarding.d.ts +12 -0
- package/dist/runtime/scaffold-onboarding.js +42 -5
- package/dist/runtime/scaffold-template-variables.d.ts +9 -0
- package/dist/runtime/scaffold-template-variables.js +111 -0
- package/dist/runtime/scaffold.d.ts +11 -9
- package/dist/runtime/scaffold.js +6 -202
- package/package.json +3 -3
|
@@ -1,380 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { execFileSync } from 'node:child_process';
|
|
4
|
-
import { ROOT_PHP_MIGRATION_REGISTRY, } from './migration-constants.js';
|
|
5
|
-
import { createMigrationDiff } from './migration-diff.js';
|
|
6
|
-
import { createEdgeFixtureDocument, ensureEdgeFixtureFile, } from './migration-fixtures.js';
|
|
7
|
-
import { collectGeneratedMigrationEntries, } from './migration-generated-artifacts.js';
|
|
8
|
-
import { collectFixtureTargets, formatScaffoldCommand, getSelectedEntriesByBlock, hasSnapshotForVersion, isLegacySingleBlockProject, isSnapshotOptionalForBlockVersion, resolveLegacyVersions, } from './migration-planning.js';
|
|
9
|
-
import { assertRuleHasNoTodos, getFixtureFilePath, getGeneratedDirForBlock, getRuleFilePath, getSnapshotBlockJsonPath, getSnapshotManifestPath, getSnapshotRoot, getSnapshotSavePath, loadMigrationProject, readRuleMetadata, } from './migration-project.js';
|
|
10
|
-
import { renderFuzzFile, renderGeneratedDeprecatedFile, renderGeneratedMigrationIndexFile, renderMigrationRegistryFile, renderPhpMigrationRegistryFile, renderVerifyFile, } from './migration-render.js';
|
|
11
|
-
import { createMigrationRiskSummary, formatMigrationRiskSummary, } from './migration-risk.js';
|
|
12
|
-
import { getLocalTsxBinary, isInteractiveTerminal, readJson, resolveTargetMigrationVersion, } from './migration-utils.js';
|
|
13
|
-
import { readWorkspaceInventory } from './workspace-inventory.js';
|
|
14
|
-
import { getInvalidWorkspaceProjectReason, tryResolveWorkspaceProject, } from './workspace-project.js';
|
|
15
|
-
/**
|
|
16
|
-
* Run deterministic migration verification against generated fixtures.
|
|
17
|
-
*
|
|
18
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
19
|
-
* @param options Verification scope and console rendering options.
|
|
20
|
-
* @returns Verified legacy versions.
|
|
21
|
-
*/
|
|
22
|
-
export function verifyProjectMigrations(projectDir, { all = false, fromMigrationVersion, renderLine = console.log, } = {}) {
|
|
23
|
-
const state = loadMigrationProject(projectDir);
|
|
24
|
-
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
25
|
-
const blockEntries = getSelectedEntriesByBlock(state, targetVersions, 'verify');
|
|
26
|
-
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
27
|
-
if (targetVersions.length === 0) {
|
|
28
|
-
renderLine('No legacy migration versions configured for verification.');
|
|
29
|
-
return { verifiedVersions: [] };
|
|
30
|
-
}
|
|
31
|
-
const tsxBinary = getLocalTsxBinary(projectDir);
|
|
32
|
-
for (const [blockKey, entries] of Object.entries(blockEntries)) {
|
|
33
|
-
const block = state.blocks.find((entry) => entry.key === blockKey);
|
|
34
|
-
if (!block || entries.length === 0) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
assertRuleHasNoTodos(projectDir, block, entry.fromVersion, state.config.currentMigrationVersion);
|
|
39
|
-
}
|
|
40
|
-
const verifyScriptPath = path.join(getGeneratedDirForBlock(state.paths, block), 'verify.ts');
|
|
41
|
-
if (!fs.existsSync(verifyScriptPath)) {
|
|
42
|
-
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
43
|
-
throw new Error(`Generated verify script is missing for ${block.blockName} (${selectedVersionsForBlock.join(', ')}). ` +
|
|
44
|
-
`Run \`${formatScaffoldCommand(selectedVersionsForBlock)}\` first, then \`wp-typia migrate doctor --all\` if the workspace should already be scaffolded.`);
|
|
45
|
-
}
|
|
46
|
-
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
47
|
-
const filteredArgs = all
|
|
48
|
-
? ['--all']
|
|
49
|
-
: ['--from-migration-version', selectedVersionsForBlock[0]];
|
|
50
|
-
execFileSync(tsxBinary, [verifyScriptPath, ...filteredArgs], {
|
|
51
|
-
cwd: projectDir,
|
|
52
|
-
shell: process.platform === 'win32',
|
|
53
|
-
stdio: 'inherit',
|
|
54
|
-
});
|
|
55
|
-
renderLine(legacySingleBlock
|
|
56
|
-
? `Verified migrations for ${selectedVersionsForBlock.join(', ')}`
|
|
57
|
-
: `Verified ${block.blockName} migrations for ${selectedVersionsForBlock.join(', ')}`);
|
|
58
|
-
}
|
|
59
|
-
return { verifiedVersions: targetVersions };
|
|
60
|
-
}
|
|
61
|
-
function recordWorkspaceMigrationTargetAlignment(projectDir, state, recordCheck) {
|
|
62
|
-
let invalidWorkspaceReason = null;
|
|
63
|
-
let workspace;
|
|
64
|
-
try {
|
|
65
|
-
invalidWorkspaceReason = getInvalidWorkspaceProjectReason(projectDir);
|
|
66
|
-
workspace = tryResolveWorkspaceProject(projectDir);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
recordCheck('fail', 'Workspace migration targets', error instanceof Error ? error.message : String(error));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (!workspace) {
|
|
73
|
-
if (invalidWorkspaceReason) {
|
|
74
|
-
recordCheck('fail', 'Workspace migration targets', invalidWorkspaceReason);
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
80
|
-
const expectedTargets = inventory.blocks.map((block) => `${workspace.workspace.namespace}/${block.slug}`);
|
|
81
|
-
const configuredTargets = state.blocks.map((block) => block.blockName);
|
|
82
|
-
const expectedTargetSet = new Set(expectedTargets);
|
|
83
|
-
const configuredTargetSet = new Set(configuredTargets);
|
|
84
|
-
const missingTargets = expectedTargets.filter((target) => !configuredTargetSet.has(target));
|
|
85
|
-
const staleTargets = configuredTargets.filter((target) => !expectedTargetSet.has(target));
|
|
86
|
-
recordCheck(missingTargets.length === 0 && staleTargets.length === 0 ? 'pass' : 'fail', 'Workspace migration targets', missingTargets.length === 0 && staleTargets.length === 0
|
|
87
|
-
? `${expectedTargets.length} workspace block target(s) align with migration config`
|
|
88
|
-
: [
|
|
89
|
-
missingTargets.length > 0
|
|
90
|
-
? `Missing from migration config: ${missingTargets.join(', ')}`
|
|
91
|
-
: null,
|
|
92
|
-
staleTargets.length > 0
|
|
93
|
-
? `Not present in scripts/block-config.ts: ${staleTargets.join(', ')}`
|
|
94
|
-
: null,
|
|
95
|
-
]
|
|
96
|
-
.filter((detail) => typeof detail === 'string')
|
|
97
|
-
.join('; '));
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
recordCheck('fail', 'Workspace migration targets', error instanceof Error ? error.message : String(error));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Validate the migration workspace without mutating files.
|
|
105
|
-
*
|
|
106
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
107
|
-
* @param options Doctor scope and console rendering options.
|
|
108
|
-
* @returns Structured doctor check results for the selected legacy versions.
|
|
109
|
-
*/
|
|
110
|
-
export function doctorProjectMigrations(projectDir, { all = false, fromMigrationVersion, renderLine = console.log, } = {}) {
|
|
111
|
-
const checks = [];
|
|
112
|
-
const recordCheck = (status, label, detail) => {
|
|
113
|
-
checks.push({ detail, label, status });
|
|
114
|
-
renderLine(`${status === 'pass' ? 'PASS' : 'FAIL'} ${label}: ${detail}`);
|
|
115
|
-
};
|
|
116
|
-
let state;
|
|
117
|
-
try {
|
|
118
|
-
state = loadMigrationProject(projectDir);
|
|
119
|
-
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
120
|
-
recordCheck('pass', 'Migration config', legacySingleBlock
|
|
121
|
-
? `Loaded ${state.blocks[0]?.blockName} @ ${state.config.currentMigrationVersion}`
|
|
122
|
-
: `Loaded ${state.blocks.length} block target(s) @ ${state.config.currentMigrationVersion}`);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
recordCheck('fail', 'Migration config', error instanceof Error ? error.message : String(error));
|
|
126
|
-
throw new Error('Migration doctor failed.');
|
|
127
|
-
}
|
|
128
|
-
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
129
|
-
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
130
|
-
const snapshotVersions = new Set(targetVersions.length > 0
|
|
131
|
-
? [state.config.currentMigrationVersion, ...targetVersions]
|
|
132
|
-
: state.config.supportedMigrationVersions);
|
|
133
|
-
recordWorkspaceMigrationTargetAlignment(projectDir, state, recordCheck);
|
|
134
|
-
for (const version of snapshotVersions) {
|
|
135
|
-
for (const block of state.blocks) {
|
|
136
|
-
const snapshotRoot = getSnapshotRoot(projectDir, block, version);
|
|
137
|
-
const blockJsonPath = getSnapshotBlockJsonPath(projectDir, block, version);
|
|
138
|
-
const manifestPath = getSnapshotManifestPath(projectDir, block, version);
|
|
139
|
-
const savePath = getSnapshotSavePath(projectDir, block, version);
|
|
140
|
-
const hasSnapshot = fs.existsSync(snapshotRoot);
|
|
141
|
-
const snapshotIsOptional = !hasSnapshot && isSnapshotOptionalForBlockVersion(state, block, version);
|
|
142
|
-
recordCheck(hasSnapshot || snapshotIsOptional ? 'pass' : 'fail', legacySingleBlock ? `Snapshot ${version}` : `Snapshot ${block.blockName} @ ${version}`, hasSnapshot
|
|
143
|
-
? path.relative(projectDir, snapshotRoot)
|
|
144
|
-
: 'Not present for this version');
|
|
145
|
-
if (!hasSnapshot) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
for (const targetPath of [blockJsonPath, manifestPath, savePath]) {
|
|
149
|
-
recordCheck(fs.existsSync(targetPath) ? 'pass' : 'fail', legacySingleBlock
|
|
150
|
-
? `Snapshot file ${version}`
|
|
151
|
-
: `Snapshot file ${block.blockName} @ ${version}`, fs.existsSync(targetPath)
|
|
152
|
-
? path.relative(projectDir, targetPath)
|
|
153
|
-
: `Missing ${path.relative(projectDir, targetPath)}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
158
|
-
const generatedEntries = collectGeneratedMigrationEntries(state);
|
|
159
|
-
const expectedGeneratedFiles = new Map();
|
|
160
|
-
for (const block of state.blocks) {
|
|
161
|
-
const blockGeneratedEntries = generatedEntries.filter(({ entry }) => entry.block.key === block.key);
|
|
162
|
-
const entries = blockGeneratedEntries.map(({ entry }) => entry);
|
|
163
|
-
const generatedDir = getGeneratedDirForBlock(state.paths, block);
|
|
164
|
-
expectedGeneratedFiles.set(path.join(generatedDir, 'registry.ts'), renderMigrationRegistryFile(state, block.key, blockGeneratedEntries));
|
|
165
|
-
expectedGeneratedFiles.set(path.join(generatedDir, 'deprecated.ts'), renderGeneratedDeprecatedFile(state, block.key, entries));
|
|
166
|
-
expectedGeneratedFiles.set(path.join(generatedDir, 'verify.ts'), renderVerifyFile(state, block.key, entries));
|
|
167
|
-
expectedGeneratedFiles.set(path.join(generatedDir, 'fuzz.ts'), renderFuzzFile(state, block.key, blockGeneratedEntries));
|
|
168
|
-
}
|
|
169
|
-
expectedGeneratedFiles.set(path.join(state.paths.generatedDir, 'index.ts'), renderGeneratedMigrationIndexFile(state, generatedEntries.map(({ entry }) => entry)));
|
|
170
|
-
expectedGeneratedFiles.set(path.join(projectDir, ROOT_PHP_MIGRATION_REGISTRY), renderPhpMigrationRegistryFile(state, generatedEntries.map(({ entry }) => entry)));
|
|
171
|
-
for (const [filePath, expectedSource] of expectedGeneratedFiles) {
|
|
172
|
-
const inSync = fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf8') === expectedSource;
|
|
173
|
-
recordCheck(inSync ? 'pass' : 'fail', `Generated ${path.relative(projectDir, filePath)}`, inSync
|
|
174
|
-
? 'In sync'
|
|
175
|
-
: 'Run `wp-typia migrate scaffold --from-migration-version <label>` or regenerate artifacts');
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
recordCheck('fail', 'Generated artifacts', error instanceof Error ? error.message : String(error));
|
|
180
|
-
}
|
|
181
|
-
for (const version of targetVersions) {
|
|
182
|
-
for (const block of state.blocks) {
|
|
183
|
-
if (!hasSnapshotForVersion(state, block, version)) {
|
|
184
|
-
recordCheck('pass', `Snapshot coverage ${block.blockName} @ ${version}`, 'Target not present for this version');
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const rulePath = getRuleFilePath(state.paths, block, version, state.config.currentMigrationVersion);
|
|
188
|
-
const fixturePath = getFixtureFilePath(state.paths, block, version, state.config.currentMigrationVersion);
|
|
189
|
-
recordCheck(fs.existsSync(rulePath) ? 'pass' : 'fail', legacySingleBlock ? `Rule ${version}` : `Rule ${block.blockName} @ ${version}`, fs.existsSync(rulePath)
|
|
190
|
-
? path.relative(projectDir, rulePath)
|
|
191
|
-
: `Missing ${path.relative(projectDir, rulePath)}`);
|
|
192
|
-
recordCheck(fs.existsSync(fixturePath) ? 'pass' : 'fail', legacySingleBlock ? `Fixture ${version}` : `Fixture ${block.blockName} @ ${version}`, fs.existsSync(fixturePath)
|
|
193
|
-
? path.relative(projectDir, fixturePath)
|
|
194
|
-
: `Missing ${path.relative(projectDir, fixturePath)}`);
|
|
195
|
-
if (!fs.existsSync(rulePath) || !fs.existsSync(fixturePath)) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
assertRuleHasNoTodos(projectDir, block, version, state.config.currentMigrationVersion);
|
|
200
|
-
recordCheck('pass', legacySingleBlock
|
|
201
|
-
? `Rule TODOs ${version}`
|
|
202
|
-
: `Rule TODOs ${block.blockName} @ ${version}`, 'No TODO MIGRATION markers remain');
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
recordCheck('fail', legacySingleBlock
|
|
206
|
-
? `Rule TODOs ${version}`
|
|
207
|
-
: `Rule TODOs ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
208
|
-
}
|
|
209
|
-
try {
|
|
210
|
-
const ruleMetadata = readRuleMetadata(rulePath);
|
|
211
|
-
recordCheck(ruleMetadata.unresolved.length === 0 ? 'pass' : 'fail', legacySingleBlock
|
|
212
|
-
? `Rule unresolved ${version}`
|
|
213
|
-
: `Rule unresolved ${block.blockName} @ ${version}`, ruleMetadata.unresolved.length === 0
|
|
214
|
-
? 'No unresolved entries remain'
|
|
215
|
-
: ruleMetadata.unresolved.join(', '));
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
recordCheck('fail', legacySingleBlock
|
|
219
|
-
? `Rule unresolved ${version}`
|
|
220
|
-
: `Rule unresolved ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
const fixtureDocument = readJson(fixturePath);
|
|
224
|
-
recordCheck(Array.isArray(fixtureDocument.cases) && fixtureDocument.cases.length > 0
|
|
225
|
-
? 'pass'
|
|
226
|
-
: 'fail', legacySingleBlock
|
|
227
|
-
? `Fixture parse ${version}`
|
|
228
|
-
: `Fixture parse ${block.blockName} @ ${version}`, Array.isArray(fixtureDocument.cases) && fixtureDocument.cases.length > 0
|
|
229
|
-
? `${fixtureDocument.cases.length} case(s)`
|
|
230
|
-
: 'Fixture document has no cases');
|
|
231
|
-
const diff = createMigrationDiff(state, block, version, state.config.currentMigrationVersion);
|
|
232
|
-
const expectedFixture = createEdgeFixtureDocument(projectDir, block, version, state.config.currentMigrationVersion, diff);
|
|
233
|
-
const actualCaseNames = new Set((fixtureDocument.cases ?? []).map((fixtureCase) => fixtureCase.name));
|
|
234
|
-
const missingCases = expectedFixture.cases
|
|
235
|
-
.map((fixtureCase) => fixtureCase.name)
|
|
236
|
-
.filter((name) => !actualCaseNames.has(name));
|
|
237
|
-
recordCheck(missingCases.length === 0 ? 'pass' : 'fail', legacySingleBlock
|
|
238
|
-
? `Fixture coverage ${version}`
|
|
239
|
-
: `Fixture coverage ${block.blockName} @ ${version}`, missingCases.length === 0
|
|
240
|
-
? 'All expected fixture cases are present'
|
|
241
|
-
: `Missing ${missingCases.join(', ')}`);
|
|
242
|
-
recordCheck('pass', legacySingleBlock
|
|
243
|
-
? `Risk summary ${version}`
|
|
244
|
-
: `Risk summary ${block.blockName} @ ${version}`, formatMigrationRiskSummary(createMigrationRiskSummary(diff)));
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
recordCheck('fail', legacySingleBlock
|
|
248
|
-
? `Fixture parse ${version}`
|
|
249
|
-
: `Fixture parse ${block.blockName} @ ${version}`, error instanceof Error ? error.message : String(error));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const failedChecks = checks.filter((check) => check.status === 'fail');
|
|
254
|
-
renderLine(`${failedChecks.length === 0 ? 'PASS' : 'FAIL'} Migration doctor summary: ${checks.length - failedChecks.length}/${checks.length} checks passed`);
|
|
255
|
-
if (failedChecks.length > 0) {
|
|
256
|
-
throw new Error('Migration doctor failed.');
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
checkedVersions: targetVersions,
|
|
260
|
-
checks,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Generate or refresh migration fixtures for one or more legacy edges.
|
|
265
|
-
*
|
|
266
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
267
|
-
* @param options Fixture generation scope and refresh options.
|
|
268
|
-
* @returns Generated and skipped legacy versions.
|
|
269
|
-
*/
|
|
270
|
-
export function fixturesProjectMigrations(projectDir, { all = false, confirmOverwrite, force = false, fromMigrationVersion, isInteractive = isInteractiveTerminal(), renderLine = console.log, toMigrationVersion = 'current', } = {}) {
|
|
271
|
-
const state = loadMigrationProject(projectDir);
|
|
272
|
-
const targetMigrationVersion = resolveTargetMigrationVersion(state.config.currentMigrationVersion, toMigrationVersion);
|
|
273
|
-
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
274
|
-
if (targetVersions.length === 0) {
|
|
275
|
-
renderLine('No legacy migration versions configured for fixture generation.');
|
|
276
|
-
return { generatedVersions: [], skippedVersions: [] };
|
|
277
|
-
}
|
|
278
|
-
const generatedVersions = [];
|
|
279
|
-
const skippedVersions = [];
|
|
280
|
-
const fixtureTargets = collectFixtureTargets(state, targetVersions, targetMigrationVersion);
|
|
281
|
-
if (force) {
|
|
282
|
-
const overwriteTargets = fixtureTargets.filter(({ fixturePath }) => fs.existsSync(fixturePath));
|
|
283
|
-
if (isInteractive && overwriteTargets.length > 0) {
|
|
284
|
-
const confirmed = confirmOverwrite?.(`About to overwrite ${overwriteTargets.length} existing migration fixture file(s). Continue?`) ??
|
|
285
|
-
promptForConfirmation(`About to overwrite ${overwriteTargets.length} existing migration fixture file(s). Continue?`);
|
|
286
|
-
if (!confirmed) {
|
|
287
|
-
renderLine(`Cancelled fixture refresh. Kept ${overwriteTargets.length} existing fixture file(s).`);
|
|
288
|
-
return {
|
|
289
|
-
generatedVersions,
|
|
290
|
-
skippedVersions: overwriteTargets.map(({ scopedLabel }) => scopedLabel),
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
for (const { block, fixturePath, scopedLabel, version } of fixtureTargets) {
|
|
296
|
-
const existed = fs.existsSync(fixturePath);
|
|
297
|
-
const diff = createMigrationDiff(state, block, version, targetMigrationVersion);
|
|
298
|
-
const result = ensureEdgeFixtureFile(projectDir, block, version, targetMigrationVersion, diff, { force });
|
|
299
|
-
if (result.written) {
|
|
300
|
-
generatedVersions.push(scopedLabel);
|
|
301
|
-
renderLine(`${existed ? 'Refreshed' : 'Generated'} fixture ${path.relative(projectDir, fixturePath)}`);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
skippedVersions.push(scopedLabel);
|
|
305
|
-
renderLine(`Preserved existing fixture ${path.relative(projectDir, fixturePath)} (use --force to refresh)`);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
generatedVersions,
|
|
310
|
-
skippedVersions,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Run seeded migration fuzz verification against generated fuzz artifacts.
|
|
315
|
-
*
|
|
316
|
-
* @param projectDir Absolute or relative project directory containing the migration workspace.
|
|
317
|
-
* @param options Fuzz scope, iteration count, seed, and console rendering options.
|
|
318
|
-
* @returns Fuzzed legacy versions and the effective seed.
|
|
319
|
-
*/
|
|
320
|
-
export function fuzzProjectMigrations(projectDir, { all = false, fromMigrationVersion, iterations = 25, renderLine = console.log, seed, } = {}) {
|
|
321
|
-
const state = loadMigrationProject(projectDir);
|
|
322
|
-
const targetVersions = resolveLegacyVersions(state, { all, fromMigrationVersion });
|
|
323
|
-
const blockEntries = getSelectedEntriesByBlock(state, targetVersions, 'fuzz');
|
|
324
|
-
const legacySingleBlock = isLegacySingleBlockProject(state);
|
|
325
|
-
if (targetVersions.length === 0) {
|
|
326
|
-
renderLine('No legacy migration versions configured for fuzzing.');
|
|
327
|
-
return { fuzzedVersions: [] };
|
|
328
|
-
}
|
|
329
|
-
const tsxBinary = getLocalTsxBinary(projectDir);
|
|
330
|
-
for (const [blockKey, entries] of Object.entries(blockEntries)) {
|
|
331
|
-
const block = state.blocks.find((entry) => entry.key === blockKey);
|
|
332
|
-
if (!block || entries.length === 0) {
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
for (const entry of entries) {
|
|
336
|
-
assertRuleHasNoTodos(projectDir, block, entry.fromVersion, state.config.currentMigrationVersion);
|
|
337
|
-
}
|
|
338
|
-
const fuzzScriptPath = path.join(getGeneratedDirForBlock(state.paths, block), 'fuzz.ts');
|
|
339
|
-
if (!fs.existsSync(fuzzScriptPath)) {
|
|
340
|
-
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
341
|
-
throw new Error(`Generated fuzz script is missing for ${block.blockName} (${selectedVersionsForBlock.join(', ')}). ` +
|
|
342
|
-
`Run \`${formatScaffoldCommand(selectedVersionsForBlock)}\` first, then \`wp-typia migrate doctor --all\` if the workspace should already be scaffolded.`);
|
|
343
|
-
}
|
|
344
|
-
const selectedVersionsForBlock = entries.map((entry) => entry.fromVersion);
|
|
345
|
-
const args = [
|
|
346
|
-
fuzzScriptPath,
|
|
347
|
-
...(all ? ['--all'] : ['--from-migration-version', selectedVersionsForBlock[0]]),
|
|
348
|
-
'--iterations',
|
|
349
|
-
String(iterations),
|
|
350
|
-
...(seed === undefined ? [] : ['--seed', String(seed)]),
|
|
351
|
-
];
|
|
352
|
-
execFileSync(tsxBinary, args, {
|
|
353
|
-
cwd: projectDir,
|
|
354
|
-
shell: process.platform === 'win32',
|
|
355
|
-
stdio: 'inherit',
|
|
356
|
-
});
|
|
357
|
-
renderLine(legacySingleBlock
|
|
358
|
-
? `Fuzzed migrations for ${selectedVersionsForBlock.join(', ')}`
|
|
359
|
-
: `Fuzzed ${block.blockName} migrations for ${selectedVersionsForBlock.join(', ')}`);
|
|
360
|
-
}
|
|
361
|
-
return { fuzzedVersions: targetVersions, seed };
|
|
362
|
-
}
|
|
363
|
-
function promptForConfirmation(message) {
|
|
364
|
-
process.stdout.write(`${message} [y/N]: `);
|
|
365
|
-
const buffer = Buffer.alloc(1);
|
|
366
|
-
let answer = '';
|
|
367
|
-
while (true) {
|
|
368
|
-
const bytesRead = fs.readSync(process.stdin.fd, buffer, 0, 1, null);
|
|
369
|
-
if (bytesRead === 0) {
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
const char = buffer.toString('utf8', 0, bytesRead);
|
|
373
|
-
if (char === '\n' || char === '\r') {
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
answer += char;
|
|
377
|
-
}
|
|
378
|
-
const normalized = answer.trim().toLowerCase();
|
|
379
|
-
return normalized === 'y' || normalized === 'yes';
|
|
380
|
-
}
|
|
1
|
+
export * from './migration-maintenance-verify.js';
|
|
2
|
+
export * from './migration-maintenance-fixtures.js';
|
|
@@ -45,9 +45,6 @@ export declare function runMigrationCommand(command: ParsedMigrationArgs, cwd: s
|
|
|
45
45
|
} | {
|
|
46
46
|
generatedVersions: string[];
|
|
47
47
|
skippedVersions: string[];
|
|
48
|
-
} | {
|
|
49
|
-
fuzzedVersions: never[];
|
|
50
|
-
seed?: undefined;
|
|
51
48
|
} | {
|
|
52
49
|
fuzzedVersions: string[];
|
|
53
50
|
seed: number | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PackageManagerId } from './package-managers.js';
|
|
2
|
+
import type { CollectScaffoldAnswersOptions, ResolvePackageManagerOptions, ResolveTemplateOptions, ScaffoldAnswers } from './scaffold.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detect the current author name from local Git config.
|
|
5
|
+
*
|
|
6
|
+
* @returns The configured Git author name, or `"Your Name"` when unavailable.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectAuthor(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Compute the default scaffold answers for one project and template pair.
|
|
11
|
+
*
|
|
12
|
+
* @param projectName User-supplied project directory or block name seed.
|
|
13
|
+
* @param templateId Selected scaffold template identifier.
|
|
14
|
+
* @returns Normalized default answers for scaffold prompts and non-interactive flows.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDefaultAnswers(projectName: string, templateId: string): ScaffoldAnswers;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the scaffold template id from flags, defaults, and interactive selection.
|
|
19
|
+
*
|
|
20
|
+
* @param options Template resolution options for interactive and non-interactive flows.
|
|
21
|
+
* @returns The normalized template identifier to scaffold.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveTemplateId({ templateId, yes, isInteractive, selectTemplate, }: ResolveTemplateOptions): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the package manager id from flags, defaults, and interactive selection.
|
|
26
|
+
*
|
|
27
|
+
* @param options Package manager resolution options for interactive and non-interactive flows.
|
|
28
|
+
* @returns The normalized package manager id.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolvePackageManagerId({ packageManager, yes, isInteractive, selectPackageManager, }: ResolvePackageManagerOptions): Promise<PackageManagerId>;
|
|
31
|
+
/**
|
|
32
|
+
* Collect scaffold answers from defaults, CLI overrides, and optional prompts.
|
|
33
|
+
*
|
|
34
|
+
* @param options Answer collection inputs including prompt callbacks and explicit overrides.
|
|
35
|
+
* @returns The normalized scaffold answers used for rendering and file generation.
|
|
36
|
+
*/
|
|
37
|
+
export declare function collectScaffoldAnswers({ projectName, templateId, yes, dataStorageMode, namespace, persistencePolicy, phpPrefix, promptText, textDomain, }: CollectScaffoldAnswersOptions): Promise<ScaffoldAnswers>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { PACKAGE_MANAGER_IDS, getPackageManager, } from './package-managers.js';
|
|
2
|
+
import { normalizeBlockSlug, resolveScaffoldIdentifiers, validateBlockSlug, validateNamespace, } from './scaffold-identifiers.js';
|
|
3
|
+
import { OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE, TEMPLATE_IDS, getTemplateById, isBuiltInTemplateId, } from './template-registry.js';
|
|
4
|
+
import { getRemovedBuiltInTemplateMessage, isRemovedBuiltInTemplateId, } from './template-defaults.js';
|
|
5
|
+
import { toSnakeCase, toTitleCase, } from './string-case.js';
|
|
6
|
+
const WORKSPACE_TEMPLATE_ALIAS = 'workspace';
|
|
7
|
+
/**
|
|
8
|
+
* Detect the current author name from local Git config.
|
|
9
|
+
*
|
|
10
|
+
* @returns The configured Git author name, or `"Your Name"` when unavailable.
|
|
11
|
+
*/
|
|
12
|
+
export function detectAuthor() {
|
|
13
|
+
try {
|
|
14
|
+
return (execSync('git config user.name', {
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
17
|
+
}).trim() || 'Your Name');
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return 'Your Name';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compute the default scaffold answers for one project and template pair.
|
|
25
|
+
*
|
|
26
|
+
* @param projectName User-supplied project directory or block name seed.
|
|
27
|
+
* @param templateId Selected scaffold template identifier.
|
|
28
|
+
* @returns Normalized default answers for scaffold prompts and non-interactive flows.
|
|
29
|
+
*/
|
|
30
|
+
export function getDefaultAnswers(projectName, templateId) {
|
|
31
|
+
const template = isBuiltInTemplateId(templateId) ? getTemplateById(templateId) : null;
|
|
32
|
+
const slugDefault = normalizeBlockSlug(projectName) || 'my-wp-typia-block';
|
|
33
|
+
return {
|
|
34
|
+
author: detectAuthor(),
|
|
35
|
+
dataStorageMode: templateId === 'persistence' ? 'custom-table' : undefined,
|
|
36
|
+
description: template?.description ?? 'A WordPress block scaffolded from a remote template',
|
|
37
|
+
namespace: slugDefault,
|
|
38
|
+
persistencePolicy: templateId === 'persistence' ? 'authenticated' : undefined,
|
|
39
|
+
phpPrefix: toSnakeCase(slugDefault),
|
|
40
|
+
slug: slugDefault,
|
|
41
|
+
textDomain: slugDefault,
|
|
42
|
+
title: toTitleCase(slugDefault),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function normalizeTemplateSelection(templateId) {
|
|
46
|
+
return templateId === WORKSPACE_TEMPLATE_ALIAS
|
|
47
|
+
? OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE
|
|
48
|
+
: templateId;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the scaffold template id from flags, defaults, and interactive selection.
|
|
52
|
+
*
|
|
53
|
+
* @param options Template resolution options for interactive and non-interactive flows.
|
|
54
|
+
* @returns The normalized template identifier to scaffold.
|
|
55
|
+
*/
|
|
56
|
+
export async function resolveTemplateId({ templateId, yes = false, isInteractive = false, selectTemplate, }) {
|
|
57
|
+
if (templateId) {
|
|
58
|
+
const normalizedTemplateId = normalizeTemplateSelection(templateId);
|
|
59
|
+
if (isRemovedBuiltInTemplateId(templateId)) {
|
|
60
|
+
throw new Error(getRemovedBuiltInTemplateMessage(templateId));
|
|
61
|
+
}
|
|
62
|
+
if (isBuiltInTemplateId(normalizedTemplateId)) {
|
|
63
|
+
return getTemplateById(normalizedTemplateId).id;
|
|
64
|
+
}
|
|
65
|
+
return normalizedTemplateId;
|
|
66
|
+
}
|
|
67
|
+
if (yes) {
|
|
68
|
+
return 'basic';
|
|
69
|
+
}
|
|
70
|
+
if (!isInteractive || !selectTemplate) {
|
|
71
|
+
throw new Error(`Template is required in non-interactive mode. Use --template <${TEMPLATE_IDS.join('|')}|./path|github:owner/repo/path[#ref]|npm-package>.`);
|
|
72
|
+
}
|
|
73
|
+
return normalizeTemplateSelection(await selectTemplate());
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve the package manager id from flags, defaults, and interactive selection.
|
|
77
|
+
*
|
|
78
|
+
* @param options Package manager resolution options for interactive and non-interactive flows.
|
|
79
|
+
* @returns The normalized package manager id.
|
|
80
|
+
*/
|
|
81
|
+
export async function resolvePackageManagerId({ packageManager, yes = false, isInteractive = false, selectPackageManager, }) {
|
|
82
|
+
if (packageManager) {
|
|
83
|
+
return getPackageManager(packageManager).id;
|
|
84
|
+
}
|
|
85
|
+
if (yes) {
|
|
86
|
+
return 'npm';
|
|
87
|
+
}
|
|
88
|
+
if (!isInteractive || !selectPackageManager) {
|
|
89
|
+
throw new Error(`Package manager is required in non-interactive mode. Use --package-manager <${PACKAGE_MANAGER_IDS.join('|')}>.`);
|
|
90
|
+
}
|
|
91
|
+
return selectPackageManager();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Collect scaffold answers from defaults, CLI overrides, and optional prompts.
|
|
95
|
+
*
|
|
96
|
+
* @param options Answer collection inputs including prompt callbacks and explicit overrides.
|
|
97
|
+
* @returns The normalized scaffold answers used for rendering and file generation.
|
|
98
|
+
*/
|
|
99
|
+
export async function collectScaffoldAnswers({ projectName, templateId, yes = false, dataStorageMode, namespace, persistencePolicy, phpPrefix, promptText, textDomain, }) {
|
|
100
|
+
const defaults = getDefaultAnswers(projectName, templateId);
|
|
101
|
+
if (yes) {
|
|
102
|
+
const identifiers = resolveScaffoldIdentifiers({
|
|
103
|
+
namespace: namespace ?? defaults.namespace,
|
|
104
|
+
phpPrefix,
|
|
105
|
+
slug: defaults.slug,
|
|
106
|
+
textDomain,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
...defaults,
|
|
110
|
+
dataStorageMode: dataStorageMode ?? defaults.dataStorageMode,
|
|
111
|
+
namespace: identifiers.namespace,
|
|
112
|
+
persistencePolicy: persistencePolicy ?? defaults.persistencePolicy,
|
|
113
|
+
phpPrefix: identifiers.phpPrefix,
|
|
114
|
+
textDomain: identifiers.textDomain,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (!promptText) {
|
|
118
|
+
throw new Error('Interactive answers require a promptText callback.');
|
|
119
|
+
}
|
|
120
|
+
const identifiers = resolveScaffoldIdentifiers({
|
|
121
|
+
namespace: namespace ?? (await promptText('Namespace', defaults.namespace, validateNamespace)),
|
|
122
|
+
phpPrefix,
|
|
123
|
+
slug: await promptText('Block slug', defaults.slug, validateBlockSlug),
|
|
124
|
+
textDomain,
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
author: await promptText('Author', defaults.author),
|
|
128
|
+
dataStorageMode: dataStorageMode ?? defaults.dataStorageMode,
|
|
129
|
+
description: await promptText('Description', defaults.description),
|
|
130
|
+
namespace: identifiers.namespace,
|
|
131
|
+
persistencePolicy: persistencePolicy ?? defaults.persistencePolicy,
|
|
132
|
+
phpPrefix: identifiers.phpPrefix,
|
|
133
|
+
slug: identifiers.slug,
|
|
134
|
+
textDomain: identifiers.textDomain,
|
|
135
|
+
title: await promptText('Block title', toTitleCase(identifiers.slug)),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
import { execSync } from 'node:child_process';
|
|
@@ -3,18 +3,12 @@ import type { BuiltInCodeArtifact } from "./built-in-block-code-artifacts.js";
|
|
|
3
3
|
import { type BuiltInTemplateId } from "./template-registry.js";
|
|
4
4
|
import type { PackageManagerId } from "./package-managers.js";
|
|
5
5
|
import type { ScaffoldTemplateVariables } from "./scaffold.js";
|
|
6
|
+
export { buildGitignore, buildReadme, mergeTextLines, } from "./scaffold-documents.js";
|
|
6
7
|
export interface InstallDependenciesOptions {
|
|
7
8
|
packageManager: PackageManagerId;
|
|
8
9
|
projectDir: string;
|
|
9
10
|
}
|
|
10
11
|
export declare function ensureDirectory(targetDir: string, allowExisting?: boolean): Promise<void>;
|
|
11
|
-
export declare function buildReadme(templateId: string, variables: ScaffoldTemplateVariables, packageManager: PackageManagerId, { withMigrationUi, withTestPreset, withWpEnv, }?: {
|
|
12
|
-
withMigrationUi?: boolean;
|
|
13
|
-
withTestPreset?: boolean;
|
|
14
|
-
withWpEnv?: boolean;
|
|
15
|
-
}): string;
|
|
16
|
-
export declare function buildGitignore(): string;
|
|
17
|
-
export declare function mergeTextLines(primaryContent: string, existingContent: string): string;
|
|
18
12
|
export declare function writeStarterManifestFiles(targetDir: string, templateId: string, variables: ScaffoldTemplateVariables, artifacts?: readonly BuiltInBlockArtifact[]): Promise<void>;
|
|
19
13
|
/**
|
|
20
14
|
* Seed REST-derived persistence artifacts into a newly scaffolded built-in
|