drizzle-kit 0.9.0 → 0.9.4
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/drizzle.js +4 -0
- package/drizzle.js.map +1 -0
- package/package.json +37 -14
- package/.eslintrc +0 -19
- package/examples/tables/authOtpTable.ts +0 -22
- package/examples/tables/cityTable.ts +0 -17
- package/examples/tables/usersTable.ts +0 -18
- package/result.json +0 -207
- package/src/cli/commands/migration/index.tsx +0 -10
- package/src/cli/commands/migration/migrate/components/Progress/index.tsx +0 -98
- package/src/cli/commands/migration/migrate/components/Prompts/index.tsx +0 -37
- package/src/cli/commands/migration/migrate/components/index.tsx +0 -132
- package/src/cli/commands/migration/migrate/index.tsx +0 -26
- package/src/cli/index.tsx +0 -8
- package/src/common/components/Prompt.tsx +0 -106
- package/src/common/components/SelectTable.tsx +0 -134
- package/src/index.ts +0 -10
- package/src/serializer.ts +0 -135
- package/tsconfig.json +0 -28
- package/webpack.config.js +0 -56
package/result.json
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "1",
|
|
3
|
-
"tables": {
|
|
4
|
-
"auth_otp": {
|
|
5
|
-
"name": "auth_otp",
|
|
6
|
-
"columns": {
|
|
7
|
-
"id": {
|
|
8
|
-
"name": "id",
|
|
9
|
-
"type": "INT",
|
|
10
|
-
"primaryKey": true,
|
|
11
|
-
"autoincrement": true,
|
|
12
|
-
"unique": false
|
|
13
|
-
},
|
|
14
|
-
"phone": {
|
|
15
|
-
"name": "phone",
|
|
16
|
-
"type": "character varying(256)",
|
|
17
|
-
"primaryKey": false,
|
|
18
|
-
"autoincrement": false,
|
|
19
|
-
"unique": false
|
|
20
|
-
},
|
|
21
|
-
"otp": {
|
|
22
|
-
"name": "otp",
|
|
23
|
-
"type": "character varying(256)",
|
|
24
|
-
"primaryKey": false,
|
|
25
|
-
"autoincrement": false,
|
|
26
|
-
"unique": false
|
|
27
|
-
},
|
|
28
|
-
"issuedAt": {
|
|
29
|
-
"name": "issued_at",
|
|
30
|
-
"type": "timestamp without time zone",
|
|
31
|
-
"primaryKey": false,
|
|
32
|
-
"autoincrement": false,
|
|
33
|
-
"unique": false
|
|
34
|
-
},
|
|
35
|
-
"createdAt": {
|
|
36
|
-
"name": "created_at",
|
|
37
|
-
"type": "timestamp without time zone",
|
|
38
|
-
"primaryKey": false,
|
|
39
|
-
"autoincrement": false,
|
|
40
|
-
"unique": false
|
|
41
|
-
},
|
|
42
|
-
"updatedAt": {
|
|
43
|
-
"name": "updated_at",
|
|
44
|
-
"type": "timestamp without time zone",
|
|
45
|
-
"primaryKey": false,
|
|
46
|
-
"autoincrement": false,
|
|
47
|
-
"unique": false
|
|
48
|
-
},
|
|
49
|
-
"enum1": {
|
|
50
|
-
"name": "enum1",
|
|
51
|
-
"type": "TestEnum",
|
|
52
|
-
"primaryKey": false,
|
|
53
|
-
"autoincrement": false,
|
|
54
|
-
"unique": false
|
|
55
|
-
},
|
|
56
|
-
"userId": {
|
|
57
|
-
"name": "user_id",
|
|
58
|
-
"type": "INT",
|
|
59
|
-
"primaryKey": false,
|
|
60
|
-
"autoincrement": false,
|
|
61
|
-
"unique": false,
|
|
62
|
-
"references": {
|
|
63
|
-
"table": "users",
|
|
64
|
-
"column": "id"
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
"test": {
|
|
68
|
-
"name": "test",
|
|
69
|
-
"type": "JSONB",
|
|
70
|
-
"primaryKey": false,
|
|
71
|
-
"autoincrement": false,
|
|
72
|
-
"unique": false
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"indexes": {}
|
|
76
|
-
},
|
|
77
|
-
"citiess": {
|
|
78
|
-
"name": "citiess",
|
|
79
|
-
"columns": {
|
|
80
|
-
"name": {
|
|
81
|
-
"name": "name",
|
|
82
|
-
"type": "timestamp without time zone",
|
|
83
|
-
"primaryKey": false,
|
|
84
|
-
"autoincrement": false,
|
|
85
|
-
"unique": false
|
|
86
|
-
},
|
|
87
|
-
"page": {
|
|
88
|
-
"name": "page",
|
|
89
|
-
"type": "character varying(256)",
|
|
90
|
-
"primaryKey": false,
|
|
91
|
-
"autoincrement": false,
|
|
92
|
-
"unique": false
|
|
93
|
-
},
|
|
94
|
-
"enum1": {
|
|
95
|
-
"name": "enum1",
|
|
96
|
-
"type": "TestEnum",
|
|
97
|
-
"primaryKey": false,
|
|
98
|
-
"autoincrement": false,
|
|
99
|
-
"unique": false
|
|
100
|
-
},
|
|
101
|
-
"userId1": {
|
|
102
|
-
"name": "user_id",
|
|
103
|
-
"type": "INT",
|
|
104
|
-
"primaryKey": false,
|
|
105
|
-
"autoincrement": false,
|
|
106
|
-
"unique": false,
|
|
107
|
-
"references": {
|
|
108
|
-
"table": "users",
|
|
109
|
-
"column": "id"
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"data": {
|
|
113
|
-
"name": "data",
|
|
114
|
-
"type": "JSONB",
|
|
115
|
-
"primaryKey": false,
|
|
116
|
-
"autoincrement": false,
|
|
117
|
-
"unique": false
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
"indexes": {}
|
|
121
|
-
},
|
|
122
|
-
"users": {
|
|
123
|
-
"name": "users",
|
|
124
|
-
"columns": {
|
|
125
|
-
"id": {
|
|
126
|
-
"name": "id",
|
|
127
|
-
"type": "INT",
|
|
128
|
-
"primaryKey": true,
|
|
129
|
-
"autoincrement": true,
|
|
130
|
-
"unique": false
|
|
131
|
-
},
|
|
132
|
-
"phone": {
|
|
133
|
-
"name": "phone",
|
|
134
|
-
"type": "character varying(256)",
|
|
135
|
-
"primaryKey": false,
|
|
136
|
-
"autoincrement": false,
|
|
137
|
-
"unique": true
|
|
138
|
-
},
|
|
139
|
-
"fullName": {
|
|
140
|
-
"name": "full_name",
|
|
141
|
-
"type": "character varying(512)",
|
|
142
|
-
"primaryKey": false,
|
|
143
|
-
"autoincrement": false,
|
|
144
|
-
"unique": false
|
|
145
|
-
},
|
|
146
|
-
"test": {
|
|
147
|
-
"name": "test",
|
|
148
|
-
"type": "numeric(100,2)",
|
|
149
|
-
"primaryKey": false,
|
|
150
|
-
"autoincrement": false,
|
|
151
|
-
"unique": false
|
|
152
|
-
},
|
|
153
|
-
"test1": {
|
|
154
|
-
"name": "test1",
|
|
155
|
-
"type": "BIGINT",
|
|
156
|
-
"primaryKey": false,
|
|
157
|
-
"autoincrement": false,
|
|
158
|
-
"unique": false
|
|
159
|
-
},
|
|
160
|
-
"createdAt": {
|
|
161
|
-
"name": "created_at",
|
|
162
|
-
"type": "timestamp without time zone",
|
|
163
|
-
"primaryKey": false,
|
|
164
|
-
"autoincrement": false,
|
|
165
|
-
"unique": false
|
|
166
|
-
},
|
|
167
|
-
"updatedAt": {
|
|
168
|
-
"name": "updated_at",
|
|
169
|
-
"type": "timestamp without time zone",
|
|
170
|
-
"primaryKey": false,
|
|
171
|
-
"autoincrement": false,
|
|
172
|
-
"unique": false
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
"indexes": {
|
|
176
|
-
"users_phone_full_name_index": {
|
|
177
|
-
"name": "users_phone_full_name_index",
|
|
178
|
-
"columns": {
|
|
179
|
-
"phone": {
|
|
180
|
-
"name": "phone"
|
|
181
|
-
},
|
|
182
|
-
"full_name": {
|
|
183
|
-
"name": "full_name"
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
"users_phone_index": {
|
|
188
|
-
"name": "users_phone_index",
|
|
189
|
-
"columns": {
|
|
190
|
-
"phone": {
|
|
191
|
-
"name": "phone"
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
"enums": {
|
|
199
|
-
"TestEnum": {
|
|
200
|
-
"name": "TestEnum",
|
|
201
|
-
"values": [
|
|
202
|
-
"first",
|
|
203
|
-
"second"
|
|
204
|
-
]
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { useImmer } from 'use-immer';
|
|
3
|
-
import { Box, Newline, Text } from 'ink';
|
|
4
|
-
import Spinner from 'ink-spinner';
|
|
5
|
-
import { v4 as uuid } from 'uuid';
|
|
6
|
-
|
|
7
|
-
import { MigrationParams } from '../../index';
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
migration: (params: MigrationParams) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const MigrationProgress: React.FC<Props> = ({ migration }) => {
|
|
14
|
-
const [steps, setSteps] = useImmer<
|
|
15
|
-
({ key: string; text: string } & (
|
|
16
|
-
| {
|
|
17
|
-
state: 'in_progress' | 'success';
|
|
18
|
-
error?: Error | undefined;
|
|
19
|
-
}
|
|
20
|
-
| { state: 'fail'; error: Error }
|
|
21
|
-
))[]
|
|
22
|
-
>([]);
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const addStep = (text: string) => {
|
|
26
|
-
setSteps((curSteps) => {
|
|
27
|
-
curSteps.push({ key: uuid(), text, state: 'in_progress' });
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const completeStep = () => {
|
|
32
|
-
setSteps((curSteps) => {
|
|
33
|
-
curSteps[curSteps.length - 1].state = 'success';
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const failStep = (e: Error) => {
|
|
38
|
-
setSteps((curSteps) => {
|
|
39
|
-
if (!curSteps.length) {
|
|
40
|
-
console.error(e);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
curSteps[curSteps.length - 1].state = 'fail';
|
|
44
|
-
curSteps[curSteps.length - 1].error = e;
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const done = () => {};
|
|
49
|
-
|
|
50
|
-
(async () => {
|
|
51
|
-
await migration({
|
|
52
|
-
addStep,
|
|
53
|
-
completeStep,
|
|
54
|
-
done,
|
|
55
|
-
});
|
|
56
|
-
})().catch((e) => {
|
|
57
|
-
failStep(e);
|
|
58
|
-
});
|
|
59
|
-
}, [migration]);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<>
|
|
63
|
-
{steps.map((step) => (
|
|
64
|
-
<Box key={step.key} flexDirection='row'>
|
|
65
|
-
<Box marginRight={1}>
|
|
66
|
-
{step.state === 'in_progress' ? (
|
|
67
|
-
<Text>
|
|
68
|
-
[<Spinner type='dots' />]
|
|
69
|
-
</Text>
|
|
70
|
-
) : step.state === 'success' ? (
|
|
71
|
-
<Text>
|
|
72
|
-
[<Text color='green'>✓</Text>]
|
|
73
|
-
</Text>
|
|
74
|
-
) : (
|
|
75
|
-
<Text>
|
|
76
|
-
[<Text color='red'>×</Text>]
|
|
77
|
-
</Text>
|
|
78
|
-
)}
|
|
79
|
-
</Box>
|
|
80
|
-
|
|
81
|
-
{step.state === 'fail' ? (
|
|
82
|
-
<Text>
|
|
83
|
-
{step.text}
|
|
84
|
-
<Newline />
|
|
85
|
-
<Text color='red'>{step.error.message}</Text>
|
|
86
|
-
</Text>
|
|
87
|
-
) : (
|
|
88
|
-
<>
|
|
89
|
-
<Text>{step.text}</Text>
|
|
90
|
-
</>
|
|
91
|
-
)}
|
|
92
|
-
</Box>
|
|
93
|
-
))}
|
|
94
|
-
</>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default MigrationProgress;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import Prompt from '@common/components/Prompt';
|
|
4
|
-
|
|
5
|
-
enum Steps {
|
|
6
|
-
NAME,
|
|
7
|
-
DONE
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface Props {
|
|
11
|
-
onDone: (config: { name: string; }) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const Prompts: React.FC<Props> = ({ onDone }) => {
|
|
15
|
-
const [name, setName] = useState('');
|
|
16
|
-
const [currentStep, setCurrentStep] = useState<Steps>(Steps.NAME);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (name !== '') {
|
|
20
|
-
setCurrentStep(Steps.DONE);
|
|
21
|
-
}
|
|
22
|
-
}, [name, setCurrentStep]);
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (currentStep === Steps.DONE) {
|
|
26
|
-
onDone({ name });
|
|
27
|
-
}
|
|
28
|
-
}, [currentStep, name]);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<>
|
|
32
|
-
<Prompt text={<>Migrate</>} onDone={setName} />
|
|
33
|
-
</>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default Prompts;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import Spinner from 'ink-spinner';
|
|
4
|
-
import SelectInput from 'ink-select-input';
|
|
5
|
-
|
|
6
|
-
import Table from '@common/components/SelectTable';
|
|
7
|
-
import { MigrationParams } from 'cli/commands/migration/migrate/index';
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
migrate: (params: MigrationParams) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
enum MigrationStep {
|
|
14
|
-
INIT,
|
|
15
|
-
TABLE,
|
|
16
|
-
ACTION,
|
|
17
|
-
TABLE_CHANGES
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const Root: React.FC<Props> = ({ migrate }) => {
|
|
21
|
-
const [table, setTable] = useState('');
|
|
22
|
-
const [action, setAction] = useState('');
|
|
23
|
-
const [index, setIndex] = useState(0);
|
|
24
|
-
const [component, setComponent] = useState('');
|
|
25
|
-
|
|
26
|
-
const [tableChanges, setTableChanges] = useState('');
|
|
27
|
-
const [currentStep, setCurrentStep] = useState(MigrationStep.INIT);
|
|
28
|
-
|
|
29
|
-
const handleTable = (a: any) => {
|
|
30
|
-
setTable(a);
|
|
31
|
-
setCurrentStep(MigrationStep.ACTION);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const handleAction = (a: any) => {
|
|
35
|
-
setAction(a);
|
|
36
|
-
setComponent((text) => `${text}\n Table 1 is: ${tableA[index].renamed}`);
|
|
37
|
-
setCurrentStep(MigrationStep.TABLE_CHANGES);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
setTimeout(() => setCurrentStep(MigrationStep.TABLE), 2000);
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
const handleSelect = (index: number) => {
|
|
45
|
-
setComponent((text) => `${text}\n` + `We're going to have table view with two columns: ${tableA[index].newName}`);
|
|
46
|
-
setCurrentStep(MigrationStep.ACTION);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const items = [
|
|
50
|
-
{
|
|
51
|
-
label: 'First',
|
|
52
|
-
value: 'first',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
label: 'Second',
|
|
56
|
-
value: 'second',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
label: 'Third',
|
|
60
|
-
value: 'third',
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const actions = [
|
|
65
|
-
{
|
|
66
|
-
label: 'Renamed',
|
|
67
|
-
value: 'Renamed',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
label: 'Deleted',
|
|
71
|
-
value: 'Deleted',
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
const tableA = [
|
|
76
|
-
{
|
|
77
|
-
missing: 'Table 1', newName: 'Table 2', deleted: false, renamed: 'Table 2',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
missing: 'Table 3', newName: 'Table 4', deleted: true, renamed: '',
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
missing: 'Table 5', newName: 'Table 6', deleted: false, renamed: 'Table 4',
|
|
84
|
-
},
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
const testRender = () => {
|
|
88
|
-
if (currentStep === MigrationStep.INIT) {
|
|
89
|
-
return (
|
|
90
|
-
<Text>
|
|
91
|
-
<Spinner />
|
|
92
|
-
...progress
|
|
93
|
-
</Text>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (currentStep === MigrationStep.TABLE) {
|
|
98
|
-
return (
|
|
99
|
-
<>
|
|
100
|
-
<Text>We`re going to have table view with two columns</Text>
|
|
101
|
-
<Table
|
|
102
|
-
text="Conflicts"
|
|
103
|
-
onDone={handleSelect}
|
|
104
|
-
selectFrom={tableA}
|
|
105
|
-
/>
|
|
106
|
-
</>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (currentStep === MigrationStep.ACTION) {
|
|
111
|
-
return (
|
|
112
|
-
<>
|
|
113
|
-
<Text>Table 1 is:</Text>
|
|
114
|
-
<SelectInput items={actions} onSelect={handleAction} />
|
|
115
|
-
</>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return (<></>);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<>
|
|
124
|
-
<Box marginBottom={1}>
|
|
125
|
-
<Text>{component}</Text>
|
|
126
|
-
</Box>
|
|
127
|
-
{testRender()}
|
|
128
|
-
</>
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export default Root;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { render } from 'ink';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
import Root from 'cli/commands/migration/migrate/components';
|
|
5
|
-
|
|
6
|
-
export interface MigrationParams {
|
|
7
|
-
addStep: (name: string) => void;
|
|
8
|
-
completeStep: () => void;
|
|
9
|
-
done: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function migrate({
|
|
13
|
-
addStep,
|
|
14
|
-
completeStep,
|
|
15
|
-
done,
|
|
16
|
-
}: MigrationParams) {
|
|
17
|
-
addStep('...progress');
|
|
18
|
-
|
|
19
|
-
completeStep();
|
|
20
|
-
|
|
21
|
-
done();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default function init() {
|
|
25
|
-
render(<Root migrate={migrate} />);
|
|
26
|
-
}
|
package/src/cli/index.tsx
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useState,
|
|
5
|
-
} from 'react';
|
|
6
|
-
import { Box, Text } from 'ink';
|
|
7
|
-
import TextInput from 'ink-text-input';
|
|
8
|
-
import SelectInput from 'ink-select-input';
|
|
9
|
-
|
|
10
|
-
interface Props<T extends string = string> {
|
|
11
|
-
text: React.ReactFragment;
|
|
12
|
-
defaultValue?: T;
|
|
13
|
-
selectFrom?: { value: T; label: string }[];
|
|
14
|
-
onDone: (value: T) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const Prompt = <T extends string = string>({
|
|
18
|
-
text,
|
|
19
|
-
defaultValue,
|
|
20
|
-
selectFrom,
|
|
21
|
-
onDone,
|
|
22
|
-
}: React.PropsWithChildren<Props<T>>) => {
|
|
23
|
-
const [promptValue, setValue] = useState('' as T);
|
|
24
|
-
const [isDone, setDone] = useState(false);
|
|
25
|
-
|
|
26
|
-
const onSelect = useCallback(
|
|
27
|
-
(val: T) => {
|
|
28
|
-
setValue(val);
|
|
29
|
-
setDone(true);
|
|
30
|
-
},
|
|
31
|
-
[setValue, onDone],
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const onSubmit = useCallback(() => {
|
|
35
|
-
if (!promptValue && defaultValue) {
|
|
36
|
-
setValue(defaultValue);
|
|
37
|
-
}
|
|
38
|
-
setDone(true);
|
|
39
|
-
}, [setDone, onDone, promptValue, defaultValue]);
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (isDone) {
|
|
43
|
-
onDone(promptValue);
|
|
44
|
-
}
|
|
45
|
-
}, [isDone, promptValue]);
|
|
46
|
-
|
|
47
|
-
const prefix = (
|
|
48
|
-
<Box flexDirection="row">
|
|
49
|
-
<Box marginRight={1}>
|
|
50
|
-
{isDone ? (
|
|
51
|
-
<Text>
|
|
52
|
-
[
|
|
53
|
-
<Text color="green">✓</Text>
|
|
54
|
-
]
|
|
55
|
-
</Text>
|
|
56
|
-
) : (
|
|
57
|
-
<Text>
|
|
58
|
-
[
|
|
59
|
-
<Text color="gray">?</Text>
|
|
60
|
-
]
|
|
61
|
-
</Text>
|
|
62
|
-
)}
|
|
63
|
-
</Box>
|
|
64
|
-
<Text>
|
|
65
|
-
{text}
|
|
66
|
-
{defaultValue && ` <${defaultValue}>`}
|
|
67
|
-
:
|
|
68
|
-
{' '}
|
|
69
|
-
</Text>
|
|
70
|
-
</Box>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<>
|
|
75
|
-
{selectFrom ? (
|
|
76
|
-
<Box flexDirection={isDone ? 'row' : 'column'}>
|
|
77
|
-
{prefix}
|
|
78
|
-
{isDone ? (
|
|
79
|
-
<Text>{promptValue}</Text>
|
|
80
|
-
) : (
|
|
81
|
-
<SelectInput
|
|
82
|
-
items={selectFrom}
|
|
83
|
-
onSelect={({ value }) => onSelect(value)}
|
|
84
|
-
initialIndex={0}
|
|
85
|
-
/>
|
|
86
|
-
)}
|
|
87
|
-
</Box>
|
|
88
|
-
) : (
|
|
89
|
-
<Box flexDirection="row">
|
|
90
|
-
{prefix}
|
|
91
|
-
{isDone ? (
|
|
92
|
-
<Text>{promptValue}</Text>
|
|
93
|
-
) : (
|
|
94
|
-
<TextInput
|
|
95
|
-
value={promptValue}
|
|
96
|
-
onChange={(value) => setValue(value as T)}
|
|
97
|
-
onSubmit={onSubmit}
|
|
98
|
-
/>
|
|
99
|
-
)}
|
|
100
|
-
</Box>
|
|
101
|
-
)}
|
|
102
|
-
</>
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export default Prompt;
|