Setting the file. One moment. Migration Review · Wix Replatform · wix/skills · Skills DocsScript Orchestration Preflight
scripts/migration-review.js
JavaScript·97 lines·4 KB
10
node skills/wix-replatform/scripts/migration-review.js <operation> <projectDir> [options]
11
12Mutation operations read one JSON request from --request <path>:
13 init | register-execution | capture-evidence | publish-evidence | record-action |
14 prepare-handoff | recover-lock
15
16Read operations:
17 report | overview | handoff | tasks [--group Data|Manual|Plugins] [--disposition <value>]
18 [--offset <n>] [--limit <n>]
19 task --task-id <id>
20 check-execution --execution-id <id>
21
22All output is one JSON object. The command never edits store JSON through an agent-authored
23patch: every mutation goes through the versioned interface and returns a durable receipt.
24`;
25}
26
27function parseArgs(argv) {
28 const result = { operation: argv[0], projectDir: argv[1] };
29 for (let i = 2; i < argv.length; i += 1) {
30 const token = argv[i];
31 if (!token.startsWith('--')) throw new Error(`unexpected argument: ${token}`);
32 const key = token.slice(2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
33 const value = argv[i + 1];
34 if (!value || value.startsWith('--')) throw new Error(`${token} requires a value`);
35 result[key] = value;
36 i += 1;
37 }
38 return result;
39}
40
41async function requestFrom(args) {
42 if (!args.request) throw new Error(`${args.operation} requires --request <json-file>`);
43 return JSON.parse(await fs.readFile(path.resolve(args.request), 'utf8'));
44}
45
46async function run(args) {
47 if (!args.operation || !args.projectDir || args.operation === 'help') throw new Error(usage());
48 const projectDir = path.resolve(args.projectDir);
49 const mutation = async (fn) => fn(projectDir, await requestFrom(args));
50 switch (args.operation) {
51 case 'init': return mutation(review.initialize);
52 case 'register-execution': return mutation(review.registerExecution);
53 case 'capture-evidence': return mutation(review.captureEvidence);
54 case 'publish-evidence': return mutation(review.publishEvidence);
55 case 'record-action': return mutation(review.recordAction);
56 case 'prepare-handoff': return mutation(review.prepareHandoff);
57 case 'recover-lock': return mutation(review.recoverLock);
58 case 'report': return review.readReport(projectDir);
59 case 'overview': return review.overview(projectDir);
60 case 'handoff': return { handoff: await review.readLatestHandoff(projectDir) };
61 case 'check-execution':
62 if (!args.executionId) throw new Error('check-execution requires --execution-id <id>');
63 return review.checkExecutionCaptureBoundaries(projectDir, args.executionId);
64 case 'tasks': return review.listTasks(projectDir, {
65 group: args.group,
66 disposition: args.disposition,
67 offset: args.offset,
68 limit: args.limit,
69 });
70 case 'task':
71 if (!args.taskId) throw new Error('task requires --task-id <id>');
72 return review.readTask(projectDir, args.taskId);
73 default: throw new Error(`unknown migration-review operation: ${args.operation}\n\n${usage()}`);
74 }
75}
76
77async function main(argv = process.argv.slice(2)) {
78 try {
79 const result = await run(parseArgs(argv));
80 process.stdout.write(`${JSON.stringify({ ok: true, ...result }, null, 2)}\n`);
81 return 0;
82 } catch (error) {
83 process.stdout.write(`${JSON.stringify({
84 ok: false,
85 error: {
86 code: error.code || 'invalid_request',
87 message: error.message,
88 details: error.details || {},
89 },
90 }, null, 2)}\n`);
91 return 1;
92 }
93}
94
95if (require.main === module) main().then((code) => { process.exitCode = code; });
96
97module.exports = { main, run, parseArgs };