@aws/nx-plugin 0.0.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.
Files changed (142) hide show
  1. package/README.md +63 -0
  2. package/generators.json +52 -0
  3. package/package.json +27 -0
  4. package/src/cloudscape-website/app/README.md +253 -0
  5. package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +539 -0
  6. package/src/cloudscape-website/app/files/app/src/config.ts.template +4 -0
  7. package/src/cloudscape-website/app/files/app/src/layouts/App/index.tsx.template +132 -0
  8. package/src/cloudscape-website/app/files/app/src/layouts/App/navitems.ts.template +8 -0
  9. package/src/cloudscape-website/app/files/app/src/layouts/Routes/index.tsx.template +18 -0
  10. package/src/cloudscape-website/app/files/app/src/main.tsx.template +22 -0
  11. package/src/cloudscape-website/app/files/app/src/pages/Home/index.tsx.template +25 -0
  12. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/cloudfront-web-acl.ts.template +317 -0
  13. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/index.ts.template +4 -0
  14. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/static-website.ts.template +237 -0
  15. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/webacl_event_handler/index.ts.template +301 -0
  16. package/src/cloudscape-website/app/files/e2e/cypress/src/e2e/app.cy.ts.template +13 -0
  17. package/src/cloudscape-website/app/files/e2e/cypress/src/support/app.po.ts.template +1 -0
  18. package/src/cloudscape-website/app/files/e2e/playwright/src/example.spec.ts.template +6 -0
  19. package/src/cloudscape-website/app/generator.d.ts +4 -0
  20. package/src/cloudscape-website/app/generator.js +177 -0
  21. package/src/cloudscape-website/app/generator.js.map +1 -0
  22. package/src/cloudscape-website/app/schema.d.js +6 -0
  23. package/src/cloudscape-website/app/schema.d.js.map +1 -0
  24. package/src/cloudscape-website/app/schema.d.ts +35 -0
  25. package/src/cloudscape-website/app/schema.json +189 -0
  26. package/src/cloudscape-website/cognito-auth/README.md +172 -0
  27. package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +238 -0
  28. package/src/cloudscape-website/cognito-auth/files/app/components/CognitoAuth/index.tsx.template +50 -0
  29. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/index.ts.template +4 -0
  30. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/user-identity.ts.template +69 -0
  31. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/userpool-with-mfa.ts.template +70 -0
  32. package/src/cloudscape-website/cognito-auth/generator.d.ts +4 -0
  33. package/src/cloudscape-website/cognito-auth/generator.js +100 -0
  34. package/src/cloudscape-website/cognito-auth/generator.js.map +1 -0
  35. package/src/cloudscape-website/cognito-auth/schema.d.js +6 -0
  36. package/src/cloudscape-website/cognito-auth/schema.d.js.map +1 -0
  37. package/src/cloudscape-website/cognito-auth/schema.d.ts +4 -0
  38. package/src/cloudscape-website/cognito-auth/schema.json +36 -0
  39. package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +112 -0
  40. package/src/cloudscape-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +46 -0
  41. package/src/cloudscape-website/runtime-config/generator.d.ts +4 -0
  42. package/src/cloudscape-website/runtime-config/generator.js +74 -0
  43. package/src/cloudscape-website/runtime-config/generator.js.map +1 -0
  44. package/src/cloudscape-website/runtime-config/schema.d.js +6 -0
  45. package/src/cloudscape-website/runtime-config/schema.d.js.map +1 -0
  46. package/src/cloudscape-website/runtime-config/schema.d.ts +3 -0
  47. package/src/cloudscape-website/runtime-config/schema.json +19 -0
  48. package/src/gitlab/files/.gitlab-ci.yml.template +26 -0
  49. package/src/gitlab/generator.d.ts +4 -0
  50. package/src/gitlab/generator.js +26 -0
  51. package/src/gitlab/generator.js.map +1 -0
  52. package/src/gitlab/schema.d.js +6 -0
  53. package/src/gitlab/schema.d.js.map +1 -0
  54. package/src/gitlab/schema.d.ts +5 -0
  55. package/src/gitlab/schema.json +52 -0
  56. package/src/index.d.ts +0 -0
  57. package/src/index.js +3 -0
  58. package/src/index.js.map +1 -0
  59. package/src/infra/app/README.md +175 -0
  60. package/src/infra/app/__snapshots__/generator.spec.ts.snap +864 -0
  61. package/src/infra/app/files/cdk.json +67 -0
  62. package/src/infra/app/files/src/main.ts.template +37 -0
  63. package/src/infra/app/files/src/stacks/application-stack.ts.template +10 -0
  64. package/src/infra/app/generator.d.ts +4 -0
  65. package/src/infra/app/generator.js +75 -0
  66. package/src/infra/app/generator.js.map +1 -0
  67. package/src/infra/app/schema.d.js +6 -0
  68. package/src/infra/app/schema.d.js.map +1 -0
  69. package/src/infra/app/schema.d.ts +6 -0
  70. package/src/infra/app/schema.json +35 -0
  71. package/src/trpc/backend/README.md +549 -0
  72. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +110 -0
  73. package/src/trpc/backend/files/backend/src/index.ts.template +1 -0
  74. package/src/trpc/backend/files/backend/src/lambdas/index.ts.template +1 -0
  75. package/src/trpc/backend/files/backend/src/lambdas/middleware.ts.template +146 -0
  76. package/src/trpc/backend/files/backend/src/lambdas/router.ts.template +36 -0
  77. package/src/trpc/backend/files/common/constructs/src/__apiNameKebabCase__/index.ts.template +64 -0
  78. package/src/trpc/backend/files/schema/src/index.ts.template +7 -0
  79. package/src/trpc/backend/generator.d.ts +4 -0
  80. package/src/trpc/backend/generator.js +128 -0
  81. package/src/trpc/backend/generator.js.map +1 -0
  82. package/src/trpc/backend/schema.d.js +6 -0
  83. package/src/trpc/backend/schema.d.js.map +1 -0
  84. package/src/trpc/backend/schema.d.ts +8 -0
  85. package/src/trpc/backend/schema.json +44 -0
  86. package/src/trpc/react/README.md +320 -0
  87. package/src/trpc/react/__snapshots__/generator.spec.ts.snap +98 -0
  88. package/src/trpc/react/files/src/components/TRPCClientProvider/index.tsx.template +34 -0
  89. package/src/trpc/react/files/src/hooks/useTrpc.tsx.template +5 -0
  90. package/src/trpc/react/generator.d.ts +4 -0
  91. package/src/trpc/react/generator.js +81 -0
  92. package/src/trpc/react/generator.js.map +1 -0
  93. package/src/trpc/react/schema.d.js +6 -0
  94. package/src/trpc/react/schema.d.js.map +1 -0
  95. package/src/trpc/react/schema.d.ts +5 -0
  96. package/src/trpc/react/schema.json +32 -0
  97. package/src/ts/cjs-to-esm/generator.d.ts +8 -0
  98. package/src/ts/cjs-to-esm/generator.js +201 -0
  99. package/src/ts/cjs-to-esm/generator.js.map +1 -0
  100. package/src/ts/cjs-to-esm/schema.d.js +6 -0
  101. package/src/ts/cjs-to-esm/schema.d.js.map +1 -0
  102. package/src/ts/cjs-to-esm/schema.d.ts +5 -0
  103. package/src/ts/cjs-to-esm/schema.json +28 -0
  104. package/src/ts/lib/README.md +149 -0
  105. package/src/ts/lib/__snapshots__/generator.spec.ts.snap +260 -0
  106. package/src/ts/lib/eslint.d.ts +3 -0
  107. package/src/ts/lib/eslint.js +41 -0
  108. package/src/ts/lib/eslint.js.map +1 -0
  109. package/src/ts/lib/files/src/index.ts.template +3 -0
  110. package/src/ts/lib/generator.d.ts +21 -0
  111. package/src/ts/lib/generator.js +61 -0
  112. package/src/ts/lib/generator.js.map +1 -0
  113. package/src/ts/lib/schema.d.js +6 -0
  114. package/src/ts/lib/schema.d.js.map +1 -0
  115. package/src/ts/lib/schema.d.ts +13 -0
  116. package/src/ts/lib/schema.json +46 -0
  117. package/src/ts/lib/ts-project-utils.d.ts +6 -0
  118. package/src/ts/lib/ts-project-utils.js +107 -0
  119. package/src/ts/lib/ts-project-utils.js.map +1 -0
  120. package/src/ts/lib/types.d.ts +10 -0
  121. package/src/ts/lib/types.js +6 -0
  122. package/src/ts/lib/types.js.map +1 -0
  123. package/src/ts/lib/vitest.d.ts +3 -0
  124. package/src/ts/lib/vitest.js +67 -0
  125. package/src/ts/lib/vitest.js.map +1 -0
  126. package/src/utils/files/common/constructs/src/index.ts.template +1 -0
  127. package/src/utils/files/common/constructs/src/runtime-config/index.ts.template +1 -0
  128. package/src/utils/files/common/constructs/src/runtime-config/runtime-config.ts.template +33 -0
  129. package/src/utils/files/common/types/src/index.ts.template +1 -0
  130. package/src/utils/files/common/types/src/runtime-config.ts.template +13 -0
  131. package/src/utils/npm-scope.d.ts +7 -0
  132. package/src/utils/npm-scope.js +37 -0
  133. package/src/utils/npm-scope.js.map +1 -0
  134. package/src/utils/paths.d.ts +3 -0
  135. package/src/utils/paths.js +32 -0
  136. package/src/utils/paths.js.map +1 -0
  137. package/src/utils/shared-constructs.d.ts +7 -0
  138. package/src/utils/shared-constructs.js +72 -0
  139. package/src/utils/shared-constructs.js.map +1 -0
  140. package/src/utils/versions.d.ts +31 -0
  141. package/src/utils/versions.js +49 -0
  142. package/src/utils/versions.js.map +1 -0
@@ -0,0 +1,69 @@
1
+ /*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
2
+ SPDX-License-Identifier: Apache-2.0 */
3
+ import {
4
+ IdentityPool,
5
+ UserPoolAuthenticationProvider,
6
+ } from '@aws-cdk/aws-cognito-identitypool-alpha';
7
+ import { CfnOutput, Stack } from 'aws-cdk-lib';
8
+ import { UserPool, UserPoolClient } from 'aws-cdk-lib/aws-cognito';
9
+ import { Construct } from 'constructs';
10
+ import { UserPoolWithMfa } from './userpool-with-mfa.js';
11
+ import { RuntimeConfig } from '../runtime-config/index.js';
12
+
13
+ const WEB_CLIENT_ID = 'WebClient';
14
+
15
+ /**
16
+ * Creates a UserPool and Identity Pool with sane defaults configured intended for usage from a web client.
17
+ */
18
+ export class UserIdentity extends Construct {
19
+ public readonly identityPool: IdentityPool;
20
+ public readonly userPool: UserPool;
21
+ public readonly userPoolClient: UserPoolClient;
22
+
23
+ constructor(scope: Construct, id: string) {
24
+ super(scope, id);
25
+
26
+ // Unless explicitly stated, created a default Cognito User Pool and Web Client.
27
+ this.userPool = new UserPoolWithMfa(this, 'UserPool');
28
+
29
+ this.identityPool = new IdentityPool(
30
+ this,
31
+ 'IdentityPool'
32
+ );
33
+
34
+ const existingClient = this.userPool.node.children.find(
35
+ (e) => e.node.id === WEB_CLIENT_ID && e instanceof UserPoolClient
36
+ ) as UserPoolClient | undefined;
37
+
38
+ this.userPoolClient =
39
+ existingClient ??
40
+ this.userPool.addClient(WEB_CLIENT_ID, {
41
+ authFlows: {
42
+ userPassword: true,
43
+ userSrp: true,
44
+ },
45
+ });
46
+
47
+ this.identityPool.addUserPoolAuthentication(
48
+ new UserPoolAuthenticationProvider({
49
+ userPool: this.userPool,
50
+ userPoolClient: this.userPoolClient,
51
+ })
52
+ );
53
+
54
+ new CfnOutput(this, `${id}-UserPoolId`, {
55
+ value: this.userPool.userPoolId,
56
+ });
57
+
58
+ new CfnOutput(this, `${id}-IdentityPoolId`, {
59
+ value: this.identityPool.identityPoolId,
60
+ });
61
+
62
+ RuntimeConfig.ensure(this).config.cognitoProps = {
63
+ region: Stack.of(this).region,
64
+ identityPoolId: this.identityPool.identityPoolId,
65
+ userPoolId: this.userPool?.userPoolId,
66
+ userPoolWebClientId: this.userPoolClient?.userPoolClientId,
67
+ };
68
+ }
69
+ }
@@ -0,0 +1,70 @@
1
+ /*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
2
+ SPDX-License-Identifier: Apache-2.0 */
3
+ import { PDKNag } from "@aws/pdk/pdk-nag";
4
+ import { Duration, Stack } from "aws-cdk-lib";
5
+ import {
6
+ AccountRecovery,
7
+ AdvancedSecurityMode,
8
+ Mfa,
9
+ UserPool,
10
+ } from "aws-cdk-lib/aws-cognito";
11
+ import { Construct } from "constructs";
12
+
13
+ /**
14
+ * Configures a UserPool with MFA across SMS/TOTP using sane defaults.
15
+ */
16
+ export class UserPoolWithMfa extends UserPool {
17
+ constructor(scope: Construct, id: string) {
18
+ super(scope, id, {
19
+ deletionProtection: true,
20
+ passwordPolicy: {
21
+ minLength: 8,
22
+ requireLowercase: true,
23
+ requireUppercase: true,
24
+ requireDigits: true,
25
+ requireSymbols: true,
26
+ tempPasswordValidity: Duration.days(3),
27
+ },
28
+ mfa: Mfa.REQUIRED,
29
+ mfaSecondFactor: { sms: true, otp: true },
30
+ signInCaseSensitive: false,
31
+ advancedSecurityMode: AdvancedSecurityMode.ENFORCED,
32
+ signInAliases: { username: true, email: true },
33
+ accountRecovery: AccountRecovery.EMAIL_ONLY,
34
+ selfSignUpEnabled: <%= allowSignup %>,
35
+ standardAttributes: {
36
+ phoneNumber: { required: false },
37
+ email: { required: true },
38
+ givenName: { required: true },
39
+ familyName: { required: true },
40
+ },
41
+ autoVerify: {
42
+ email: true,
43
+ phone: true,
44
+ },
45
+ keepOriginal: {
46
+ email: true,
47
+ phone: true,
48
+ },
49
+ });
50
+
51
+ const stack = Stack.of(this);
52
+
53
+ ["AwsSolutions-IAM5", "AwsPrototyping-IAMNoWildcardPermissions"].forEach(
54
+ (RuleId) => {
55
+ PDKNag.addResourceSuppressionsByPathNoThrow(
56
+ stack,
57
+ `${PDKNag.getStackPrefix(stack)}${id}/UserPool/smsRole/Resource`,
58
+ [
59
+ {
60
+ id: RuleId,
61
+ reason:
62
+ "MFA requires sending a text to a users phone number which cannot be known at deployment time.",
63
+ appliesTo: ["Resource::*"],
64
+ },
65
+ ]
66
+ );
67
+ }
68
+ );
69
+ }
70
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { CognitoAuthGeneratorSchema as CognitoAuthGeneratorSchema } from './schema';
3
+ export declare function cognitoAuthGenerator(tree: Tree, options: CognitoAuthGeneratorSchema): Promise<() => void>;
4
+ export default cognitoAuthGenerator;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ cognitoAuthGenerator: function() {
13
+ return cognitoAuthGenerator;
14
+ },
15
+ default: function() {
16
+ return _default;
17
+ }
18
+ });
19
+ const _extends = require("@swc/helpers/_/_extends");
20
+ const _devkit = require("@nx/devkit");
21
+ const _generator = require("../runtime-config/generator");
22
+ const _tsquery = require("@phenomnomnominal/tsquery");
23
+ const _typescript = require("typescript");
24
+ const _sharedconstructs = require("../../utils/shared-constructs");
25
+ const _versions = require("../../utils/versions");
26
+ async function cognitoAuthGenerator(tree, options) {
27
+ const srcRoot = (0, _devkit.readProjectConfiguration)(tree, options.project).sourceRoot;
28
+ if (tree.exists((0, _devkit.joinPathFragments)(srcRoot, 'components/CognitoAuth/index.tsx'))) {
29
+ throw new Error(`This generator has already been run on ${options.project}.`);
30
+ }
31
+ await (0, _generator.runtimeConfigGenerator)(tree, {
32
+ project: options.project
33
+ });
34
+ await (0, _sharedconstructs.sharedConstructsGenerator)(tree);
35
+ const identityPath = (0, _devkit.joinPathFragments)(_sharedconstructs.PACKAGES_DIR, _sharedconstructs.SHARED_CONSTRUCTS_DIR, 'src', 'identity', 'index.ts');
36
+ (0, _devkit.generateFiles)(tree, (0, _devkit.joinPathFragments)(__dirname, 'files', 'app'), srcRoot, options);
37
+ if (!tree.exists(identityPath)) {
38
+ (0, _devkit.generateFiles)(tree, (0, _devkit.joinPathFragments)(__dirname, 'files', _sharedconstructs.SHARED_CONSTRUCTS_DIR), (0, _devkit.joinPathFragments)(_sharedconstructs.PACKAGES_DIR, _sharedconstructs.SHARED_CONSTRUCTS_DIR), {
39
+ allowSignup: options.allowSignup
40
+ });
41
+ (0, _devkit.addDependenciesToPackageJson)(tree, (0, _versions.withVersions)([
42
+ 'constructs',
43
+ 'aws-cdk-lib',
44
+ '@aws/pdk',
45
+ '@aws-cdk/aws-cognito-identitypool-alpha'
46
+ ]), {});
47
+ const sharedConstructsIndexTsPath = (0, _devkit.joinPathFragments)(_sharedconstructs.PACKAGES_DIR, _sharedconstructs.SHARED_CONSTRUCTS_DIR, 'src', 'index.ts');
48
+ const sharedConstructsIndexContents = tree.read(sharedConstructsIndexTsPath).toString();
49
+ const identityExportDeclaration = _typescript.factory.createExportDeclaration(undefined, undefined, undefined, _typescript.factory.createStringLiteral('./identity/index.js'));
50
+ const updatedIndex = _tsquery.tsquery.map((0, _tsquery.ast)(sharedConstructsIndexContents), 'SourceFile', (node)=>{
51
+ return _extends._({}, node, {
52
+ statements: [
53
+ identityExportDeclaration,
54
+ ...node.statements
55
+ ]
56
+ });
57
+ }).getFullText();
58
+ if (sharedConstructsIndexContents !== updatedIndex) {
59
+ tree.write(sharedConstructsIndexTsPath, updatedIndex);
60
+ }
61
+ }
62
+ const mainTsxPath = (0, _devkit.joinPathFragments)(srcRoot, 'main.tsx');
63
+ if (!tree.exists(mainTsxPath)) {
64
+ throw new Error(`Can only run this generator on a project which contains ${mainTsxPath}`);
65
+ }
66
+ const mainTsxContents = tree.read(mainTsxPath).toString();
67
+ const authImport = _typescript.factory.createImportDeclaration(undefined, _typescript.factory.createImportClause(false, _typescript.factory.createIdentifier('CognitoAuth'), undefined), _typescript.factory.createStringLiteral('./components/CognitoAuth'));
68
+ const updatedImports = _tsquery.tsquery.map((0, _tsquery.ast)(mainTsxContents), 'SourceFile', (node)=>{
69
+ return _extends._({}, node, {
70
+ statements: [
71
+ authImport,
72
+ ...node.statements
73
+ ]
74
+ });
75
+ }).getFullText();
76
+ let locatedTargetNode = false;
77
+ const mainTsxUpdatedContents = _tsquery.tsquery.map((0, _tsquery.ast)(updatedImports), 'JsxElement', (node)=>{
78
+ if (node.openingElement.tagName.getText() !== 'RuntimeConfigProvider') {
79
+ return node;
80
+ } else {
81
+ locatedTargetNode = true;
82
+ }
83
+ return _typescript.factory.createJsxElement(node.openingElement, [
84
+ _typescript.factory.createJsxElement(_typescript.factory.createJsxOpeningElement(_typescript.factory.createIdentifier('CognitoAuth'), undefined, _typescript.factory.createJsxAttributes([])), node.children, _typescript.factory.createJsxClosingElement(_typescript.factory.createIdentifier('CognitoAuth')))
85
+ ], node.closingElement);
86
+ }).getFullText();
87
+ if (!locatedTargetNode) {
88
+ throw new Error('Could not locate the RuntimeConfigProvider element in main.tsx');
89
+ }
90
+ if (locatedTargetNode && mainTsxContents !== mainTsxUpdatedContents) {
91
+ tree.write(mainTsxPath, mainTsxUpdatedContents);
92
+ }
93
+ await (0, _devkit.formatFiles)(tree);
94
+ return ()=>{
95
+ (0, _devkit.installPackagesTask)(tree);
96
+ };
97
+ }
98
+ const _default = cognitoAuthGenerator;
99
+
100
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/cognito-auth/generator.ts"],"sourcesContent":["import {\n formatFiles,\n joinPathFragments,\n generateFiles,\n Tree,\n readProjectConfiguration,\n addDependenciesToPackageJson,\n installPackagesTask,\n} from '@nx/devkit';\nimport { CognitoAuthGeneratorSchema as CognitoAuthGeneratorSchema } from './schema';\nimport { runtimeConfigGenerator } from '../runtime-config/generator';\nimport { tsquery, ast } from '@phenomnomnominal/tsquery';\nimport { factory, ImportClause, JsxElement, SourceFile } from 'typescript';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\n\nexport async function cognitoAuthGenerator(\n tree: Tree,\n options: CognitoAuthGeneratorSchema\n) {\n const srcRoot = readProjectConfiguration(tree, options.project).sourceRoot;\n\n if (\n tree.exists(joinPathFragments(srcRoot, 'components/CognitoAuth/index.tsx'))\n ) {\n throw new Error(\n `This generator has already been run on ${options.project}.`\n );\n }\n\n await runtimeConfigGenerator(tree, {\n project: options.project,\n });\n\n await sharedConstructsGenerator(tree);\n const identityPath = joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'identity',\n 'index.ts'\n );\n\n generateFiles(\n tree,\n joinPathFragments(__dirname, 'files', 'app'),\n srcRoot,\n options\n );\n\n if (!tree.exists(identityPath)) {\n generateFiles(\n tree,\n joinPathFragments(__dirname, 'files', SHARED_CONSTRUCTS_DIR),\n joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR),\n {\n allowSignup: options.allowSignup,\n }\n );\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'constructs',\n 'aws-cdk-lib',\n '@aws/pdk',\n '@aws-cdk/aws-cognito-identitypool-alpha',\n ]),\n {}\n );\n\n const sharedConstructsIndexTsPath = joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'index.ts'\n );\n const sharedConstructsIndexContents = tree\n .read(sharedConstructsIndexTsPath)\n .toString();\n\n const identityExportDeclaration = factory.createExportDeclaration(\n undefined,\n undefined,\n undefined,\n factory.createStringLiteral('./identity/index.js')\n );\n const updatedIndex = tsquery\n .map(\n ast(sharedConstructsIndexContents),\n 'SourceFile',\n (node: SourceFile) => {\n return {\n ...node,\n statements: [identityExportDeclaration, ...node.statements],\n };\n }\n )\n .getFullText();\n\n if (sharedConstructsIndexContents !== updatedIndex) {\n tree.write(sharedConstructsIndexTsPath, updatedIndex);\n }\n }\n\n const mainTsxPath = joinPathFragments(srcRoot, 'main.tsx');\n\n if (!tree.exists(mainTsxPath)) {\n throw new Error(\n `Can only run this generator on a project which contains ${mainTsxPath}`\n );\n }\n\n const mainTsxContents = tree.read(mainTsxPath).toString();\n\n const authImport = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n factory.createIdentifier('CognitoAuth'),\n undefined\n ) as ImportClause,\n factory.createStringLiteral('./components/CognitoAuth')\n );\n\n const updatedImports = tsquery\n .map(ast(mainTsxContents), 'SourceFile', (node: SourceFile) => {\n return {\n ...node,\n statements: [authImport, ...node.statements],\n };\n })\n .getFullText();\n\n let locatedTargetNode = false;\n const mainTsxUpdatedContents = tsquery\n .map(ast(updatedImports), 'JsxElement', (node: JsxElement) => {\n if (node.openingElement.tagName.getText() !== 'RuntimeConfigProvider') {\n return node;\n } else {\n locatedTargetNode = true;\n }\n\n return factory.createJsxElement(\n node.openingElement,\n [\n factory.createJsxElement(\n factory.createJsxOpeningElement(\n factory.createIdentifier('CognitoAuth'),\n undefined,\n factory.createJsxAttributes([])\n ),\n node.children,\n factory.createJsxClosingElement(\n factory.createIdentifier('CognitoAuth')\n )\n ),\n ],\n node.closingElement\n );\n })\n .getFullText();\n\n if (!locatedTargetNode) {\n throw new Error(\n 'Could not locate the RuntimeConfigProvider element in main.tsx'\n );\n }\n\n if (locatedTargetNode && mainTsxContents !== mainTsxUpdatedContents) {\n tree.write(mainTsxPath, mainTsxUpdatedContents);\n }\n\n await formatFiles(tree);\n\n return () => {\n installPackagesTask(tree);\n };\n}\n\nexport default cognitoAuthGenerator;\n"],"names":["cognitoAuthGenerator","tree","options","srcRoot","readProjectConfiguration","project","sourceRoot","exists","joinPathFragments","Error","runtimeConfigGenerator","sharedConstructsGenerator","identityPath","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","generateFiles","__dirname","allowSignup","addDependenciesToPackageJson","withVersions","sharedConstructsIndexTsPath","sharedConstructsIndexContents","read","toString","identityExportDeclaration","factory","createExportDeclaration","undefined","createStringLiteral","updatedIndex","tsquery","map","ast","node","statements","getFullText","write","mainTsxPath","mainTsxContents","authImport","createImportDeclaration","createImportClause","createIdentifier","updatedImports","locatedTargetNode","mainTsxUpdatedContents","openingElement","tagName","getText","createJsxElement","createJsxOpeningElement","createJsxAttributes","children","createJsxClosingElement","closingElement","formatFiles","installPackagesTask"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"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"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=schema.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/cognito-auth/schema.d.ts"],"names":[],"rangeMappings":"","mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface CognitoAuthGeneratorSchema {
2
+ project: string;
3
+ allowSignup: boolean;
4
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "Cloudscape App",
5
+ "title": "Create a Cloudscape React Application",
6
+ "description": "Create a Cloudscape React application for Nx.",
7
+ "examples": [
8
+ {
9
+ "command": "nx g app myapp --directory=myorg",
10
+ "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`"
11
+ },
12
+ {
13
+ "command": "nx g app myapp --classComponent",
14
+ "description": "Use class components instead of functional components"
15
+ }
16
+ ],
17
+ "type": "object",
18
+ "properties": {
19
+ "project": {
20
+ "description": "The root directory of the Cloudscape application.",
21
+ "type": "string",
22
+ "alias": "dir",
23
+ "x-priority": "important",
24
+ "x-prompt": "the root directory for your Cloudscape application",
25
+ "x-dropdown": "projects"
26
+ },
27
+ "allowSignup": {
28
+ "description": "Whether to allow self-signup",
29
+ "type": "boolean",
30
+ "default": false,
31
+ "x-prompt": "Enable self signup?",
32
+ "x-priority": "important"
33
+ }
34
+ },
35
+ "required": ["project"]
36
+ }
@@ -0,0 +1,112 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`runtime-config generator > should generate runtime config files > runtime-config-component.tsx 1`] = `
4
+ "/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
5
+ SPDX-License-Identifier: Apache-2.0 */
6
+ import ErrorMessage from '@aws-northstar/ui/components/CognitoAuth/components/ErrorMessage';
7
+ import { Spinner } from '@cloudscape-design/components';
8
+ import React, { createContext, useEffect, useState } from 'react';
9
+ import type { IRuntimeConfig } from ':proj/common-types';
10
+
11
+ /**
12
+ * Context for storing the runtimeConfig.
13
+ */
14
+ export const RuntimeConfigContext = createContext<IRuntimeConfig | undefined>(
15
+ undefined
16
+ );
17
+
18
+ /**
19
+ * Sets up the runtimeConfig.
20
+ *
21
+ * This assumes a runtime-config.json file is present at '/'.
22
+ */
23
+ const RuntimeConfigProvider: React.FC<any> = ({ children }) => {
24
+ const [runtimeConfig, setRuntimeConfig] = useState<
25
+ IRuntimeConfig | undefined
26
+ >();
27
+ const [error, setError] = useState<string | undefined>();
28
+
29
+ useEffect(() => {
30
+ fetch('/runtime-config.json')
31
+ .then((response) => {
32
+ return response.json();
33
+ })
34
+ .then((_runtimeConfig) => {
35
+ setRuntimeConfig(_runtimeConfig as IRuntimeConfig);
36
+ })
37
+ .catch(() => {
38
+ setError('No runtime-config.json detected');
39
+ });
40
+ }, [setRuntimeConfig]);
41
+
42
+ return error ? (
43
+ <ErrorMessage>{error}</ErrorMessage>
44
+ ) : runtimeConfig ? (
45
+ <RuntimeConfigContext.Provider value={runtimeConfig}>
46
+ {children}
47
+ </RuntimeConfigContext.Provider>
48
+ ) : (
49
+ <Spinner></Spinner>
50
+ );
51
+ };
52
+
53
+ export default RuntimeConfigProvider;
54
+ "
55
+ `;
56
+
57
+ exports[`runtime-config generator > should generate shared constructs > common/constructs-index.ts 1`] = `
58
+ "export * from './runtime-config.js';
59
+ "
60
+ `;
61
+
62
+ exports[`runtime-config generator > should generate shared constructs > runtime-config.ts 1`] = `
63
+ "/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
64
+ SPDX-License-Identifier: Apache-2.0 */
65
+ import type { IRuntimeConfig } from ':proj/common-types';
66
+ import { Stack } from 'aws-cdk-lib';
67
+ import { Construct } from 'constructs';
68
+
69
+ const RuntimeConfigKey = '__RuntimeConfig__';
70
+
71
+ export class RuntimeConfig extends Construct {
72
+ static ensure(scope: Construct): RuntimeConfig {
73
+ const stack = Stack.of(scope);
74
+ return (
75
+ RuntimeConfig.of(scope) ?? new RuntimeConfig(stack, RuntimeConfigKey)
76
+ );
77
+ }
78
+
79
+ static of(scope: Construct): RuntimeConfig | undefined {
80
+ const stack = Stack.of(scope);
81
+ return stack.node.tryFindChild(RuntimeConfigKey) as
82
+ | RuntimeConfig
83
+ | undefined;
84
+ }
85
+
86
+ private readonly _runtimeConfig: IRuntimeConfig = {};
87
+
88
+ constructor(scope: Construct, id: string) {
89
+ super(scope, id);
90
+ }
91
+
92
+ get config(): IRuntimeConfig {
93
+ return this._runtimeConfig;
94
+ }
95
+ }
96
+ "
97
+ `;
98
+
99
+ exports[`runtime-config generator > should modify main.tsx correctly > modified-main.tsx 1`] = `
100
+ "import RuntimeConfigProvider from './components/RuntimeConfig';
101
+ import { BrowserRouter } from 'react-router-dom';
102
+ export function App() {
103
+ return (
104
+ <RuntimeConfigProvider>
105
+ <BrowserRouter>
106
+ <div>Test App</div>
107
+ </BrowserRouter>
108
+ </RuntimeConfigProvider>
109
+ );
110
+ }
111
+ "
112
+ `;
@@ -0,0 +1,46 @@
1
+ /*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
2
+ SPDX-License-Identifier: Apache-2.0 */
3
+ import ErrorMessage from "@aws-northstar/ui/components/CognitoAuth/components/ErrorMessage";
4
+ import { Spinner } from "@cloudscape-design/components";
5
+ import React, { createContext, useEffect, useState } from "react";
6
+ import type { IRuntimeConfig } from '<%= scopeAlias %>common-types';
7
+
8
+ /**
9
+ * Context for storing the runtimeConfig.
10
+ */
11
+ export const RuntimeConfigContext = createContext<IRuntimeConfig | undefined>(
12
+ undefined
13
+ );
14
+
15
+ /**
16
+ * Sets up the runtimeConfig.
17
+ *
18
+ * This assumes a runtime-config.json file is present at '/'.
19
+ */
20
+ const RuntimeConfigProvider: React.FC<any> = ({ children }) => {
21
+ const [runtimeConfig, setRuntimeConfig] = useState<IRuntimeConfig | undefined>();
22
+ const [error, setError] = useState<string | undefined>();
23
+
24
+ useEffect(() => {
25
+ fetch("/runtime-config.json")
26
+ .then((response) => {
27
+ return response.json();
28
+ })
29
+ .then((_runtimeConfig) => {
30
+ setRuntimeConfig(_runtimeConfig as IRuntimeConfig);
31
+ })
32
+ .catch(() => {
33
+ setError("No runtime-config.json detected");
34
+ });
35
+ }, [setRuntimeConfig]);
36
+
37
+ return error ? (
38
+ <ErrorMessage>{error}</ErrorMessage>
39
+ ) : runtimeConfig ? (
40
+ <RuntimeConfigContext.Provider value={runtimeConfig}>
41
+ {children}
42
+ </RuntimeConfigContext.Provider>
43
+ ) : <Spinner></Spinner>;
44
+ };
45
+
46
+ export default RuntimeConfigProvider;
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { RuntimeConfigGeneratorSchema } from './schema';
3
+ export declare function runtimeConfigGenerator(tree: Tree, options: RuntimeConfigGeneratorSchema): Promise<void>;
4
+ export default runtimeConfigGenerator;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ default: function() {
13
+ return _default;
14
+ },
15
+ runtimeConfigGenerator: function() {
16
+ return runtimeConfigGenerator;
17
+ }
18
+ });
19
+ const _extends = require("@swc/helpers/_/_extends");
20
+ const _devkit = require("@nx/devkit");
21
+ const _tsquery = require("@phenomnomnominal/tsquery");
22
+ const _typescript = require("typescript");
23
+ const _sharedconstructs = require("../../utils/shared-constructs");
24
+ const _npmscope = require("../../utils/npm-scope");
25
+ async function runtimeConfigGenerator(tree, options) {
26
+ const srcRoot = (0, _devkit.readProjectConfiguration)(tree, options.project).sourceRoot;
27
+ const mainTsxPath = (0, _devkit.joinPathFragments)(srcRoot, 'main.tsx');
28
+ if (!tree.exists(mainTsxPath)) {
29
+ throw new Error(`Can only run this generator on a project which contains ${mainTsxPath}`);
30
+ }
31
+ const mainTsxContents = tree.read(mainTsxPath).toString();
32
+ const mainTsxAst = (0, _tsquery.ast)(mainTsxContents);
33
+ const runtimeConfigPath = (0, _devkit.joinPathFragments)(srcRoot, 'components', 'RuntimeConfig', 'index.tsx');
34
+ if (tree.exists(runtimeConfigPath) || _tsquery.tsquery.query(mainTsxAst, 'JsxElement > JsxOpeningElement[name.text="RuntimeConfigProvider"]').length > 0) {
35
+ console.debug('Runtime config already exists, skipping generation');
36
+ return;
37
+ }
38
+ await (0, _sharedconstructs.sharedConstructsGenerator)(tree);
39
+ const npmScopePrefix = (0, _npmscope.getNpmScopePrefix)(tree);
40
+ (0, _devkit.generateFiles)(tree, (0, _devkit.joinPathFragments)(__dirname, 'files', 'app'), srcRoot, _extends._({}, options, {
41
+ npmScopePrefix,
42
+ scopeAlias: (0, _npmscope.toScopeAlias)(npmScopePrefix)
43
+ }));
44
+ const runtimeContextImport = _typescript.factory.createImportDeclaration(undefined, _typescript.factory.createImportClause(false, _typescript.factory.createIdentifier('RuntimeConfigProvider'), undefined), _typescript.factory.createStringLiteral('./components/RuntimeConfig'));
45
+ const updatedImports = _tsquery.tsquery.map(mainTsxAst, 'SourceFile', (node)=>{
46
+ return _extends._({}, node, {
47
+ statements: [
48
+ runtimeContextImport,
49
+ ...node.statements
50
+ ]
51
+ });
52
+ }).getFullText();
53
+ let locatedTargetNode = false;
54
+ const mainTsxUpdatedContents = _tsquery.tsquery.map((0, _tsquery.ast)(updatedImports), 'JsxElement', (node)=>{
55
+ if (node.openingElement.tagName.getText() !== 'BrowserRouter') {
56
+ return node;
57
+ } else {
58
+ locatedTargetNode = true;
59
+ }
60
+ return _typescript.factory.createJsxElement(_typescript.factory.createJsxOpeningElement(_typescript.factory.createIdentifier('RuntimeConfigProvider'), undefined, _typescript.factory.createJsxAttributes([])), [
61
+ node
62
+ ], _typescript.factory.createJsxClosingElement(_typescript.factory.createIdentifier('RuntimeConfigProvider')));
63
+ }).getFullText();
64
+ if (!locatedTargetNode) {
65
+ throw new Error('Could not locate the BrowserRouter element in main.tsx');
66
+ }
67
+ if (locatedTargetNode && mainTsxContents !== mainTsxUpdatedContents) {
68
+ tree.write(mainTsxPath, mainTsxUpdatedContents);
69
+ }
70
+ await (0, _devkit.formatFiles)(tree);
71
+ }
72
+ const _default = runtimeConfigGenerator;
73
+
74
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/runtime-config/generator.ts"],"sourcesContent":["import {\n formatFiles,\n joinPathFragments,\n generateFiles,\n Tree,\n readProjectConfiguration,\n} from '@nx/devkit';\nimport { RuntimeConfigGeneratorSchema } from './schema';\nimport { tsquery, ast } from '@phenomnomnominal/tsquery';\nimport { factory, JsxElement, SourceFile } from 'typescript';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { getNpmScopePrefix, toScopeAlias } from '../../utils/npm-scope';\n\nexport async function runtimeConfigGenerator(\n tree: Tree,\n options: RuntimeConfigGeneratorSchema\n) {\n const srcRoot = readProjectConfiguration(tree, options.project).sourceRoot;\n const mainTsxPath = joinPathFragments(srcRoot, 'main.tsx');\n\n if (!tree.exists(mainTsxPath)) {\n throw new Error(\n `Can only run this generator on a project which contains ${mainTsxPath}`\n );\n }\n\n const mainTsxContents = tree.read(mainTsxPath).toString();\n const mainTsxAst = ast(mainTsxContents);\n const runtimeConfigPath = joinPathFragments(\n srcRoot,\n 'components',\n 'RuntimeConfig',\n 'index.tsx'\n );\n\n if (\n tree.exists(runtimeConfigPath) ||\n tsquery.query(\n mainTsxAst,\n 'JsxElement > JsxOpeningElement[name.text=\"RuntimeConfigProvider\"]'\n ).length > 0\n ) {\n console.debug('Runtime config already exists, skipping generation');\n return;\n }\n\n await sharedConstructsGenerator(tree);\n\n const npmScopePrefix = getNpmScopePrefix(tree);\n generateFiles(tree, joinPathFragments(__dirname, 'files', 'app'), srcRoot, {\n ...options,\n npmScopePrefix,\n scopeAlias: toScopeAlias(npmScopePrefix),\n });\n\n const runtimeContextImport = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n factory.createIdentifier('RuntimeConfigProvider'),\n undefined\n ),\n factory.createStringLiteral('./components/RuntimeConfig')\n );\n\n const updatedImports = tsquery\n .map(mainTsxAst, 'SourceFile', (node: SourceFile) => {\n return {\n ...node,\n statements: [runtimeContextImport, ...node.statements],\n };\n })\n .getFullText();\n\n let locatedTargetNode = false;\n const mainTsxUpdatedContents = tsquery\n .map(ast(updatedImports), 'JsxElement', (node: JsxElement) => {\n if (node.openingElement.tagName.getText() !== 'BrowserRouter') {\n return node;\n } else {\n locatedTargetNode = true;\n }\n\n return factory.createJsxElement(\n factory.createJsxOpeningElement(\n factory.createIdentifier('RuntimeConfigProvider'),\n undefined,\n factory.createJsxAttributes([])\n ),\n [node],\n factory.createJsxClosingElement(\n factory.createIdentifier('RuntimeConfigProvider')\n )\n );\n })\n .getFullText();\n\n if (!locatedTargetNode) {\n throw new Error('Could not locate the BrowserRouter element in main.tsx');\n }\n\n if (locatedTargetNode && mainTsxContents !== mainTsxUpdatedContents) {\n tree.write(mainTsxPath, mainTsxUpdatedContents);\n }\n\n await formatFiles(tree);\n}\n\nexport default runtimeConfigGenerator;\n"],"names":["runtimeConfigGenerator","tree","options","srcRoot","readProjectConfiguration","project","sourceRoot","mainTsxPath","joinPathFragments","exists","Error","mainTsxContents","read","toString","mainTsxAst","ast","runtimeConfigPath","tsquery","query","length","console","debug","sharedConstructsGenerator","npmScopePrefix","getNpmScopePrefix","generateFiles","__dirname","scopeAlias","toScopeAlias","runtimeContextImport","factory","createImportDeclaration","undefined","createImportClause","createIdentifier","createStringLiteral","updatedImports","map","node","statements","getFullText","locatedTargetNode","mainTsxUpdatedContents","openingElement","tagName","getText","createJsxElement","createJsxOpeningElement","createJsxAttributes","createJsxClosingElement","write","formatFiles"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IA4GA,OAAsC;eAAtC;;IA/FsBA,sBAAsB;eAAtBA;;;;wBAPf;yBAEsB;4BACmB;kCACN;0BACM;AAEzC,eAAeA,uBACpBC,IAAU,EACVC,OAAqC;IAErC,MAAMC,UAAUC,IAAAA,gCAAwB,EAACH,MAAMC,QAAQG,OAAO,EAAEC,UAAU;IAC1E,MAAMC,cAAcC,IAAAA,yBAAiB,EAACL,SAAS;IAE/C,IAAI,CAACF,KAAKQ,MAAM,CAACF,cAAc;QAC7B,MAAM,IAAIG,MACR,CAAC,wDAAwD,EAAEH,YAAY,CAAC;IAE5E;IAEA,MAAMI,kBAAkBV,KAAKW,IAAI,CAACL,aAAaM,QAAQ;IACvD,MAAMC,aAAaC,IAAAA,YAAG,EAACJ;IACvB,MAAMK,oBAAoBR,IAAAA,yBAAiB,EACzCL,SACA,cACA,iBACA;IAGF,IACEF,KAAKQ,MAAM,CAACO,sBACZC,gBAAO,CAACC,KAAK,CACXJ,YACA,qEACAK,MAAM,GAAG,GACX;QACAC,QAAQC,KAAK,CAAC;QACd;IACF;IAEA,MAAMC,IAAAA,2CAAyB,EAACrB;IAEhC,MAAMsB,iBAAiBC,IAAAA,2BAAiB,EAACvB;IACzCwB,IAAAA,qBAAa,EAACxB,MAAMO,IAAAA,yBAAiB,EAACkB,WAAW,SAAS,QAAQvB,SAAS,eACtED;QACHqB;QACAI,YAAYC,IAAAA,sBAAY,EAACL;;IAG3B,MAAMM,uBAAuBC,mBAAO,CAACC,uBAAuB,CAC1DC,WACAF,mBAAO,CAACG,kBAAkB,CACxB,OACAH,mBAAO,CAACI,gBAAgB,CAAC,0BACzBF,YAEFF,mBAAO,CAACK,mBAAmB,CAAC;IAG9B,MAAMC,iBAAiBnB,gBAAO,CAC3BoB,GAAG,CAACvB,YAAY,cAAc,CAACwB;QAC9B,OAAO,eACFA;YACHC,YAAY;gBAACV;mBAAyBS,KAAKC,UAAU;aAAC;;IAE1D,GACCC,WAAW;IAEd,IAAIC,oBAAoB;IACxB,MAAMC,yBAAyBzB,gBAAO,CACnCoB,GAAG,CAACtB,IAAAA,YAAG,EAACqB,iBAAiB,cAAc,CAACE;QACvC,IAAIA,KAAKK,cAAc,CAACC,OAAO,CAACC,OAAO,OAAO,iBAAiB;YAC7D,OAAOP;QACT,OAAO;YACLG,oBAAoB;QACtB;QAEA,OAAOX,mBAAO,CAACgB,gBAAgB,CAC7BhB,mBAAO,CAACiB,uBAAuB,CAC7BjB,mBAAO,CAACI,gBAAgB,CAAC,0BACzBF,WACAF,mBAAO,CAACkB,mBAAmB,CAAC,EAAE,IAEhC;YAACV;SAAK,EACNR,mBAAO,CAACmB,uBAAuB,CAC7BnB,mBAAO,CAACI,gBAAgB,CAAC;IAG/B,GACCM,WAAW;IAEd,IAAI,CAACC,mBAAmB;QACtB,MAAM,IAAI/B,MAAM;IAClB;IAEA,IAAI+B,qBAAqB9B,oBAAoB+B,wBAAwB;QACnEzC,KAAKiD,KAAK,CAAC3C,aAAamC;IAC1B;IAEA,MAAMS,IAAAA,mBAAW,EAAClD;AACpB;MAEA,WAAeD"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=schema.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/runtime-config/schema.d.ts"],"names":[],"rangeMappings":"","mappings":""}
@@ -0,0 +1,3 @@
1
+ export interface RuntimeConfigGeneratorSchema {
2
+ project: string;
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "Runtime Config",
5
+ "title": "Adds runtime config to a react application",
6
+ "description": "Adds runtime config to a react application",
7
+ "type": "object",
8
+ "properties": {
9
+ "project": {
10
+ "description": "The target project.",
11
+ "type": "string",
12
+ "alias": "dir",
13
+ "x-priority": "important",
14
+ "x-prompt": "the project to target",
15
+ "x-dropdown": "projects"
16
+ }
17
+ },
18
+ "required": ["project"]
19
+ }
@@ -0,0 +1,26 @@
1
+ default:
2
+ image: node:20
3
+ before_script:
4
+ - npm install -g pnpm@9
5
+ - pnpm install --frozen-lockfile --prefer-offline
6
+
7
+ stages:
8
+ - build
9
+ - deploy
10
+
11
+ build-job:
12
+ stage: build
13
+ script:
14
+ - pnpm nx build <%= infraProject %>
15
+ artifacts:
16
+ paths:
17
+ - dist/**/*
18
+
19
+ deploy-job:
20
+ stage: deploy
21
+ environment: beta
22
+ variables:
23
+ AWS_CREDS_TARGET_ROLE: <%= roleArn %>
24
+ AWS_DEFAULT_REGION: <%= region %>
25
+ script:
26
+ - pnpm nx deploy <%= infraProject %> --skip-nx-cache
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { GitlabGeneratorSchema } from './schema';
3
+ export declare function gitlabGenerator(tree: Tree, options: GitlabGeneratorSchema): Promise<void>;
4
+ export default gitlabGenerator;