@aws-amplify/amplify-util-uibuilder 1.5.0-studio-forms.0 → 1.5.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/CHANGELOG.md +1 -2
- package/amplify-plugin.json +3 -10
- package/lib/clients/amplify-studio-client.d.ts +2 -13
- package/lib/clients/amplify-studio-client.d.ts.map +1 -1
- package/lib/clients/amplify-studio-client.js +4 -72
- package/lib/clients/amplify-studio-client.js.map +1 -1
- package/lib/commands/generateComponents.d.ts.map +1 -1
- package/lib/commands/generateComponents.js +15 -36
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/help.d.ts +1 -1
- package/lib/commands/help.d.ts.map +1 -1
- package/lib/commands/help.js +2 -2
- package/lib/commands/help.js.map +1 -1
- package/lib/commands/utils/codegenResources.d.ts +2 -12
- package/lib/commands/utils/codegenResources.d.ts.map +1 -1
- package/lib/commands/utils/codegenResources.js +3 -70
- package/lib/commands/utils/codegenResources.js.map +1 -1
- package/lib/commands/utils/getUiBuilderComponentsPath.d.ts.map +1 -1
- package/lib/commands/utils/getUiBuilderComponentsPath.js.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +20 -12
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +3 -36
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/lib/commands/version.d.ts +1 -1
- package/lib/commands/version.d.ts.map +1 -1
- package/lib/commands/version.js +2 -2
- package/lib/commands/version.js.map +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.d.ts +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.d.ts.map +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.js +6 -4
- package/lib/event-handlers/handle-PostEnvAdd.js.map +1 -1
- package/lib/event-handlers/handle-PostPull.d.ts +1 -1
- package/lib/event-handlers/handle-PostPull.d.ts.map +1 -1
- package/lib/event-handlers/handle-PostPull.js +3 -4
- package/lib/event-handlers/handle-PostPull.js.map +1 -1
- package/package.json +7 -8
- package/src/__tests__/cloneComponentsFromEnv.test.ts +0 -11
- package/src/__tests__/createUiBuilderComponent.test.ts +1 -19
- package/src/__tests__/generateComponents.test.ts +1 -35
- package/src/__tests__/getAmplifyDataSchema.test.ts +3 -43
- package/src/__tests__/handleEvents.test.ts +21 -0
- package/src/__tests__/syncAmplifyUiComponents.test.ts +8 -111
- package/src/clients/amplify-studio-client.ts +63 -146
- package/src/commands/generateComponents.ts +16 -46
- package/src/commands/help.ts +2 -5
- package/src/commands/utils/codegenResources.ts +4 -108
- package/src/commands/utils/getUiBuilderComponentsPath.ts +2 -7
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +29 -74
- package/src/commands/version.ts +2 -5
- package/src/event-handlers/handle-PostEnvAdd.ts +6 -8
- package/src/event-handlers/handle-PostPull.ts +3 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/utils/featureFlags.d.ts +0 -3
- package/lib/commands/utils/featureFlags.d.ts.map +0 -1
- package/lib/commands/utils/featureFlags.js +0 -34
- package/lib/commands/utils/featureFlags.js.map +0 -1
- package/lib/event-handlers/handle-PostPush.d.ts +0 -3
- package/lib/event-handlers/handle-PostPush.d.ts.map +0 -1
- package/lib/event-handlers/handle-PostPush.js +0 -15
- package/lib/event-handlers/handle-PostPush.js.map +0 -1
- package/src/__tests__/utils.ts +0 -70
- package/src/commands/utils/featureFlags.ts +0 -61
- package/src/event-handlers/handle-PostPush.ts +0 -15
|
@@ -6,12 +6,9 @@ import {
|
|
|
6
6
|
getEnvName,
|
|
7
7
|
getAppId,
|
|
8
8
|
resolveAppId,
|
|
9
|
-
generateUiBuilderForms,
|
|
10
9
|
} from '../commands/utils';
|
|
11
10
|
import { AmplifyStudioClient } from '../clients';
|
|
12
11
|
import * as createUiBuilderComponentDependency from '../commands/utils/codegenResources';
|
|
13
|
-
import { exampleSchema } from './utils';
|
|
14
|
-
import { GenericDataModel, GenericDataSchema } from '@aws-amplify/codegen-ui';
|
|
15
12
|
|
|
16
13
|
jest.mock('amplify-cli-core', () => ({
|
|
17
14
|
...jest.requireActual('amplify-cli-core'),
|
|
@@ -20,9 +17,6 @@ jest.mock('amplify-cli-core', () => ({
|
|
|
20
17
|
getNumber: () => 0,
|
|
21
18
|
},
|
|
22
19
|
}));
|
|
23
|
-
jest.mock('../commands/utils/featureFlags', () => ({
|
|
24
|
-
getTransformerVersion: jest.fn().mockImplementation(() => 2)
|
|
25
|
-
}));
|
|
26
20
|
|
|
27
21
|
const awsMock = aws as any;
|
|
28
22
|
const stateManagerMock = stateManager as any;
|
|
@@ -70,12 +64,12 @@ describe('should sync amplify ui builder components', () => {
|
|
|
70
64
|
promise: jest.fn(() => ({
|
|
71
65
|
entities: [
|
|
72
66
|
{
|
|
73
|
-
appId: 'd37nrm8rzt3oek',
|
|
67
|
+
appId: 'd37nrm8rzt3oek',
|
|
74
68
|
bindingProperties: {},
|
|
75
69
|
componentType: 'Box',
|
|
76
70
|
environmentName: 'staging',
|
|
77
|
-
id: 's-s4mU579Ycf6JGHwhqT',
|
|
78
|
-
name: 'aawwdd',
|
|
71
|
+
id: 's-s4mU579Ycf6JGHwhqT',
|
|
72
|
+
name: 'aawwdd',
|
|
79
73
|
overrides: {},
|
|
80
74
|
properties: {},
|
|
81
75
|
variants: [],
|
|
@@ -88,62 +82,10 @@ describe('should sync amplify ui builder components', () => {
|
|
|
88
82
|
entities: [{}],
|
|
89
83
|
})),
|
|
90
84
|
})),
|
|
91
|
-
exportForms: jest.fn(() => ({
|
|
92
|
-
promise: jest.fn(() => ({
|
|
93
|
-
entities: [{
|
|
94
|
-
name: 'BasicFormCreate',
|
|
95
|
-
formActionType: 'create',
|
|
96
|
-
dataType: {
|
|
97
|
-
dataSourceType: 'Custom',
|
|
98
|
-
dataTypeName: 'Post',
|
|
99
|
-
},
|
|
100
|
-
fields: {
|
|
101
|
-
name: {
|
|
102
|
-
inputType: {
|
|
103
|
-
required: true,
|
|
104
|
-
type: 'TextField',
|
|
105
|
-
name: 'name',
|
|
106
|
-
defaultValue: 'John Doe',
|
|
107
|
-
},
|
|
108
|
-
label: 'name',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
sectionalElements: {},
|
|
112
|
-
style: {},
|
|
113
|
-
}],
|
|
114
|
-
})),
|
|
115
|
-
})),
|
|
116
|
-
exportViews: jest.fn(() => ({
|
|
117
|
-
promise: jest.fn(() => ({
|
|
118
|
-
entities: [{
|
|
119
|
-
appId: '23342',
|
|
120
|
-
dataSource: { type: 'Custom' },
|
|
121
|
-
environmentName: 'staging',
|
|
122
|
-
id: 'id',
|
|
123
|
-
name: 'ProductTable',
|
|
124
|
-
// TODO: replace with export when Codegen updated
|
|
125
|
-
schemaVersion: '1.0',
|
|
126
|
-
style: {},
|
|
127
|
-
viewConfiguration: {
|
|
128
|
-
type: 'Table',
|
|
129
|
-
},
|
|
130
|
-
}],
|
|
131
|
-
})),
|
|
132
|
-
})),
|
|
133
|
-
getMetadata: jest.fn(() => ({
|
|
134
|
-
promise: jest.fn(() => ({
|
|
135
|
-
features: {
|
|
136
|
-
autoGenerateForms: 'true',
|
|
137
|
-
autoGenerateViews: 'true',
|
|
138
|
-
},
|
|
139
|
-
})),
|
|
140
|
-
})),
|
|
141
85
|
}));
|
|
142
86
|
|
|
143
87
|
createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn();
|
|
144
88
|
createUiBuilderComponentDependencyMock.createUiBuilderTheme = jest.fn();
|
|
145
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn();
|
|
146
|
-
createUiBuilderComponentDependencyMock.createUiBuilderView = jest.fn();
|
|
147
89
|
});
|
|
148
90
|
|
|
149
91
|
it('pulls components from aws-sdk and passes them to createUiBuilderComponent', () => {
|
|
@@ -152,14 +94,14 @@ describe('should sync amplify ui builder components', () => {
|
|
|
152
94
|
|
|
153
95
|
it('does not throw an error when createUiBuilderComponent fails', () => {
|
|
154
96
|
createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn(() => {
|
|
155
|
-
throw new Error('ahhh!');
|
|
97
|
+
throw new Error('ahhh!');
|
|
156
98
|
});
|
|
157
99
|
expect(async () => generateUiBuilderComponents(context, [])).not.toThrow();
|
|
158
100
|
});
|
|
159
101
|
|
|
160
102
|
it('does not throw an error when createUiBuilderThemes fails', () => {
|
|
161
103
|
createUiBuilderComponentDependencyMock.createUiBuilderComponent = jest.fn(() => {
|
|
162
|
-
throw new Error('ahhh!');
|
|
104
|
+
throw new Error('ahhh!');
|
|
163
105
|
});
|
|
164
106
|
expect(async () => generateUiBuilderThemes(context, [])).not.toThrow();
|
|
165
107
|
});
|
|
@@ -171,30 +113,19 @@ describe('should sync amplify ui builder components', () => {
|
|
|
171
113
|
expect(Object.keys(client)).toEqual(expect.arrayContaining([
|
|
172
114
|
'listComponents',
|
|
173
115
|
'listThemes',
|
|
174
|
-
'listForms',
|
|
175
116
|
'getModels',
|
|
176
|
-
'loadMetadata',
|
|
177
117
|
'createComponent',
|
|
178
118
|
]));
|
|
179
|
-
expect(client.metadata).toEqual(expect.objectContaining({
|
|
180
|
-
autoGenerateForms: true,
|
|
181
|
-
autoGenerateViews: true,
|
|
182
|
-
}));
|
|
183
|
-
});
|
|
184
|
-
it('can list components', async () => {
|
|
185
|
-
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
186
|
-
const components = await client.listComponents();
|
|
187
|
-
expect(components.entities).toHaveLength(1);
|
|
188
119
|
});
|
|
189
120
|
it('can list themes', async () => {
|
|
190
121
|
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
191
122
|
const themes = await client.listThemes();
|
|
192
123
|
expect(themes.entities).toHaveLength(1);
|
|
193
124
|
});
|
|
194
|
-
it('can
|
|
125
|
+
it('can listUiBuilderComponents', async () => {
|
|
195
126
|
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
196
|
-
const
|
|
197
|
-
expect(
|
|
127
|
+
const components = await client.listThemes();
|
|
128
|
+
expect(components.entities).toHaveLength(1);
|
|
198
129
|
});
|
|
199
130
|
it('can getAppId', async () => {
|
|
200
131
|
const appId = getAppId(context);
|
|
@@ -238,38 +169,4 @@ describe('should sync amplify ui builder components', () => {
|
|
|
238
169
|
const themes = generateUiBuilderThemes(context, [{}, {}]);
|
|
239
170
|
expect(themes.every(theme => theme.resultType === 'FAILURE')).toBeTruthy();
|
|
240
171
|
});
|
|
241
|
-
it('can generate ui builder forms', async () => {
|
|
242
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
|
|
243
|
-
const forms = generateUiBuilderForms(context, [{}, {}]);
|
|
244
|
-
expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
|
|
245
|
-
});
|
|
246
|
-
it('can handle failed generation generate ui builder forms', async () => {
|
|
247
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => {
|
|
248
|
-
throw new Error('ahh!');
|
|
249
|
-
});
|
|
250
|
-
const forms = generateUiBuilderForms(context, [{}, {}]);
|
|
251
|
-
expect(forms.every(form => form.resultType === 'FAILURE')).toBeTruthy();
|
|
252
|
-
});
|
|
253
|
-
it('can generate uibuilder forms from data schema if autogen true', async () => {
|
|
254
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
|
|
255
|
-
const forms = generateUiBuilderForms(context, [], exampleSchema, true);
|
|
256
|
-
expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
|
|
257
|
-
// create & update form for author model
|
|
258
|
-
expect(forms.length).toEqual(2);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('should not autogen forms for join tables or unsupported models', async () => {
|
|
262
|
-
expect(Object.keys(exampleSchema.models)).toStrictEqual(['Author', 'JoinTable', 'EmptyModel' ])
|
|
263
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation((context, schema, dataSchema) => ({name: schema.dataType.dataTypeName}));
|
|
264
|
-
const forms = generateUiBuilderForms(context, [], exampleSchema, true);
|
|
265
|
-
expect(forms.every(form => form.resultType === 'SUCCESS')).toBeTruthy();
|
|
266
|
-
// only create & update form for author model
|
|
267
|
-
expect(forms.map(f => (f.schema as any).name)).toStrictEqual(['Author', 'Author']);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('does not generate uibuilder forms from data schema if autogen false', async () => {
|
|
271
|
-
createUiBuilderComponentDependencyMock.createUiBuilderForm = jest.fn().mockImplementation(() => ({}));
|
|
272
|
-
const forms = generateUiBuilderForms(context, [], exampleSchema, false);
|
|
273
|
-
expect(forms.length).toEqual(0);
|
|
274
|
-
});
|
|
275
172
|
});
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import { $TSContext
|
|
1
|
+
import type { $TSContext } from 'amplify-cli-core';
|
|
2
2
|
import type { ServiceConfigurationOptions } from 'aws-sdk/lib/service';
|
|
3
|
-
import type {
|
|
4
|
-
CreateComponentData, Component, Theme, Form,
|
|
5
|
-
} from 'aws-sdk/clients/amplifyuibuilder';
|
|
3
|
+
import type { CreateComponentData, Component, Theme } from 'aws-sdk/clients/amplifyuibuilder';
|
|
6
4
|
import { AmplifyUIBuilder, AmplifyBackend } from 'aws-sdk';
|
|
7
5
|
import { printer } from 'amplify-prompts';
|
|
8
6
|
import { getAppId, getEnvName } from '../commands/utils/environmentHelpers';
|
|
9
|
-
import { getTransformerVersion } from '../commands/utils/featureFlags';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* studio client metadata
|
|
13
|
-
*/
|
|
14
|
-
export type StudioMetadata = {
|
|
15
|
-
autoGenerateForms: boolean;
|
|
16
|
-
autoGenerateViews: boolean;
|
|
17
|
-
};
|
|
18
7
|
|
|
19
8
|
/**
|
|
20
9
|
* Builds the Amplify Backend Client
|
|
@@ -56,8 +45,6 @@ export default class AmplifyStudioClient {
|
|
|
56
45
|
#amplifyBackend: AmplifyBackend;
|
|
57
46
|
#appId: string;
|
|
58
47
|
#envName: string;
|
|
59
|
-
metadata: StudioMetadata;
|
|
60
|
-
isSupportedGraphQL = false;
|
|
61
48
|
/**
|
|
62
49
|
* Used to configure the AWS Amplify clients.
|
|
63
50
|
*/
|
|
@@ -69,56 +56,19 @@ export default class AmplifyStudioClient {
|
|
|
69
56
|
resolvedEnvName,
|
|
70
57
|
resolvedAppId,
|
|
71
58
|
])) as ServiceConfigurationOptions;
|
|
72
|
-
|
|
73
|
-
const client = new AmplifyStudioClient(awsConfigInfo, resolvedAppId, resolvedEnvName);
|
|
74
|
-
|
|
75
|
-
if ((await getTransformerVersion(context)) === 2) {
|
|
76
|
-
await client.loadMetadata();
|
|
77
|
-
client.isSupportedGraphQL = true;
|
|
78
|
-
} else {
|
|
79
|
-
client.isSupportedGraphQL = false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return client;
|
|
59
|
+
return new AmplifyStudioClient(awsConfigInfo, resolvedAppId, resolvedEnvName);
|
|
83
60
|
}
|
|
84
61
|
|
|
85
62
|
/*
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
* Builds the clients
|
|
64
|
+
*/
|
|
88
65
|
constructor(awsConfigInfo: ServiceConfigurationOptions, appId: string, envName: string) {
|
|
89
66
|
this.#amplifyUiBuilder = buildAmplifyUiBuilderClient(awsConfigInfo);
|
|
90
67
|
this.#amplifyBackend = buildAmplifyBackendClient(awsConfigInfo);
|
|
91
68
|
this.#appId = appId;
|
|
92
69
|
this.#envName = envName;
|
|
93
|
-
this.metadata = {
|
|
94
|
-
autoGenerateForms: false,
|
|
95
|
-
autoGenerateViews: false,
|
|
96
|
-
};
|
|
97
70
|
}
|
|
98
71
|
|
|
99
|
-
/**
|
|
100
|
-
* loads metadata from appId/envName
|
|
101
|
-
*/
|
|
102
|
-
loadMetadata = async (envName?: string, appId?: string): Promise<void> => {
|
|
103
|
-
const environmentName = envName || this.#envName;
|
|
104
|
-
const resolvedAppId = appId || this.#appId;
|
|
105
|
-
try {
|
|
106
|
-
const response = await this.#amplifyUiBuilder
|
|
107
|
-
.getMetadata({
|
|
108
|
-
appId: resolvedAppId,
|
|
109
|
-
environmentName,
|
|
110
|
-
})
|
|
111
|
-
.promise();
|
|
112
|
-
this.metadata = {
|
|
113
|
-
autoGenerateForms: response.features?.autoGenerateForms === 'true',
|
|
114
|
-
autoGenerateViews: response.features?.autoGenerateViews === 'true',
|
|
115
|
-
};
|
|
116
|
-
} catch (e) {
|
|
117
|
-
printer.debug(e.toString());
|
|
118
|
-
throw e;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
72
|
/**
|
|
123
73
|
* listComponents from Studio
|
|
124
74
|
*/
|
|
@@ -145,100 +95,67 @@ export default class AmplifyStudioClient {
|
|
|
145
95
|
printer.debug(e);
|
|
146
96
|
throw e;
|
|
147
97
|
}
|
|
148
|
-
}
|
|
98
|
+
}
|
|
149
99
|
|
|
150
100
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
listForms = async (envName?: string, appId?: string): Promise<{ entities: Form[] }> => {
|
|
180
|
-
const environmentName = envName || this.#envName;
|
|
181
|
-
const resolvedAppId = appId || this.#appId;
|
|
182
|
-
try {
|
|
183
|
-
let nextToken: string | undefined;
|
|
184
|
-
const uibuilderForms: Form[] = [];
|
|
185
|
-
do {
|
|
186
|
-
const response = await this.#amplifyUiBuilder
|
|
187
|
-
.exportForms({
|
|
188
|
-
appId: resolvedAppId,
|
|
189
|
-
environmentName,
|
|
190
|
-
nextToken,
|
|
191
|
-
})
|
|
192
|
-
.promise();
|
|
193
|
-
uibuilderForms.push(...response.entities);
|
|
194
|
-
nextToken = response.nextToken;
|
|
195
|
-
} while (nextToken);
|
|
196
|
-
printer.debug(JSON.stringify(uibuilderForms, null, 2));
|
|
197
|
-
return { entities: uibuilderForms };
|
|
198
|
-
} catch (e) {
|
|
199
|
-
printer.debug(e);
|
|
200
|
-
throw e;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
createComponent = async (component: CreateComponentData, envName?: string, appId?: string): Promise<Component | undefined> => {
|
|
205
|
-
const environmentName = envName || this.#envName;
|
|
206
|
-
const resolvedAppId = appId || this.#appId;
|
|
207
|
-
try {
|
|
208
|
-
const response = await this.#amplifyUiBuilder
|
|
209
|
-
.createComponent({
|
|
210
|
-
appId: resolvedAppId,
|
|
211
|
-
environmentName,
|
|
212
|
-
componentToCreate: component,
|
|
213
|
-
})
|
|
214
|
-
.promise();
|
|
215
|
-
return response.entity;
|
|
216
|
-
} catch (err) {
|
|
217
|
-
printer.debug(err.toString());
|
|
218
|
-
throw err;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
101
|
+
* Returns all the UI Builder themes from the app
|
|
102
|
+
*/
|
|
103
|
+
listThemes = async (envName?: string, appId?: string): Promise<{ entities: Theme[] }> => {
|
|
104
|
+
const environmentName = envName || this.#envName;
|
|
105
|
+
const resolvedAppId = appId || this.#appId;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
let nextToken: string | undefined;
|
|
109
|
+
const uiBuilderThemes: Theme[] = [];
|
|
110
|
+
do {
|
|
111
|
+
const response = await this.#amplifyUiBuilder
|
|
112
|
+
.exportThemes({
|
|
113
|
+
appId: resolvedAppId,
|
|
114
|
+
environmentName,
|
|
115
|
+
nextToken,
|
|
116
|
+
})
|
|
117
|
+
.promise();
|
|
118
|
+
uiBuilderThemes.push(...response.entities);
|
|
119
|
+
nextToken = response.nextToken;
|
|
120
|
+
} while (nextToken);
|
|
121
|
+
printer.debug(JSON.stringify(uiBuilderThemes, null, 2));
|
|
122
|
+
return { entities: uiBuilderThemes };
|
|
123
|
+
} catch (e) {
|
|
124
|
+
printer.debug(e);
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
221
128
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
};
|
|
129
|
+
createComponent = async (component: CreateComponentData, envName?: string, appId?: string): Promise<Component | undefined> => {
|
|
130
|
+
const environmentName = envName || this.#envName;
|
|
131
|
+
const resolvedAppId = appId || this.#appId;
|
|
132
|
+
try {
|
|
133
|
+
const response = await this.#amplifyUiBuilder.createComponent({
|
|
134
|
+
appId: resolvedAppId,
|
|
135
|
+
environmentName,
|
|
136
|
+
componentToCreate: component,
|
|
137
|
+
}).promise();
|
|
138
|
+
return response.entity;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
printer.debug(err.toString());
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
239
144
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
145
|
+
getModels = async (resourceName: string, envName?: string, appId?: string): Promise<string | undefined> => {
|
|
146
|
+
try {
|
|
147
|
+
const environmentName = envName || this.#envName;
|
|
148
|
+
const resolvedAppId = appId || this.#appId;
|
|
149
|
+
const { Models } = await this.#amplifyBackend.getBackendAPIModels({
|
|
150
|
+
AppId: resolvedAppId,
|
|
151
|
+
BackendEnvironmentName: environmentName,
|
|
152
|
+
ResourceName: resourceName,
|
|
153
|
+
})
|
|
154
|
+
.promise();
|
|
155
|
+
return Models;
|
|
156
|
+
} catch (e) {
|
|
157
|
+
printer.debug(e);
|
|
158
|
+
throw new Error(`Models not found in AmplifyBackend:GetBackendAPIModels response: ${e.message}`);
|
|
159
|
+
}
|
|
243
160
|
}
|
|
244
161
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { StudioSchema } from '@aws-amplify/codegen-ui';
|
|
1
|
+
import { StudioComponent } from '@aws-amplify/codegen-ui';
|
|
3
2
|
import ora from 'ora';
|
|
4
3
|
import { printer } from 'amplify-prompts';
|
|
5
4
|
import { $TSContext } from 'amplify-cli-core';
|
|
@@ -11,8 +10,6 @@ import {
|
|
|
11
10
|
generateUiBuilderThemes,
|
|
12
11
|
getAmplifyDataSchema,
|
|
13
12
|
generateAmplifyUiBuilderIndexFile,
|
|
14
|
-
generateUiBuilderForms,
|
|
15
|
-
generateAmplifyUiBuilderUtilFile,
|
|
16
13
|
} from './utils';
|
|
17
14
|
|
|
18
15
|
/**
|
|
@@ -25,63 +22,36 @@ export const run = async (context: $TSContext): Promise<void> => {
|
|
|
25
22
|
const spinner = ora('');
|
|
26
23
|
try {
|
|
27
24
|
const studioClient = await AmplifyStudioClient.setClientInfo(context);
|
|
28
|
-
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const [componentSchemas, themeSchemas, formSchemas, dataSchema] = await Promise.all([
|
|
25
|
+
const [componentSchemas, themeSchemas, dataSchema] = await Promise.all([
|
|
32
26
|
studioClient.listComponents(),
|
|
33
27
|
studioClient.listThemes(),
|
|
34
|
-
studioClient.listForms(),
|
|
35
28
|
getAmplifyDataSchema(studioClient),
|
|
36
29
|
]);
|
|
37
|
-
|
|
38
|
-
const nothingWouldAutogen = !dataSchema || !studioClient.metadata.autoGenerateForms || !studioClient.isSupportedGraphQL;
|
|
39
|
-
|
|
40
|
-
if (nothingWouldAutogen && [componentSchemas, themeSchemas, formSchemas].every(group => !group.entities.length)) {
|
|
30
|
+
if (componentSchemas.entities.length === 0 && themeSchemas.entities.length === 0) {
|
|
41
31
|
printer.debug('Skipping UI component generation since none are found.');
|
|
42
32
|
return;
|
|
43
33
|
}
|
|
44
34
|
spinner.start('Generating UI components...');
|
|
35
|
+
const generatedComponentResults = generateUiBuilderComponents(context, componentSchemas.entities, dataSchema);
|
|
36
|
+
const generatedThemeResults = generateUiBuilderThemes(context, themeSchemas.entities);
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
context, formSchemas.entities, dataSchema, studioClient.metadata.autoGenerateForms && studioClient.isSupportedGraphQL,
|
|
51
|
-
),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const successfulSchemas: StudioSchema[] = [];
|
|
55
|
-
let hasSuccessfulForm = false;
|
|
56
|
-
const failedResponseNames: string[] = [];
|
|
38
|
+
generateAmplifyUiBuilderIndexFile(context, [
|
|
39
|
+
...generatedComponentResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ component }) => component),
|
|
40
|
+
...generatedThemeResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ theme }) => theme),
|
|
41
|
+
] as StudioComponent[]);
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (key === 'form') {
|
|
63
|
-
hasSuccessfulForm = true;
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
failedResponseNames.push(result.schemaName);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
generateAmplifyUiBuilderIndexFile(context, successfulSchemas);
|
|
72
|
-
|
|
73
|
-
generateAmplifyUiBuilderUtilFile(context, { hasForms: hasSuccessfulForm, hasViews: false });
|
|
43
|
+
const failedSchemas = [
|
|
44
|
+
...generatedComponentResults.filter(({ resultType }) => resultType === 'FAILURE').map(({ schemaName }) => schemaName),
|
|
45
|
+
...generatedThemeResults.filter(({ resultType }) => resultType === 'FAILURE').map(({ schemaName }) => schemaName),
|
|
46
|
+
];
|
|
74
47
|
|
|
75
|
-
if (
|
|
76
|
-
spinner.fail(`Failed to sync the following components: ${
|
|
48
|
+
if (failedSchemas.length > 0) {
|
|
49
|
+
spinner.fail(`Failed to sync the following components: ${failedSchemas.join(', ')}`);
|
|
77
50
|
} else {
|
|
78
51
|
spinner.succeed('Synced UI components.');
|
|
79
52
|
}
|
|
80
53
|
|
|
81
|
-
const invalidComponentNames =
|
|
82
|
-
...componentSchemas.entities.filter(component => !component.schemaVersion).map(component => component.name),
|
|
83
|
-
...formSchemas.entities.filter(form => !form.schemaVersion).map(form => form.name),
|
|
84
|
-
];
|
|
54
|
+
const invalidComponentNames = componentSchemas.entities.filter(component => !component.schemaVersion).map(component => component.name);
|
|
85
55
|
if (invalidComponentNames.length) {
|
|
86
56
|
printer.warn(
|
|
87
57
|
`The components ${invalidComponentNames.join(
|
package/src/commands/help.ts
CHANGED