@aws-amplify/amplify-util-uibuilder 1.2.20-optimize-pipeline-2.0 → 1.2.21-beta.1

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/lib/commands/cloneComponentsFromEnv.d.ts.map +1 -1
  3. package/lib/commands/cloneComponentsFromEnv.js +2 -16
  4. package/lib/commands/cloneComponentsFromEnv.js.map +1 -1
  5. package/lib/commands/generateComponents.d.ts +1 -1
  6. package/lib/commands/generateComponents.d.ts.map +1 -1
  7. package/lib/commands/generateComponents.js +9 -8
  8. package/lib/commands/generateComponents.js.map +1 -1
  9. package/lib/commands/utils/amplifyUiBuilderService.d.ts +5 -0
  10. package/lib/commands/utils/amplifyUiBuilderService.d.ts.map +1 -0
  11. package/lib/commands/utils/amplifyUiBuilderService.js +20 -0
  12. package/lib/commands/utils/amplifyUiBuilderService.js.map +1 -0
  13. package/lib/commands/utils/createUiBuilderComponent.d.ts +3 -4
  14. package/lib/commands/utils/createUiBuilderComponent.d.ts.map +1 -1
  15. package/lib/commands/utils/createUiBuilderComponent.js +12 -20
  16. package/lib/commands/utils/createUiBuilderComponent.js.map +1 -1
  17. package/lib/commands/utils/notifyMissingPackages.d.ts +1 -2
  18. package/lib/commands/utils/notifyMissingPackages.d.ts.map +1 -1
  19. package/lib/commands/utils/notifyMissingPackages.js +4 -13
  20. package/lib/commands/utils/notifyMissingPackages.js.map +1 -1
  21. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +9 -6
  22. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
  23. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +31 -36
  24. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
  25. package/package.json +10 -10
  26. package/src/__tests__/createUiBuilderComponent.test.ts +2 -2
  27. package/src/__tests__/generateComponents.test.ts +2 -0
  28. package/src/__tests__/notifyMissingPackages.test.ts +4 -4
  29. package/src/__tests__/syncAmplifyUiComponents.test.ts +1 -1
  30. package/src/commands/cloneComponentsFromEnv.ts +3 -17
  31. package/src/commands/generateComponents.ts +16 -11
  32. package/src/commands/utils/amplifyUiBuilderService.ts +22 -0
  33. package/src/commands/utils/createUiBuilderComponent.ts +44 -21
  34. package/src/commands/utils/notifyMissingPackages.ts +12 -16
  35. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +22 -27
  36. package/tsconfig.json +7 -7
  37. package/tsconfig.tsbuildinfo +1 -1
  38. package/lib/commands/utils/createUiBuilderComponentNew.d.ts +0 -5
  39. package/lib/commands/utils/createUiBuilderComponentNew.d.ts.map +0 -1
  40. package/lib/commands/utils/createUiBuilderComponentNew.js +0 -44
  41. package/lib/commands/utils/createUiBuilderComponentNew.js.map +0 -1
  42. package/src/commands/utils/createUiBuilderComponentNew.ts +0 -53
@@ -5,10 +5,10 @@ import {
5
5
  getAppId,
6
6
  listUiBuilderComponents,
7
7
  listUiBuilderThemes,
8
- getAmplifyUIBuilderService,
9
8
  resolveAppId,
10
9
  generateUiBuilderThemes,
11
10
  } from '../commands/utils/syncAmplifyUiBuilderComponents';
11
+ import { getAmplifyUIBuilderService } from '../commands/utils/amplifyUiBuilderService'
12
12
  import aws from 'aws-sdk';
13
13
  import * as CLICore from 'amplify-cli-core';
14
14
  import * as createUiBuilderComponentDependency from '../commands/utils/createUiBuilderComponent';
@@ -1,8 +1,8 @@
1
- import aws from 'aws-sdk';
2
1
  import { extractArgs } from './utils/extractArgs';
3
2
  import { listUiBuilderComponents } from './utils/syncAmplifyUiBuilderComponents';
4
3
  import { printer } from 'amplify-prompts';
5
- import { $TSAny, $TSContext } from 'amplify-cli-core';
4
+ import { $TSContext } from 'amplify-cli-core';
5
+ import { getAmplifyUIBuilderService } from './utils/amplifyUiBuilderService';
6
6
 
7
7
  export async function run(context: $TSContext) {
8
8
  printer.debug('Running create components command in amplify-util-uibuilder');
@@ -26,21 +26,7 @@ export async function run(context: $TSContext) {
26
26
 
27
27
  const environmentName = args.environmentName ?? context.exeInfo.localEnvInfo.envName;
28
28
  const appId = args.appId ?? context.exeInfo.teamProviderInfo[environmentName].awscloudformation.AmplifyAppId;
29
- const awsConfigInfo = (await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'loadConfigurationForEnv', [
30
- context,
31
- newEnvName,
32
- appId,
33
- ])) as $TSAny;
34
-
35
- if (process.env.UI_BUILDER_ENDPOINT) {
36
- awsConfigInfo.endpoint = process.env.UI_BUILDER_ENDPOINT;
37
- }
38
-
39
- if (process.env.UI_BUILDER_REGION) {
40
- awsConfigInfo.region = process.env.UI_BUILDER_REGION;
41
- }
42
-
43
- const amplifyUIBuilder = new aws.AmplifyUIBuilder(awsConfigInfo);
29
+ const amplifyUIBuilder = await getAmplifyUIBuilderService(context, environmentName, appId);
44
30
  const components = existingComponents.entities;
45
31
  if (!components.length) {
46
32
  printer.debug(`No UIBuilder components found in app ${appId} from env ${sourceEnvName}. Skipping component clone process.`);
@@ -1,3 +1,7 @@
1
+ import { StudioComponent } from '@aws-amplify/codegen-ui';
2
+ import { printer } from 'amplify-prompts';
3
+ import ora from 'ora';
4
+ import { $TSContext } from 'amplify-cli-core';
1
5
  import { notifyMissingPackages } from './utils/notifyMissingPackages';
2
6
  import { shouldRenderComponents } from './utils/shouldRenderComponents';
3
7
  import {
@@ -6,13 +10,12 @@ import {
6
10
  generateUiBuilderComponents,
7
11
  generateUiBuilderThemes,
8
12
  } from './utils/syncAmplifyUiBuilderComponents';
9
- import { StudioComponent as StudioComponentNew } from '@aws-amplify/codegen-ui-new';
10
13
  import { generateAmplifyUiBuilderIndexFile } from './utils/createUiBuilderComponent';
11
- import { printer } from 'amplify-prompts';
12
- import ora from 'ora';
13
- import { $TSContext } from 'amplify-cli-core';
14
14
 
15
- export async function run(context: $TSContext) {
15
+ /**
16
+ * Pulls ui components from Studio backend and generates the code in the user's file system
17
+ */
18
+ export const run = async (context: $TSContext): Promise<void> => {
16
19
  printer.debug('Running generate components command in amplify-util-uibuilder');
17
20
  if (!(await shouldRenderComponents(context))) {
18
21
  return;
@@ -32,7 +35,7 @@ export async function run(context: $TSContext) {
32
35
  generateAmplifyUiBuilderIndexFile(context, [
33
36
  ...generatedComponentResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ component }) => component),
34
37
  ...generatedThemeResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ theme }) => theme),
35
- ] as StudioComponentNew[]);
38
+ ] as StudioComponent[]);
36
39
 
37
40
  const failedSchemas = [
38
41
  ...generatedComponentResults.filter(({ resultType }) => resultType === 'FAILURE').map(({ schemaName }) => schemaName),
@@ -45,12 +48,14 @@ export async function run(context: $TSContext) {
45
48
  spinner.succeed('Synced UI components.');
46
49
  }
47
50
 
48
- notifyMissingPackages(context, [
49
- ...generatedComponentResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ component }) => component),
50
- ...generatedThemeResults.filter(({ resultType }) => resultType === 'SUCCESS').map(({ theme }) => theme),
51
- ] as StudioComponentNew[]);
51
+ const invalidComponentNames = componentSchemas.entities.filter(component => !component.schemaVersion).map(component => component.name);
52
+ if (invalidComponentNames.length) {
53
+ printer.warn(`The components ${invalidComponentNames.join(', ')} were synced with an older version of Amplify Studio. Please re-sync your components with Figma to get latest features and changes.`);
54
+ }
55
+
56
+ notifyMissingPackages(context);
52
57
  } catch (e) {
53
58
  printer.debug(e);
54
59
  spinner.fail('Failed to sync UI components');
55
60
  }
56
- }
61
+ };
@@ -0,0 +1,22 @@
1
+ import { AmplifyUIBuilder } from 'aws-sdk';
2
+ import { $TSContext, $TSAny } from 'amplify-cli-core';
3
+
4
+ export { Component, Theme } from 'aws-sdk/clients/amplifyuibuilder';
5
+
6
+ export const getAmplifyUIBuilderService = async (context: $TSContext, environmentName: string, appId: string): Promise<AmplifyUIBuilder> => {
7
+ const awsConfigInfo = (await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'loadConfigurationForEnv', [
8
+ context,
9
+ environmentName,
10
+ appId,
11
+ ])) as $TSAny;
12
+
13
+ if (process.env.UI_BUILDER_ENDPOINT) {
14
+ awsConfigInfo.endpoint = process.env.UI_BUILDER_ENDPOINT;
15
+ }
16
+
17
+ if (process.env.UI_BUILDER_REGION) {
18
+ awsConfigInfo.region = process.env.UI_BUILDER_REGION;
19
+ }
20
+
21
+ return new AmplifyUIBuilder(awsConfigInfo);
22
+ };
@@ -1,18 +1,25 @@
1
- import { StudioTemplateRendererManager, StudioComponent, StudioTemplateRendererFactory, StudioTemplateRenderer, FrameworkOutputManager, RenderTextComponentResponse } from '@aws-amplify/codegen-ui-old';
1
+ import {
2
+ StudioTemplateRendererManager,
3
+ StudioComponent,
4
+ StudioTheme,
5
+ StudioTemplateRendererFactory,
6
+ StudioTemplateRenderer,
7
+ FrameworkOutputManager,
8
+ RenderTextComponentResponse,
9
+ } from '@aws-amplify/codegen-ui';
2
10
  import {
3
11
  AmplifyRenderer,
4
12
  ReactThemeStudioTemplateRenderer,
13
+ ReactIndexStudioTemplateRenderer,
5
14
  ModuleKind,
6
15
  ScriptTarget,
7
16
  ScriptKind,
8
- } from '@aws-amplify/codegen-ui-react-old';
17
+ } from '@aws-amplify/codegen-ui-react';
9
18
 
10
- import {StudioComponent as StudioComponentNew, StudioTheme} from '@aws-amplify/codegen-ui-new';
11
- import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
12
19
  import { printer } from 'amplify-prompts';
13
20
  import { $TSContext } from 'amplify-cli-core';
14
- import { createUiBuilderComponent as createUiBuilderComponentNew } from './createUiBuilderComponentNew';
15
- import { ReactIndexStudioTemplateRenderer } from '@aws-amplify/codegen-ui-react-new';
21
+ import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
22
+
16
23
  const config = {
17
24
  module: ModuleKind.ES2020,
18
25
  target: ScriptTarget.ES2020,
@@ -20,18 +27,13 @@ const config = {
20
27
  renderTypeDeclarations: true,
21
28
  };
22
29
 
23
- const isUpdatedSchema = (schema: StudioComponent) => {
24
- return (schema as unknown as StudioComponentNew).schemaVersion && (schema as unknown as StudioComponentNew).schemaVersion === '1.0';
25
- };
26
-
27
- export const createUiBuilderComponent = (context: $TSContext, schema: StudioComponent) => {
28
- if (isUpdatedSchema(schema)) {
29
- return createUiBuilderComponentNew(context, schema as unknown as StudioComponentNew);
30
- }
30
+ /**
31
+ * Writes component file to the work space
32
+ */
33
+ export const createUiBuilderComponent = (context: $TSContext, schema: StudioComponent): StudioComponent => {
31
34
  const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
32
35
  const rendererFactory = new StudioTemplateRendererFactory(
33
- (component: StudioComponent) =>
34
- new AmplifyRenderer(component as StudioComponent, config) as unknown as StudioTemplateRenderer<
36
+ (component: StudioComponent) => new AmplifyRenderer(component as StudioComponent, config) as unknown as StudioTemplateRenderer<
35
37
  unknown,
36
38
  StudioComponent,
37
39
  FrameworkOutputManager<unknown>,
@@ -49,9 +51,19 @@ export const createUiBuilderComponent = (context: $TSContext, schema: StudioComp
49
51
  return schema;
50
52
  };
51
53
 
52
- export const createUiBuilderTheme = (context: $TSContext, schema: StudioTheme) => {
54
+ /**
55
+ * Writes theme file to the work space
56
+ */
57
+ export const createUiBuilderTheme = (context: $TSContext, schema: StudioTheme): StudioTheme => {
53
58
  const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
54
- const rendererFactory = new StudioTemplateRendererFactory((component: StudioTheme) => new ReactThemeStudioTemplateRenderer(component, config) as unknown as StudioTemplateRenderer<unknown, StudioTheme, FrameworkOutputManager<unknown>, RenderTextComponentResponse>);
59
+ const rendererFactory = new StudioTemplateRendererFactory(
60
+ (component: StudioTheme) => new ReactThemeStudioTemplateRenderer(component, config) as unknown as StudioTemplateRenderer<
61
+ unknown,
62
+ StudioTheme,
63
+ FrameworkOutputManager<unknown>,
64
+ RenderTextComponentResponse
65
+ >,
66
+ );
55
67
 
56
68
  const outputPathDir = uiBuilderComponentsPath;
57
69
 
@@ -70,9 +82,19 @@ export const createUiBuilderTheme = (context: $TSContext, schema: StudioTheme) =
70
82
  }
71
83
  };
72
84
 
73
- export const generateAmplifyUiBuilderIndexFile = (context: $TSContext, schemas: StudioComponentNew[]) => {
85
+ /**
86
+ * Writes index file to the work space
87
+ */
88
+ export const generateAmplifyUiBuilderIndexFile = (context: $TSContext, schemas: StudioComponent[]): RenderTextComponentResponse => {
74
89
  const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
75
- const rendererFactory = new StudioTemplateRendererFactory((component: StudioComponentNew[]) => new ReactIndexStudioTemplateRenderer(component, config) as unknown as StudioTemplateRenderer<unknown, StudioComponentNew[], FrameworkOutputManager<unknown>, RenderTextComponentResponse>);
90
+ const rendererFactory = new StudioTemplateRendererFactory(
91
+ (component: StudioComponent[]) => new ReactIndexStudioTemplateRenderer(component, config) as unknown as StudioTemplateRenderer<
92
+ unknown,
93
+ StudioComponent[],
94
+ FrameworkOutputManager<unknown>,
95
+ RenderTextComponentResponse
96
+ >,
97
+ );
76
98
 
77
99
  const outputPathDir = uiBuilderComponentsPath;
78
100
 
@@ -86,4 +108,5 @@ export const generateAmplifyUiBuilderIndexFile = (context: $TSContext, schemas:
86
108
  printer.debug(e);
87
109
  printer.debug('Failed to generate component index file');
88
110
  throw e;
89
- }};
111
+ }
112
+ };
@@ -1,25 +1,21 @@
1
- import { pathManager, JSONUtilities, $TSContext, $TSAny } from 'amplify-cli-core';
1
+ import {
2
+ pathManager, JSONUtilities, $TSContext, $TSAny,
3
+ } from 'amplify-cli-core';
2
4
  import { printer } from 'amplify-prompts';
3
5
  import fs from 'fs-extra';
4
6
  import path from 'path';
5
7
  import rangeSubset from 'semver/ranges/subset';
8
+ import { RequiredDependency } from '@aws-amplify/codegen-ui';
9
+ import { ReactRequiredDependencyProvider } from '@aws-amplify/codegen-ui-react';
6
10
  import { extractArgs } from './extractArgs';
7
- import { ReactRequiredDependencyProvider } from '@aws-amplify/codegen-ui-react-old';
8
- import { ReactRequiredDependencyProvider as ReactRequiredDependencyProviderNew } from '@aws-amplify/codegen-ui-react-new';
9
- import { StudioComponent } from '@aws-amplify/codegen-ui-new';
10
11
 
11
- const isUpdatedSchema = (schemas: StudioComponent[]) => {
12
- return schemas.some(schema => schema.schemaVersion && schema.schemaVersion === '1.0');
13
- };
14
-
15
- const getRequiredDependencies = (schemas: StudioComponent[]) => {
16
- if (isUpdatedSchema(schemas)) {
17
- return new ReactRequiredDependencyProviderNew().getRequiredDependencies();
18
- }
19
- return new ReactRequiredDependencyProvider().getRequiredDependencies();
20
- };
12
+ const getRequiredDependencies = (): RequiredDependency[] => new ReactRequiredDependencyProvider().getRequiredDependencies();
21
13
 
22
- export const notifyMissingPackages = (context: $TSContext, schemas: StudioComponent[]) => {
14
+ /**
15
+ * Displays a warning to the user if they have npm dependencies
16
+ * they need to install in their application for UIBuilder components to work properly
17
+ */
18
+ export const notifyMissingPackages = (context: $TSContext): void => {
23
19
  const args = extractArgs(context);
24
20
  const localEnvFilePath = args.localEnvFilePath ?? pathManager.getLocalEnvFilePath();
25
21
  if (!fs.existsSync(localEnvFilePath)) {
@@ -33,7 +29,7 @@ export const notifyMissingPackages = (context: $TSContext, schemas: StudioCompon
33
29
  return;
34
30
  }
35
31
  const packageJson = JSONUtilities.readJson(packageJsonPath) as { dependencies: { [key: string]: string } };
36
- getRequiredDependencies(schemas).forEach((dependency: $TSAny) => {
32
+ getRequiredDependencies().forEach((dependency: $TSAny) => {
37
33
  const packageIsInstalled = Object.keys(packageJson.dependencies).includes(dependency.dependencyName);
38
34
  if (!packageIsInstalled) {
39
35
  printer.warn(
@@ -1,9 +1,9 @@
1
- import aws from 'aws-sdk';
1
+ import { getAmplifyUIBuilderService, Component, Theme } from './amplifyUiBuilderService';
2
2
  import { printer } from 'amplify-prompts';
3
3
  import { createUiBuilderComponent, createUiBuilderTheme } from './createUiBuilderComponent';
4
4
  import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
5
5
  import { extractArgs } from './extractArgs';
6
- import { $TSAny, $TSContext } from 'amplify-cli-core';
6
+ import { $TSContext } from 'amplify-cli-core';
7
7
  export const getEnvName = (context: $TSContext, envName?: string) => {
8
8
  const args = extractArgs(context);
9
9
  return envName ? envName : args.environmentName ? args.environmentName : context.exeInfo.localEnvInfo.envName;
@@ -24,40 +24,53 @@ export const getAppId = async (context: $TSContext) => {
24
24
  return appId;
25
25
  };
26
26
 
27
- export async function listUiBuilderComponents(context: $TSContext, envName?: string) {
27
+ export async function listUiBuilderComponents(context: $TSContext, envName?: string): Promise<{ entities: Component[] }> {
28
28
  const environmentName = getEnvName(context, envName);
29
29
  const appId = await getAppId(context);
30
30
 
31
31
  try {
32
32
  const amplifyUIBuilder = await getAmplifyUIBuilderService(context, environmentName, appId);
33
- const uiBuilderComponents = await amplifyUIBuilder
33
+ let nextToken: string | undefined;
34
+ const uiBuilderComponents: Component[] = [];
35
+ do {
36
+ const response = await amplifyUIBuilder
34
37
  .exportComponents({
35
38
  appId,
36
39
  environmentName,
40
+ nextToken
37
41
  })
38
42
  .promise();
43
+ uiBuilderComponents.push(...response.entities);
44
+ nextToken = response.nextToken;
45
+ } while (nextToken);
39
46
  printer.debug(JSON.stringify(uiBuilderComponents, null, 2));
40
- return uiBuilderComponents;
47
+ return { entities: uiBuilderComponents };
41
48
  } catch (e) {
42
49
  printer.debug(e);
43
50
  throw e;
44
51
  }
45
52
  }
46
53
 
47
- export async function listUiBuilderThemes(context: $TSContext, envName?: string) {
54
+ export async function listUiBuilderThemes(context: $TSContext, envName?: string): Promise<{ entities: Theme[] }> {
48
55
  const environmentName = getEnvName(context, envName);
49
56
  const appId = await getAppId(context);
50
57
 
51
58
  try {
52
59
  const amplifyUIBuilder = await getAmplifyUIBuilderService(context, environmentName, appId);
53
- const uiBuilderThemes = await amplifyUIBuilder
60
+ let nextToken: string | undefined;
61
+ const uiBuilderThemes: Theme[] = [];
62
+ do {
63
+ const response = await amplifyUIBuilder
54
64
  .exportThemes({
55
65
  appId,
56
66
  environmentName,
57
67
  })
58
68
  .promise();
69
+ uiBuilderThemes.push(...response.entities);
70
+ nextToken = response.nextToken;
71
+ } while (nextToken);
59
72
  printer.debug(JSON.stringify(uiBuilderThemes, null, 2));
60
- return uiBuilderThemes;
73
+ return { entities: uiBuilderThemes };
61
74
  } catch (e) {
62
75
  printer.debug(e);
63
76
  throw e;
@@ -100,22 +113,4 @@ export function generateUiBuilderThemes(context: $TSContext, themeSchemas: any[]
100
113
  `Generated ${themeResults.filter(result => result.resultType === 'SUCCESS').length} themes in ${getUiBuilderComponentsPath(context)}`,
101
114
  );
102
115
  return themeResults;
103
- }
104
-
105
- export const getAmplifyUIBuilderService = async (context: $TSContext, environmentName: string, appId: string) => {
106
- const awsConfigInfo = (await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'loadConfigurationForEnv', [
107
- context,
108
- environmentName,
109
- appId,
110
- ])) as $TSAny;
111
-
112
- if (process.env.UI_BUILDER_ENDPOINT) {
113
- awsConfigInfo.endpoint = process.env.UI_BUILDER_ENDPOINT;
114
- }
115
-
116
- if (process.env.UI_BUILDER_REGION) {
117
- awsConfigInfo.region = process.env.UI_BUILDER_REGION;
118
- }
119
-
120
- return new aws.AmplifyUIBuilder(awsConfigInfo);
121
- };
116
+ }
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "rootDir": "./src",
6
- "strict": true,
7
- "skipLibCheck": true
8
- }
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "strict": true,
7
+ "skipLibCheck": true
9
8
  }
9
+ }