@aws-amplify/amplify-util-uibuilder 1.2.16-pin-codegen-dependency.0 → 1.2.16

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 (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/lib/commands/generateComponents.d.ts +1 -1
  3. package/lib/commands/generateComponents.d.ts.map +1 -1
  4. package/lib/commands/generateComponents.js +8 -9
  5. package/lib/commands/generateComponents.js.map +1 -1
  6. package/lib/commands/utils/createUiBuilderComponent.d.ts +4 -3
  7. package/lib/commands/utils/createUiBuilderComponent.d.ts.map +1 -1
  8. package/lib/commands/utils/createUiBuilderComponent.js +20 -12
  9. package/lib/commands/utils/createUiBuilderComponent.js.map +1 -1
  10. package/lib/commands/utils/createUiBuilderComponentNew.d.ts +5 -0
  11. package/lib/commands/utils/createUiBuilderComponentNew.d.ts.map +1 -0
  12. package/lib/commands/utils/createUiBuilderComponentNew.js +44 -0
  13. package/lib/commands/utils/createUiBuilderComponentNew.js.map +1 -0
  14. package/lib/commands/utils/notifyMissingPackages.d.ts +2 -1
  15. package/lib/commands/utils/notifyMissingPackages.d.ts.map +1 -1
  16. package/lib/commands/utils/notifyMissingPackages.js +13 -4
  17. package/lib/commands/utils/notifyMissingPackages.js.map +1 -1
  18. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +2 -2
  19. package/package.json +12 -10
  20. package/src/__tests__/createUiBuilderComponent.test.ts +2 -2
  21. package/src/__tests__/generateComponents.test.ts +0 -2
  22. package/src/__tests__/notifyMissingPackages.test.ts +4 -4
  23. package/src/commands/generateComponents.ts +11 -16
  24. package/src/commands/utils/createUiBuilderComponent.ts +21 -44
  25. package/src/commands/utils/createUiBuilderComponentNew.ts +53 -0
  26. package/src/commands/utils/notifyMissingPackages.ts +16 -12
  27. package/tsconfig.json +7 -7
  28. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,53 @@
1
+ import { StudioTemplateRendererManager, StudioTemplateRendererFactory, StudioComponent, StudioTheme, StudioTemplateRenderer, FrameworkOutputManager, RenderTextComponentResponse } from '@aws-amplify/codegen-ui-new';
2
+ import {
3
+ AmplifyRenderer,
4
+ ReactThemeStudioTemplateRenderer,
5
+ ReactIndexStudioTemplateRenderer,
6
+ ModuleKind,
7
+ ScriptTarget,
8
+ ScriptKind,
9
+ } from '@aws-amplify/codegen-ui-react-new';
10
+ import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
11
+ import { printer } from 'amplify-prompts';
12
+ import { $TSContext } from 'amplify-cli-core';
13
+ const config = {
14
+ module: ModuleKind.ES2020,
15
+ target: ScriptTarget.ES2020,
16
+ script: ScriptKind.JSX,
17
+ renderTypeDeclarations: true,
18
+ };
19
+
20
+ export const createUiBuilderComponent = (context: $TSContext, schema: StudioComponent) => {
21
+ const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
22
+ const rendererFactory = new StudioTemplateRendererFactory((component: StudioComponent) => new AmplifyRenderer(component, config) as unknown as StudioTemplateRenderer<unknown, StudioComponent, FrameworkOutputManager<unknown>, RenderTextComponentResponse>);
23
+
24
+ const outputPathDir = uiBuilderComponentsPath;
25
+
26
+ const rendererManager = new StudioTemplateRendererManager(rendererFactory, {
27
+ outputPathDir,
28
+ });
29
+
30
+ rendererManager.renderSchemaToTemplate(schema);
31
+ return schema;
32
+ };
33
+
34
+ export const createUiBuilderTheme = (context: $TSContext, schema: StudioTheme) => {
35
+ const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
36
+ const rendererFactory = new StudioTemplateRendererFactory((component: StudioTheme) => new ReactThemeStudioTemplateRenderer(component, config) as unknown as StudioTemplateRenderer<unknown, StudioTheme, FrameworkOutputManager<unknown>, RenderTextComponentResponse>);
37
+
38
+ const outputPathDir = uiBuilderComponentsPath;
39
+
40
+ const rendererManager = new StudioTemplateRendererManager(rendererFactory, {
41
+ outputPathDir,
42
+ });
43
+
44
+ try {
45
+ rendererManager.renderSchemaToTemplate(schema);
46
+ return schema;
47
+ } catch (e) {
48
+ printer.debug(e);
49
+ printer.debug('Skipping invalid theme with schema');
50
+ printer.debug(JSON.stringify(schema, null, 2));
51
+ throw e;
52
+ }
53
+ };
@@ -1,21 +1,25 @@
1
- import {
2
- pathManager, JSONUtilities, $TSContext, $TSAny,
3
- } from 'amplify-cli-core';
1
+ import { pathManager, JSONUtilities, $TSContext, $TSAny } from 'amplify-cli-core';
4
2
  import { printer } from 'amplify-prompts';
5
3
  import fs from 'fs-extra';
6
4
  import path from 'path';
7
5
  import rangeSubset from 'semver/ranges/subset';
8
- import { RequiredDependency } from '@aws-amplify/codegen-ui';
9
- import { ReactRequiredDependencyProvider } from '@aws-amplify/codegen-ui-react';
10
6
  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';
11
10
 
12
- const getRequiredDependencies = (): RequiredDependency[] => new ReactRequiredDependencyProvider().getRequiredDependencies();
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
+ };
13
21
 
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 => {
22
+ export const notifyMissingPackages = (context: $TSContext, schemas: StudioComponent[]) => {
19
23
  const args = extractArgs(context);
20
24
  const localEnvFilePath = args.localEnvFilePath ?? pathManager.getLocalEnvFilePath();
21
25
  if (!fs.existsSync(localEnvFilePath)) {
@@ -29,7 +33,7 @@ export const notifyMissingPackages = (context: $TSContext): void => {
29
33
  return;
30
34
  }
31
35
  const packageJson = JSONUtilities.readJson(packageJsonPath) as { dependencies: { [key: string]: string } };
32
- getRequiredDependencies().forEach((dependency: $TSAny) => {
36
+ getRequiredDependencies(schemas).forEach((dependency: $TSAny) => {
33
37
  const packageIsInstalled = Object.keys(packageJson.dependencies).includes(dependency.dependencyName);
34
38
  if (!packageIsInstalled) {
35
39
  printer.warn(
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
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "rootDir": "./src",
6
+ "strict": true,
7
+ "skipLibCheck": true
8
+ }
8
9
  }
9
- }