@aws-amplify/amplify-util-uibuilder 1.3.0-rc.c36fa71f5.0 → 1.3.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 +14 -1
- package/lib/clients/amplify-studio-client.d.ts +17 -0
- package/lib/clients/amplify-studio-client.d.ts.map +1 -0
- package/lib/clients/amplify-studio-client.js +145 -0
- package/lib/clients/amplify-studio-client.js.map +1 -0
- package/lib/clients/index.d.ts +2 -0
- package/lib/clients/index.d.ts.map +1 -0
- package/lib/clients/index.js +9 -0
- package/lib/clients/index.js.map +1 -0
- package/lib/commands/cloneComponentsFromEnv.d.ts +1 -1
- package/lib/commands/cloneComponentsFromEnv.d.ts.map +1 -1
- package/lib/commands/cloneComponentsFromEnv.js +15 -31
- package/lib/commands/cloneComponentsFromEnv.js.map +1 -1
- package/lib/commands/generateComponents.d.ts.map +1 -1
- package/lib/commands/generateComponents.js +14 -12
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/utils/{createUiBuilderComponent.d.ts → codegenResources.d.ts} +5 -3
- package/lib/commands/utils/codegenResources.d.ts.map +1 -0
- package/lib/commands/utils/{createUiBuilderComponent.js → codegenResources.js} +26 -4
- package/lib/commands/utils/codegenResources.js.map +1 -0
- package/lib/commands/utils/environmentHelpers.d.ts +5 -0
- package/lib/commands/utils/environmentHelpers.d.ts.map +1 -0
- package/lib/commands/utils/environmentHelpers.js +25 -0
- package/lib/commands/utils/environmentHelpers.js.map +1 -0
- package/lib/commands/utils/index.d.ts +8 -0
- package/lib/commands/utils/index.d.ts.map +1 -0
- package/lib/commands/utils/index.js +20 -0
- package/lib/commands/utils/index.js.map +1 -0
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +9 -18
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +8 -80
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/package.json +14 -6
- package/src/__tests__/cloneComponentsFromEnv.test.ts +33 -26
- package/src/__tests__/createUiBuilderComponent.test.ts +14 -13
- package/src/__tests__/generateComponents.test.ts +40 -30
- package/src/__tests__/getAmplifyDataSchema.test.ts +102 -0
- package/src/__tests__/syncAmplifyUiComponents.test.ts +55 -33
- package/src/clients/amplify-studio-client.ts +161 -0
- package/src/clients/index.ts +1 -0
- package/src/commands/cloneComponentsFromEnv.ts +26 -29
- package/src/commands/generateComponents.ts +19 -12
- package/src/commands/utils/{createUiBuilderComponent.ts → codegenResources.ts} +39 -11
- package/src/commands/utils/environmentHelpers.ts +32 -0
- package/src/commands/utils/index.ts +7 -0
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +38 -81
- package/src/index.ts +15 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/utils/amplifyUiBuilderService.d.ts +0 -5
- package/lib/commands/utils/amplifyUiBuilderService.d.ts.map +0 -1
- package/lib/commands/utils/amplifyUiBuilderService.js +0 -20
- package/lib/commands/utils/amplifyUiBuilderService.js.map +0 -1
- package/lib/commands/utils/createUiBuilderComponent.d.ts.map +0 -1
- package/lib/commands/utils/createUiBuilderComponent.js.map +0 -1
- package/src/commands/utils/amplifyUiBuilderService.ts +0 -22
|
@@ -1,86 +1,29 @@
|
|
|
1
|
-
import { getAmplifyUIBuilderService, Component, Theme } from './amplifyUiBuilderService';
|
|
2
1
|
import { printer } from 'amplify-prompts';
|
|
3
|
-
import { createUiBuilderComponent, createUiBuilderTheme } from './createUiBuilderComponent';
|
|
4
|
-
import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
|
|
5
|
-
import { extractArgs } from './extractArgs';
|
|
6
2
|
import { $TSContext } from 'amplify-cli-core';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const resolveAppId = async (context: $TSContext) => {
|
|
13
|
-
return await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'resolveAppId', [context]);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const getAppId = async (context: $TSContext) => {
|
|
17
|
-
const appId = extractArgs(context).appId || (await resolveAppId(context));
|
|
18
|
-
|
|
19
|
-
if (!appId) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
'Unable to sync Studio components since appId could not be determined. This can happen when you hit the soft limit of number of apps that you can have in Amplify console.',
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return appId;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export async function listUiBuilderComponents(context: $TSContext, envName?: string): Promise<{ entities: Component[] }> {
|
|
28
|
-
const environmentName = getEnvName(context, envName);
|
|
29
|
-
const appId = await getAppId(context);
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const amplifyUIBuilder = await getAmplifyUIBuilderService(context, environmentName, appId);
|
|
33
|
-
let nextToken: string | undefined;
|
|
34
|
-
const uiBuilderComponents: Component[] = [];
|
|
35
|
-
do {
|
|
36
|
-
const response = await amplifyUIBuilder
|
|
37
|
-
.exportComponents({
|
|
38
|
-
appId,
|
|
39
|
-
environmentName,
|
|
40
|
-
nextToken
|
|
41
|
-
})
|
|
42
|
-
.promise();
|
|
43
|
-
uiBuilderComponents.push(...response.entities);
|
|
44
|
-
nextToken = response.nextToken;
|
|
45
|
-
} while (nextToken);
|
|
46
|
-
printer.debug(JSON.stringify(uiBuilderComponents, null, 2));
|
|
47
|
-
return { entities: uiBuilderComponents };
|
|
48
|
-
} catch (e) {
|
|
49
|
-
printer.debug(e);
|
|
50
|
-
throw e;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function listUiBuilderThemes(context: $TSContext, envName?: string): Promise<{ entities: Theme[] }> {
|
|
55
|
-
const environmentName = getEnvName(context, envName);
|
|
56
|
-
const appId = await getAppId(context);
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const amplifyUIBuilder = await getAmplifyUIBuilderService(context, environmentName, appId);
|
|
60
|
-
let nextToken: string | undefined;
|
|
61
|
-
const uiBuilderThemes: Theme[] = [];
|
|
62
|
-
do {
|
|
63
|
-
const response = await amplifyUIBuilder
|
|
64
|
-
.exportThemes({
|
|
65
|
-
appId,
|
|
66
|
-
environmentName,
|
|
67
|
-
})
|
|
68
|
-
.promise();
|
|
69
|
-
uiBuilderThemes.push(...response.entities);
|
|
70
|
-
nextToken = response.nextToken;
|
|
71
|
-
} while (nextToken);
|
|
72
|
-
printer.debug(JSON.stringify(uiBuilderThemes, null, 2));
|
|
73
|
-
return { entities: uiBuilderThemes };
|
|
74
|
-
} catch (e) {
|
|
75
|
-
printer.debug(e);
|
|
76
|
-
throw e;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
3
|
+
import {
|
|
4
|
+
StudioComponent, StudioTheme, GenericDataSchema,
|
|
5
|
+
} from '@aws-amplify/codegen-ui';
|
|
6
|
+
import { createUiBuilderComponent, createUiBuilderTheme } from './codegenResources';
|
|
7
|
+
import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
|
|
79
8
|
|
|
80
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Returns instances of StudioComponent from the component schemas
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
export const generateUiBuilderComponents = (context: $TSContext, componentSchemas: any[], dataSchema?: GenericDataSchema): ({
|
|
14
|
+
resultType: string;
|
|
15
|
+
component: StudioComponent;
|
|
16
|
+
schemaName?: undefined;
|
|
17
|
+
error?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
resultType: string;
|
|
20
|
+
schemaName: string;
|
|
21
|
+
error: Error;
|
|
22
|
+
component?: undefined;
|
|
23
|
+
})[] => {
|
|
81
24
|
const componentResults = componentSchemas.map(schema => {
|
|
82
25
|
try {
|
|
83
|
-
const component = createUiBuilderComponent(context, schema);
|
|
26
|
+
const component = createUiBuilderComponent(context, schema, dataSchema);
|
|
84
27
|
return { resultType: 'SUCCESS', component };
|
|
85
28
|
} catch (e) {
|
|
86
29
|
printer.debug(`Failure caught processing ${schema.name}`);
|
|
@@ -95,9 +38,23 @@ export function generateUiBuilderComponents(context: $TSContext, componentSchema
|
|
|
95
38
|
)}`,
|
|
96
39
|
);
|
|
97
40
|
return componentResults;
|
|
98
|
-
}
|
|
41
|
+
};
|
|
99
42
|
|
|
100
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Returns instances of StudioTheme from theme schemas
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]): ({
|
|
48
|
+
resultType: string;
|
|
49
|
+
theme: StudioTheme;
|
|
50
|
+
schemaName?: undefined;
|
|
51
|
+
error?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
resultType: string;
|
|
54
|
+
schemaName: string;
|
|
55
|
+
error: Error;
|
|
56
|
+
theme?: undefined;
|
|
57
|
+
})[] => {
|
|
101
58
|
const themeResults = themeSchemas.map(schema => {
|
|
102
59
|
try {
|
|
103
60
|
const theme = createUiBuilderTheme(context, schema);
|
|
@@ -113,4 +70,4 @@ export function generateUiBuilderThemes(context: $TSContext, themeSchemas: any[]
|
|
|
113
70
|
`Generated ${themeResults.filter(result => result.resultType === 'SUCCESS').length} themes in ${getUiBuilderComponentsPath(context)}`,
|
|
114
71
|
);
|
|
115
72
|
return themeResults;
|
|
116
|
-
}
|
|
73
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { $TSContext } from 'amplify-cli-core';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// TODO: remove dynamic require
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* executes main amplify command into uibuilder
|
|
8
|
+
*/
|
|
9
|
+
export const executeAmplifyCommand = async (context: $TSContext, cmd: string): Promise<void> => {
|
|
5
10
|
const commandsDirPath = path.normalize(path.join(__dirname, 'commands'));
|
|
6
|
-
const commandPath = path.join(commandsDirPath, cmd
|
|
11
|
+
const commandPath = path.join(commandsDirPath, cmd || context.input.command);
|
|
12
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
|
|
7
13
|
const commandModule = require(commandPath);
|
|
8
14
|
await commandModule.run(context);
|
|
9
|
-
}
|
|
15
|
+
};
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
/**
|
|
18
|
+
* runs event based command
|
|
19
|
+
*/
|
|
20
|
+
export const handleAmplifyEvent = async (context: $TSContext, { event }: { event: string }): Promise<void> => {
|
|
12
21
|
const eventHandlersDirPath = path.normalize(path.join(__dirname, 'event-handlers'));
|
|
13
22
|
const eventHandlerPath = path.join(eventHandlersDirPath, `handle-${event}`);
|
|
23
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
|
|
14
24
|
const eventHandlerModule = require(eventHandlerPath);
|
|
15
25
|
await eventHandlerModule.run(context);
|
|
16
|
-
}
|
|
26
|
+
};
|