wp-typia 0.16.0 → 0.16.2
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/package.json +2 -2
- package/src/ui/README.md +26 -0
- package/src/ui/add-flow-model.ts +120 -0
- package/src/ui/add-flow.tsx +246 -183
- package/src/ui/alternate-buffer-lifecycle.ts +152 -0
- package/src/ui/create-flow-model.ts +125 -0
- package/src/ui/create-flow.tsx +172 -145
- package/src/ui/first-party-form-model.ts +62 -0
- package/src/ui/first-party-form.tsx +460 -0
- package/src/ui/lazy-flow.tsx +22 -17
- package/src/ui/migrate-flow-model.ts +126 -0
- package/src/ui/migrate-flow.tsx +177 -159
package/src/ui/migrate-flow.tsx
CHANGED
|
@@ -1,187 +1,205 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement, useMemo } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
Form,
|
|
5
|
+
type SelectOption,
|
|
6
|
+
useFormContext,
|
|
7
|
+
useTerminalDimensions,
|
|
8
|
+
} from "@bunli/tui";
|
|
6
9
|
|
|
7
10
|
import { executeMigrateCommand } from "../runtime-bridge";
|
|
11
|
+
import { useAlternateBufferLifecycle } from "./alternate-buffer-lifecycle";
|
|
12
|
+
import {
|
|
13
|
+
type MigrateFlowValues,
|
|
14
|
+
getMigrateScrollTop,
|
|
15
|
+
getMigrateViewportHeight,
|
|
16
|
+
getVisibleMigrateFieldNames,
|
|
17
|
+
migrateFlowSchema,
|
|
18
|
+
sanitizeMigrateSubmitValues,
|
|
19
|
+
} from "./migrate-flow-model";
|
|
20
|
+
import {
|
|
21
|
+
FirstPartyCheckboxField,
|
|
22
|
+
FirstPartyScrollBox,
|
|
23
|
+
FirstPartySelectField,
|
|
24
|
+
FirstPartyTextField,
|
|
25
|
+
} from "./first-party-form";
|
|
26
|
+
import { getWrappedFieldNeighbors } from "./first-party-form-model";
|
|
8
27
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"snapshot",
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const migrateCommandOptions: SelectOption[] = [
|
|
29
|
+
{ name: "init", description: "Initialize migration config", value: "init" },
|
|
30
|
+
{
|
|
31
|
+
name: "snapshot",
|
|
32
|
+
description: "Capture the current schema snapshot",
|
|
33
|
+
value: "snapshot",
|
|
34
|
+
},
|
|
35
|
+
{ name: "plan", description: "Preview migration work", value: "plan" },
|
|
36
|
+
{
|
|
37
|
+
name: "wizard",
|
|
38
|
+
description: "Guided migration preview",
|
|
39
|
+
value: "wizard",
|
|
40
|
+
},
|
|
41
|
+
{ name: "diff", description: "Diff migration snapshots", value: "diff" },
|
|
42
|
+
{
|
|
43
|
+
name: "scaffold",
|
|
44
|
+
description: "Generate migration rules and artifacts",
|
|
45
|
+
value: "scaffold",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "verify",
|
|
49
|
+
description: "Verify generated migration fixtures",
|
|
50
|
+
value: "verify",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "doctor",
|
|
54
|
+
description: "Diagnose migration workspace health",
|
|
55
|
+
value: "doctor",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "fixtures",
|
|
59
|
+
description: "Refresh migration fixtures",
|
|
60
|
+
value: "fixtures",
|
|
61
|
+
},
|
|
62
|
+
{ name: "fuzz", description: "Run migration fuzzing", value: "fuzz" },
|
|
63
|
+
];
|
|
33
64
|
|
|
34
65
|
type MigrateFlowProps = {
|
|
35
66
|
cwd: string;
|
|
36
67
|
initialValues: Partial<MigrateFlowValues>;
|
|
37
68
|
};
|
|
38
69
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (typeof value === "string" && value.trim().length === 0) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
return [[key, value]];
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
70
|
+
type MigrateSelectFieldName = {
|
|
71
|
+
[K in keyof MigrateFlowValues]-?: MigrateFlowValues[K] extends string | undefined ? K : never;
|
|
72
|
+
}[keyof MigrateFlowValues];
|
|
49
73
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
type MigrateCheckboxFieldName = {
|
|
75
|
+
[K in keyof MigrateFlowValues]-?: MigrateFlowValues[K] extends boolean | undefined ? K : never;
|
|
76
|
+
}[keyof MigrateFlowValues];
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
name: "fixtures",
|
|
96
|
-
description: "Refresh migration fixtures",
|
|
97
|
-
value: "fixtures",
|
|
98
|
-
},
|
|
99
|
-
{ name: "fuzz", description: "Run migration fuzzing", value: "fuzz" },
|
|
100
|
-
],
|
|
101
|
-
required: true,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
kind: "text",
|
|
78
|
+
function MigrateFlowFields() {
|
|
79
|
+
const { activeFieldName, values } = useFormContext();
|
|
80
|
+
const { height: terminalHeight = 24 } = useTerminalDimensions();
|
|
81
|
+
const migrateValues = values as Partial<MigrateFlowValues>;
|
|
82
|
+
const command = migrateValues.command ?? "plan";
|
|
83
|
+
const viewportHeight = getMigrateViewportHeight(terminalHeight);
|
|
84
|
+
const scrollValues = useMemo(() => ({ command }), [command]);
|
|
85
|
+
const scrollTop = useMemo(
|
|
86
|
+
() =>
|
|
87
|
+
getMigrateScrollTop({
|
|
88
|
+
activeFieldName,
|
|
89
|
+
values: scrollValues,
|
|
90
|
+
viewportHeight,
|
|
91
|
+
}),
|
|
92
|
+
[activeFieldName, scrollValues, viewportHeight],
|
|
93
|
+
);
|
|
94
|
+
const visibleFields = new Set(getVisibleMigrateFieldNames(migrateValues));
|
|
95
|
+
const orderedVisibleFields = useMemo(
|
|
96
|
+
() => getVisibleMigrateFieldNames(migrateValues),
|
|
97
|
+
[migrateValues],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return createElement(
|
|
101
|
+
FirstPartyScrollBox,
|
|
102
|
+
{ scrollTop, viewportHeight },
|
|
103
|
+
[
|
|
104
|
+
createElement(FirstPartySelectField, {
|
|
105
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "command"),
|
|
106
|
+
key: "command",
|
|
107
|
+
label: "Migration command",
|
|
108
|
+
name: "command" satisfies MigrateSelectFieldName,
|
|
109
|
+
options: migrateCommandOptions,
|
|
110
|
+
}),
|
|
111
|
+
visibleFields.has("current-migration-version")
|
|
112
|
+
? createElement(FirstPartyTextField, {
|
|
113
|
+
...getWrappedFieldNeighbors(
|
|
114
|
+
orderedVisibleFields,
|
|
115
|
+
"current-migration-version",
|
|
116
|
+
),
|
|
117
|
+
key: "current-migration-version",
|
|
105
118
|
label: "Current migration version",
|
|
106
119
|
name: "current-migration-version",
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
120
|
+
})
|
|
121
|
+
: null,
|
|
122
|
+
visibleFields.has("migration-version")
|
|
123
|
+
? createElement(FirstPartyTextField, {
|
|
124
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "migration-version"),
|
|
125
|
+
key: "migration-version",
|
|
111
126
|
label: "Migration version",
|
|
112
127
|
name: "migration-version",
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
})
|
|
129
|
+
: null,
|
|
130
|
+
visibleFields.has("from-migration-version")
|
|
131
|
+
? createElement(FirstPartyTextField, {
|
|
132
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "from-migration-version"),
|
|
133
|
+
key: "from-migration-version",
|
|
117
134
|
label: "From migration version",
|
|
118
135
|
name: "from-migration-version",
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
values.command === "fixtures" ||
|
|
126
|
-
values.command === "fuzz",
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
kind: "text",
|
|
136
|
+
})
|
|
137
|
+
: null,
|
|
138
|
+
visibleFields.has("to-migration-version")
|
|
139
|
+
? createElement(FirstPartyTextField, {
|
|
140
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "to-migration-version"),
|
|
141
|
+
key: "to-migration-version",
|
|
130
142
|
label: "To migration version",
|
|
131
143
|
name: "to-migration-version",
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
kind: "checkbox",
|
|
144
|
+
})
|
|
145
|
+
: null,
|
|
146
|
+
visibleFields.has("all")
|
|
147
|
+
? createElement(FirstPartyCheckboxField, {
|
|
148
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "all"),
|
|
149
|
+
key: "all",
|
|
140
150
|
label: "All configured migration versions",
|
|
141
|
-
name: "all",
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
kind: "checkbox",
|
|
151
|
+
name: "all" satisfies MigrateCheckboxFieldName,
|
|
152
|
+
})
|
|
153
|
+
: null,
|
|
154
|
+
visibleFields.has("force")
|
|
155
|
+
? createElement(FirstPartyCheckboxField, {
|
|
156
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "force"),
|
|
157
|
+
key: "force",
|
|
150
158
|
label: "Force overwrite",
|
|
151
|
-
name: "force",
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
name: "force" satisfies MigrateCheckboxFieldName,
|
|
160
|
+
})
|
|
161
|
+
: null,
|
|
162
|
+
visibleFields.has("iterations")
|
|
163
|
+
? createElement(FirstPartyTextField, {
|
|
164
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "iterations"),
|
|
165
|
+
key: "iterations",
|
|
156
166
|
label: "Iterations",
|
|
157
167
|
name: "iterations",
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
})
|
|
169
|
+
: null,
|
|
170
|
+
visibleFields.has("seed")
|
|
171
|
+
? createElement(FirstPartyTextField, {
|
|
172
|
+
...getWrappedFieldNeighbors(orderedVisibleFields, "seed"),
|
|
173
|
+
key: "seed",
|
|
162
174
|
label: "Seed",
|
|
163
175
|
name: "seed",
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
})
|
|
177
|
+
: null,
|
|
178
|
+
],
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function MigrateFlow({ cwd, initialValues }: MigrateFlowProps) {
|
|
183
|
+
const { handleCancel, handleSubmit } = useAlternateBufferLifecycle("wp-typia migrate failed");
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<Form
|
|
187
|
+
initialValues={initialValues}
|
|
188
|
+
onCancel={handleCancel}
|
|
189
|
+
onSubmit={async (values) =>
|
|
190
|
+
handleSubmit(async () => {
|
|
191
|
+
const flags = sanitizeMigrateSubmitValues(values);
|
|
192
|
+
await executeMigrateCommand({
|
|
193
|
+
command: values.command,
|
|
194
|
+
cwd,
|
|
195
|
+
flags,
|
|
196
|
+
});
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
schema={migrateFlowSchema}
|
|
200
|
+
title="Run wp-typia migration workflows"
|
|
201
|
+
>
|
|
202
|
+
<MigrateFlowFields />
|
|
203
|
+
</Form>
|
|
186
204
|
);
|
|
187
205
|
}
|