@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
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # PACE Plugin for Nx
2
+
3
+ This plugin provides a collection of generators to help you build cloud-native applications with AWS, TypeScript, and React.
4
+
5
+ ## What are Generators?
6
+
7
+ Generators (also known as schematics) are powerful tools that automate the creation and modification of code. They help maintain consistency across your codebase by following established patterns and best practices. When you run a generator, it:
8
+
9
+ 1. Prompts for necessary configuration options
10
+ 2. Creates new files from templates
11
+ 3. Updates existing files when needed
12
+ 4. Follows project conventions automatically
13
+
14
+ For more information about generators, see the [Nx Generator documentation](https://nx.dev/plugin-features/use-code-generators).
15
+
16
+ ## Getting started
17
+
18
+ ### Install the plugin
19
+
20
+ From the root of your workspace run:
21
+
22
+ ```bash
23
+ nx add @aws/nx-plugin
24
+ ```
25
+
26
+ ### IDE Setup
27
+
28
+ For the best development experience, install the Nx Console extension for your IDE:
29
+
30
+ - VS Code: [Nx Console for VS Code](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
31
+ - JetBrains IDEs: [Nx Console for JetBrains](https://plugins.jetbrains.com/plugin/21060-nx-console)
32
+
33
+ The Nx Console provides:
34
+ - Interactive generator configuration
35
+ - Command autocompletion
36
+ - Visual project graph
37
+ - Integrated task runner
38
+
39
+ ### Using Generators
40
+
41
+ Refer to the individual generator README.md files below for detailed installation instructions.
42
+
43
+ ## Available Generators
44
+
45
+ ### Cloudscape Website
46
+
47
+ - [Cloudscape Website App](src/cloudscape-website/app/README.md) - Generate a new Cloudscape-based web application
48
+ - [Cognito Authentication](src/cloudscape-website/cognito-auth/README.md) - Add AWS Cognito authentication to your Cloudscape website
49
+ - [Runtime Configuration](src/cloudscape-website/runtime-config/README.md) - Add runtime configuration capabilities to your Cloudscape website
50
+
51
+ ### Infrastructure
52
+
53
+ - [Infrastructure App](src/infra/app/README.md) - Generate AWS CDK infrastructure code for your application
54
+
55
+ ### tRPC
56
+
57
+ - [tRPC Backend](src/trpc/backend/README.md) - Generate a tRPC backend service with AWS Lambda integration
58
+ - [tRPC React](src/trpc/react/README.md) - Add tRPC client integration to your React application
59
+
60
+ ### TypeScript
61
+
62
+ - [TypeScript Library](src/ts/lib/README.md) - Generate a new TypeScript library with best practices and testing setup
63
+ - [CJS to ESM](src/ts/cjs-to-esm/README.md) - Convert CommonJS modules to ECMAScript modules
@@ -0,0 +1,52 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "name": "pace",
4
+ "version": "0.0.1",
5
+ "generators": {
6
+ "ts#lib": {
7
+ "factory": "./src/ts/lib/generator",
8
+ "schema": "./src/ts/lib/schema.json",
9
+ "description": "Generates a TypeScript library"
10
+ },
11
+ "ts#cjs-to-esm": {
12
+ "factory": "./src/ts/cjs-to-esm/generator",
13
+ "schema": "./src/ts/cjs-to-esm/schema.json",
14
+ "description": "Convert CommonJS TypeScript/JavaScript files to ESM"
15
+ },
16
+ "cloudscape-website#app": {
17
+ "factory": "./src/cloudscape-website/app/generator",
18
+ "schema": "./src/cloudscape-website/app/schema.json",
19
+ "description": "Generates a React static website based on Cloudscape"
20
+ },
21
+ "cloudscape-website#cognito-auth": {
22
+ "factory": "./src/cloudscape-website/cognito-auth/generator",
23
+ "schema": "./src/cloudscape-website/cognito-auth/schema.json",
24
+ "description": "Adds cognito auth to an existing cloudscape website"
25
+ },
26
+ "cloudscape-website#runtime-config": {
27
+ "factory": "./src/cloudscape-website/runtime-config/generator",
28
+ "schema": "./src/cloudscape-website/runtime-config/schema.json",
29
+ "description": "Adds runtime config to an existing cloudscape website"
30
+ },
31
+ "infra#app": {
32
+ "factory": "./src/infra/app/generator",
33
+ "schema": "./src/infra/app/schema.json",
34
+ "description": "Generates a cdk application"
35
+ },
36
+ "trpc#backend": {
37
+ "factory": "./src/trpc/backend/generator",
38
+ "schema": "./src/trpc/backend/schema.json",
39
+ "description": "creates a trpc backend"
40
+ },
41
+ "trpc#react": {
42
+ "factory": "./src/trpc/react/generator",
43
+ "schema": "./src/trpc/react/schema.json",
44
+ "description": "provides React integration to a React website"
45
+ },
46
+ "gitlab": {
47
+ "factory": "./src/gitlab/generator",
48
+ "schema": "./src/gitlab/schema.json",
49
+ "description": "Gitlab CI/CD pipeline"
50
+ }
51
+ }
52
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@aws/nx-plugin",
3
+ "version": "0.0.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "private": false,
8
+ "type": "commonjs",
9
+ "main": "./src/index.js",
10
+ "typings": "./src/index.d.ts",
11
+ "generators": "./generators.json",
12
+ "dependencies": {
13
+ "@nx/eslint": "20.0.10",
14
+ "@nx/js": "20.0.10",
15
+ "@nx/react": "20.0.10",
16
+ "@phenomnomnominal/tsquery": "6.1.3",
17
+ "lodash.kebabcase": "4.1.1",
18
+ "typescript": "~5.5.4",
19
+ "vitest": "^1.6.0",
20
+ "minimatch": "^10.0.1",
21
+ "vite": "^5.4.0",
22
+ "@nx/vite": "20.0.10",
23
+ "@nx/devkit": "20.1.1",
24
+ "nx": "19.8.2"
25
+ },
26
+ "types": "./src/index.d.ts"
27
+ }
@@ -0,0 +1,253 @@
1
+ # Cloudscape Website App Generator
2
+
3
+ ## Overview
4
+ This generator creates a new Cloudscape React application with AWS CDK infrastructure setup. The generated application uses Vite as the build tool and bundler, providing fast development and optimized production builds. The codebase is structured using ES Modules (ESM) for modern JavaScript module system compatibility. It sets up a complete web application using AWS Cloudscape Design System components and configures the necessary build tools and dependencies.
5
+
6
+ ## Usage
7
+
8
+ You can generate a new Cloudscape website application in two ways:
9
+
10
+ ### 1. Using VSCode IDE
11
+
12
+ First, install the NX Console extension for VSCode:
13
+ 1. Open VSCode
14
+ 2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
15
+ 3. Search for "Nx Console"
16
+ 4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
17
+
18
+ Then generate your application:
19
+ 1. Open the NX Console in VSCode
20
+ 2. Click on "Generate"
21
+ 3. Search for "cloudscape-website#app"
22
+ 4. Fill in the required parameters in the form
23
+ 5. Click "Run"
24
+
25
+ ### 2. Using CLI
26
+
27
+ Generate the application:
28
+ ```bash
29
+ nx g @aws/nx-plugin:cloudscape-website#app my-website --directory=apps/web
30
+ ```
31
+
32
+ You can also perform a dry-run to see what files would be generated without actually creating them:
33
+ ```bash
34
+ nx g @aws/nx-plugin:cloudscape-website#app my-website --directory=apps/web --dry-run
35
+ ```
36
+
37
+ Both methods will create a new Cloudscape website application in `apps/web/my-website` with all the necessary configuration and infrastructure code.
38
+
39
+ ## Input Parameters
40
+
41
+ | Parameter | Type | Default | Description |
42
+ |-----------|------|---------|-------------|
43
+ | name* | string | - | The name of the application (required). Must start with a letter and not contain colons. |
44
+ | directory | string | "packages" | The directory to store the application in. |
45
+ | style | string | "css" | The file extension for style files. Options: css, scss, less, tailwind, styled-components, @emotion/styled, styled-jsx, none |
46
+ | unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
47
+ | bundler | string | "vite" | The bundler to use. Options: vite, webpack, rspack |
48
+ | compiler | string | "swc" | The compiler to use. Options: babel, swc |
49
+ | linter | string | "eslint" | The tool for running lint checks. Options: eslint, none |
50
+ | classComponent | boolean | false | Use class components instead of functional components |
51
+ | strict | boolean | true | Creates an application with strict mode and strict type checking |
52
+ | js | boolean | false | Generate JavaScript files instead of TypeScript files |
53
+ | minimal | boolean | false | Generate a React app with minimal setup, no separate test files |
54
+
55
+ *Required parameter
56
+
57
+ ## Expected Output
58
+
59
+ The generator creates two main components:
60
+
61
+ ### 1. React Application Code
62
+ ```
63
+ <directory>/<name>/
64
+ ├── src/
65
+ │ ├── main.tsx # Application entry point with React setup
66
+ │ ├── config.ts # Application configuration
67
+ │ ├── layouts/ # Layout components
68
+ │ └── pages/ # Page components for routing
69
+ ├── public/ # Static assets
70
+ ├── tsconfig.json # TypeScript configuration
71
+ ├── vite.config.ts # Vite bundler configuration
72
+ ├── project.json # Project configuration and build targets
73
+ └── index.html # HTML entry point
74
+ ```
75
+
76
+ ### 2. Infrastructure Code
77
+ ```
78
+ common/constructs/
79
+ ├── src/
80
+ │ ├── <name>/ # Infrastructure specific to this website
81
+ │ │ └── index.ts # Website infrastructure stack
82
+ │ │ └── static-website.ts # Contains the StaticWebsite construct
83
+ │ │ └── cloudfront-web-acl.ts # Sets up the ACL
84
+ │ │ └── webacl_event_handler # Custom resource to support cross region ACL deployment
85
+ │ └── index.ts # Exports for all constructs
86
+ ├── tsconfig.json # TypeScript configuration
87
+ └── project.json # Project configuration and build targets
88
+ ```
89
+
90
+ Additionally, it:
91
+ 1. Configures build settings for production deployment
92
+ 2. Installs required dependencies:
93
+ - @aws-northstar/ui
94
+ - @cloudscape-design/components
95
+ - @cloudscape-design/board-components
96
+ - react-router-dom
97
+ - aws-cdk-lib
98
+ - constructs
99
+ - cdk-nag
100
+
101
+ ## Infrastructure Architecture
102
+
103
+ ```mermaid
104
+ graph TD
105
+ subgraph AWS Cloud
106
+ CF[CloudFront Distribution] --> S3[S3 Bucket]
107
+ CF --> WAF[WAF Rules]
108
+ OAC[Origin Access Control] --> S3
109
+ end
110
+ ```
111
+
112
+ The infrastructure stack deploys:
113
+ 1. **CloudFront Distribution**
114
+ - Global content delivery network
115
+ - Edge caching for static assets
116
+ - HTTPS enabled by default
117
+
118
+ 2. **S3 Bucket**
119
+ - Static website content hosting
120
+ - Private access through CloudFront
121
+ - Versioning enabled
122
+
123
+ 3. **WAF (Web Application Firewall)**
124
+ - Web exploit protection
125
+ - Rate limiting
126
+ - IP-based filtering
127
+
128
+ 4. **Origin Access Control**
129
+ - Secure S3 bucket access
130
+ - Restricted to CloudFront only
131
+
132
+ ## Using the StaticWebsite Construct
133
+
134
+ After generating the application, you can use the generated `StaticWebsite` construct in your CDK code:
135
+
136
+ ```typescript
137
+ import { App, Stack } from 'aws-cdk-lib';
138
+ import { StaticWebsite } from ':my-org/common-constructs';
139
+
140
+ export class MyWebsiteStack extends Stack {
141
+ constructor(scope: App, id: string) {
142
+ super(scope, id);
143
+
144
+ // Create the static website with the pre-configured setup
145
+ new StaticWebsite(this, 'MyWebsite');
146
+ }
147
+ }
148
+ ```
149
+
150
+ The StaticWebsite construct is pre-configured with:
151
+ - S3 bucket for hosting website content
152
+ - CloudFront distribution with Origin Access Control
153
+ - WAF rules for security
154
+ - Cross-region support for WAF configuration
155
+
156
+ Since all the infrastructure code is generated in your project's `common/constructs` directory, you have full control to customize the implementation. You can modify:
157
+ - `static-website.ts` to adjust the CloudFront distribution settings or S3 bucket configuration
158
+ - `cloudfront-web-acl.ts` to customize WAF rules and rate limiting
159
+ - `webacl_event_handler` to modify the cross-region WAF deployment behavior
160
+
161
+ The generated code serves as a starting point that you can adapt to your specific requirements.
162
+
163
+ ## Runtime Configuration
164
+
165
+ The generator includes a RuntimeConfig system that bridges your infrastructure and frontend application. This system allows you to:
166
+
167
+ 1. **Share Configuration**: Pass runtime configuration from your infrastructure to your React application
168
+ 2. **Type Safety**: Configuration is fully typed using TypeScript interfaces
169
+ 3. **Context-Based Access**: Access configuration anywhere in your React components using React Context
170
+
171
+ ### Infrastructure Usage
172
+
173
+ In your CDK code, you can set runtime configuration using the RuntimeConfig construct:
174
+
175
+ ```typescript
176
+ import { RuntimeConfig } from ':my-org/common-constructs';
177
+
178
+ export class MyWebsiteStack extends Stack {
179
+ constructor(scope: App, id: string) {
180
+ super(scope, id);
181
+
182
+ // Get or create the RuntimeConfig instance
183
+ const runtimeConfig = RuntimeConfig.ensure(this);
184
+
185
+ // Set configuration values
186
+ runtimeConfig.config.myFeature = {
187
+ apiEndpoint: 'https://api.example.com',
188
+ region: Stack.of(this).region
189
+ };
190
+ }
191
+ }
192
+ ```
193
+
194
+ ### Frontend Usage
195
+
196
+ In your React components, you can access the runtime configuration using the RuntimeConfigContext:
197
+
198
+ ```typescript
199
+ import { useContext } from 'react';
200
+ import { RuntimeConfigContext } from './components/RuntimeConfig';
201
+
202
+ const MyComponent = () => {
203
+ const runtimeConfig = useContext(RuntimeConfigContext);
204
+
205
+ return (
206
+ <div>
207
+ <p>API Endpoint: {runtimeConfig?.myFeature?.apiEndpoint}</p>
208
+ <p>Region: {runtimeConfig?.myFeature?.region}</p>
209
+ </div>
210
+ );
211
+ };
212
+ ```
213
+
214
+ The RuntimeConfigProvider is automatically set up in your application's entry point:
215
+
216
+ ```typescript
217
+ import RuntimeConfigProvider from './components/RuntimeConfig';
218
+
219
+ const App = () => (
220
+ <RuntimeConfigProvider>
221
+ <BrowserRouter>
222
+ {/* Your app components */}
223
+ </BrowserRouter>
224
+ </RuntimeConfigProvider>
225
+ );
226
+ ```
227
+
228
+ This configuration system is particularly useful when:
229
+ - Integrating with AWS services that require runtime configuration (e.g., Cognito, API Gateway)
230
+ - Managing environment-specific settings
231
+ - Sharing infrastructure outputs with your frontend application
232
+
233
+ ## Building the Application
234
+
235
+ ### Development Build
236
+ To run the application in development mode with hot-reload:
237
+ ```bash
238
+ nx serve my-website
239
+ ```
240
+
241
+ ### Production Build
242
+ To create a production build:
243
+ ```bash
244
+ nx build my-website
245
+ ```
246
+
247
+ All built code is located in the `dist` folder at the root of your workspace. For example, if your application is in `apps/web/my-website`, the built code will be in `dist/apps/web/my-website`.
248
+
249
+ The production build:
250
+ - Minifies JavaScript and CSS
251
+ - Optimizes assets
252
+ - Generates source maps
253
+ - Creates a deployment-ready bundle