@aws/nx-plugin 0.1.6 → 0.2.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 (115) hide show
  1. package/LICENSE-THIRD-PARTY +114 -244
  2. package/generators.json +1 -7
  3. package/package.json +1 -1
  4. package/src/cloudscape-website/app/README.md +84 -48
  5. package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +157 -218
  6. package/src/cloudscape-website/app/files/app/README.md.template +44 -0
  7. package/src/cloudscape-website/app/files/app/src/layouts/App/index.tsx.template +40 -43
  8. package/src/cloudscape-website/app/files/app/src/layouts/App/navitems.ts.template +3 -3
  9. package/src/cloudscape-website/app/files/app/src/layouts/Routes/index.tsx.template +4 -6
  10. package/src/cloudscape-website/app/files/app/src/main.tsx.template +7 -10
  11. package/src/cloudscape-website/app/files/app/src/pages/Home/index.tsx.template +0 -2
  12. package/src/cloudscape-website/app/files/common/constructs/src/app/static-websites/__websiteNameKebabCase__.ts.template +13 -0
  13. package/src/cloudscape-website/app/files/common/constructs/src/{__websiteNameKebabCase__ → core}/static-website.ts.template +74 -144
  14. package/src/cloudscape-website/app/generator.js +74 -64
  15. package/src/cloudscape-website/app/generator.js.map +1 -1
  16. package/src/cloudscape-website/app/schema.d.ts +3 -4
  17. package/src/cloudscape-website/app/schema.json +1 -24
  18. package/src/cloudscape-website/cognito-auth/README.md +53 -32
  19. package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +161 -125
  20. package/src/cloudscape-website/cognito-auth/files/app/components/CognitoAuth/index.tsx.template +53 -39
  21. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/core/user-identity.ts.template +168 -0
  22. package/src/cloudscape-website/cognito-auth/generator.js +129 -46
  23. package/src/cloudscape-website/cognito-auth/generator.js.map +1 -1
  24. package/src/cloudscape-website/cognito-auth/schema.d.ts +1 -0
  25. package/src/cloudscape-website/cognito-auth/schema.json +7 -1
  26. package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +15 -17
  27. package/src/cloudscape-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +7 -10
  28. package/src/cloudscape-website/runtime-config/files/app/hooks/useRuntimeConfig.tsx.template +13 -0
  29. package/src/cloudscape-website/runtime-config/generator.js +3 -1
  30. package/src/cloudscape-website/runtime-config/generator.js.map +1 -1
  31. package/src/infra/app/README.md +71 -46
  32. package/src/infra/app/__snapshots__/generator.spec.ts.snap +114 -252
  33. package/src/infra/app/files/app/README.md.template +76 -0
  34. package/src/infra/app/files/app/src/main.ts.template +18 -0
  35. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/aws-prototyping.guard +1282 -0
  36. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/cfn-nag.guard +6839 -0
  37. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/hipaa-security.guard +2807 -0
  38. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/nist-csf.guard +2585 -0
  39. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/pci-dss-3-2-1.guard +2236 -0
  40. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-reliability-pillar.guard +885 -0
  41. package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-security-pillar.guard +2205 -0
  42. package/src/infra/app/files/common/constructs/src/core/cfn-guard.ts.template +63 -0
  43. package/src/infra/app/generator.js +17 -3
  44. package/src/infra/app/generator.js.map +1 -1
  45. package/src/infra/app/schema.d.ts +10 -1
  46. package/src/infra/app/schema.json +16 -8
  47. package/src/trpc/backend/README.md +102 -80
  48. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +37 -17
  49. package/src/trpc/backend/files/backend/README.md.template +33 -0
  50. package/src/trpc/backend/files/common/constructs/src/app/trpc-apis/__apiNameKebabCase__.ts.template +18 -0
  51. package/src/trpc/backend/files/common/constructs/src/{__apiNameKebabCase__/index.ts.template → core/trpc-api.ts.template} +12 -16
  52. package/src/trpc/backend/files/schema/README.md.template +33 -0
  53. package/src/trpc/backend/generator.js +29 -43
  54. package/src/trpc/backend/generator.js.map +1 -1
  55. package/src/trpc/backend/schema.d.ts +3 -1
  56. package/src/trpc/backend/schema.json +8 -13
  57. package/src/trpc/react/README.md +46 -66
  58. package/src/trpc/react/__snapshots__/generator.spec.ts.snap +104 -65
  59. package/src/trpc/react/files/src/components/TrpcClients/IsolatedTrpcProvider.tsx.template +75 -0
  60. package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +1 -0
  61. package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +10 -0
  62. package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +5 -0
  63. package/src/trpc/react/files/src/hooks/useSigV4.tsx.template +38 -0
  64. package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +3 -0
  65. package/src/trpc/react/generator.js +123 -24
  66. package/src/trpc/react/generator.js.map +1 -1
  67. package/src/trpc/react/schema.json +2 -2
  68. package/src/ts/cjs-to-esm/generator.js.map +1 -1
  69. package/src/ts/lib/eslint.d.ts +1 -1
  70. package/src/ts/lib/eslint.js +59 -11
  71. package/src/ts/lib/eslint.js.map +1 -1
  72. package/src/ts/lib/files/README.md.template +33 -0
  73. package/src/ts/lib/generator.js +11 -4
  74. package/src/ts/lib/generator.js.map +1 -1
  75. package/src/ts/lib/schema.d.ts +1 -3
  76. package/src/ts/lib/schema.json +2 -15
  77. package/src/ts/lib/ts-project-utils.js.map +1 -1
  78. package/src/ts/lib/vitest.js +14 -0
  79. package/src/ts/lib/vitest.js.map +1 -1
  80. package/src/utils/ast.d.ts +13 -0
  81. package/src/utils/ast.js +102 -0
  82. package/src/utils/ast.js.map +1 -0
  83. package/src/utils/files/common/constructs/src/app/index.ts.template +0 -0
  84. package/src/utils/files/common/constructs/src/{runtime-config → core}/runtime-config.ts.template +3 -5
  85. package/src/utils/files/common/constructs/src/index.ts.template +2 -1
  86. package/src/utils/files/common/readme/README.md.template +33 -0
  87. package/src/utils/files/common/types/src/runtime-config.ts.template +1 -13
  88. package/src/utils/format.js.map +1 -1
  89. package/src/utils/names.d.ts +2 -0
  90. package/src/utils/names.js +27 -0
  91. package/src/utils/names.js.map +1 -0
  92. package/src/utils/npm-scope.js.map +1 -1
  93. package/src/utils/paths.js.map +1 -1
  94. package/src/utils/shared-constructs.js +37 -4
  95. package/src/utils/shared-constructs.js.map +1 -1
  96. package/src/utils/versions.d.ts +15 -9
  97. package/src/utils/versions.js +14 -8
  98. package/src/utils/versions.js.map +1 -1
  99. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/cloudfront-web-acl.ts.template +0 -317
  100. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/index.ts.template +0 -4
  101. package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/webacl_event_handler/index.ts.template +0 -301
  102. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/index.ts.template +0 -4
  103. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/user-identity.ts.template +0 -66
  104. package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/userpool-with-mfa.ts.template +0 -70
  105. package/src/gitlab/generator.d.ts +0 -8
  106. package/src/gitlab/generator.js +0 -16
  107. package/src/gitlab/generator.js.map +0 -1
  108. package/src/gitlab/schema.d.ts +0 -9
  109. package/src/gitlab/schema.json +0 -52
  110. package/src/infra/app/files/src/main.ts.template +0 -37
  111. package/src/trpc/react/files/src/components/TRPCClientProvider/index.tsx.template +0 -34
  112. package/src/trpc/react/files/src/hooks/useTrpc.tsx.template +0 -5
  113. /package/src/infra/app/files/{cdk.json → app/cdk.json} +0 -0
  114. /package/src/infra/app/files/{src → app/src}/stacks/application-stack.ts.template +0 -0
  115. /package/src/utils/files/common/constructs/src/{runtime-config → core}/index.ts.template +0 -0
@@ -1,6 +1,7 @@
1
1
  # Cloudscape Website App Generator
2
2
 
3
3
  ## Overview
4
+
4
5
  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
 
6
7
  ## Usage
@@ -10,12 +11,14 @@ You can generate a new Cloudscape website application in two ways:
10
11
  ### 1. Using VSCode IDE
11
12
 
12
13
  First, install the NX Console extension for VSCode:
14
+
13
15
  1. Open VSCode
14
16
  2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
15
17
  3. Search for "Nx Console"
16
18
  4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
17
19
 
18
20
  Then generate your application:
21
+
19
22
  1. Open the NX Console in VSCode
20
23
  2. Click on "Generate"
21
24
  3. Search for "cloudscape-website#app"
@@ -25,11 +28,13 @@ Then generate your application:
25
28
  ### 2. Using CLI
26
29
 
27
30
  Generate the application:
31
+
28
32
  ```bash
29
33
  nx g @aws/nx-plugin:cloudscape-website#app my-website --directory=apps/web
30
34
  ```
31
35
 
32
36
  You can also perform a dry-run to see what files would be generated without actually creating them:
37
+
33
38
  ```bash
34
39
  nx g @aws/nx-plugin:cloudscape-website#app my-website --directory=apps/web --dry-run
35
40
  ```
@@ -38,27 +43,28 @@ Both methods will create a new Cloudscape website application in `apps/web/my-we
38
43
 
39
44
  ## Input Parameters
40
45
 
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
46
+ | Parameter | Type | Default | Description |
47
+ | -------------- | ------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
48
+ | name\* | string | - | The name of the application (required). Must start with a letter and not contain colons. |
49
+ | directory | string | "packages" | The directory to store the application in. |
50
+ | style | string | "css" | The file extension for style files. Options: css, scss, less, tailwind, styled-components, @emotion/styled, styled-jsx, none |
51
+ | unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
52
+ | bundler | string | "vite" | The bundler to use. Options: vite, webpack, rspack |
53
+ | compiler | string | "swc" | The compiler to use. Options: babel, swc |
54
+ | linter | string | "eslint" | The tool for running lint checks. Options: eslint, none |
55
+ | classComponent | boolean | false | Use class components instead of functional components |
56
+ | strict | boolean | true | Creates an application with strict mode and strict type checking |
57
+ | js | boolean | false | Generate JavaScript files instead of TypeScript files |
58
+ | minimal | boolean | false | Generate a React app with minimal setup, no separate test files |
59
+
60
+ \*Required parameter
56
61
 
57
62
  ## Expected Output
58
63
 
59
64
  The generator creates two main components:
60
65
 
61
66
  ### 1. React Application Code
67
+
62
68
  ```
63
69
  <directory>/<name>/
64
70
  ├── src/
@@ -74,53 +80,67 @@ The generator creates two main components:
74
80
  ```
75
81
 
76
82
  ### 2. Infrastructure Code
83
+
77
84
  ```
78
85
  common/constructs/
79
86
  ├── 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
87
+ | └── index.ts
88
+ | └── app/
89
+ | | ├── index.ts
90
+ | | └── static-websites
91
+ | | └── index.ts
92
+ | | └── <name>.ts # Infrastructure specific to your website
93
+ │ └── core/
94
+ │ └── index.ts
95
+ │ └── static-website.ts # Contains the generic StaticWebsite construct
86
96
  ├── tsconfig.json # TypeScript configuration
87
97
  └── project.json # Project configuration and build targets
88
98
  ```
89
99
 
90
100
  Additionally, it:
101
+
91
102
  1. Configures build settings for production deployment
92
103
  2. Installs required dependencies:
93
- - @aws-northstar/ui
94
104
  - @cloudscape-design/components
95
105
  - @cloudscape-design/board-components
96
106
  - react-router-dom
97
107
  - aws-cdk-lib
98
108
  - constructs
99
- - cdk-nag
109
+ - cdk-app-cli
100
110
 
101
111
  ## Infrastructure Architecture
102
112
 
103
113
  ```mermaid
104
114
  graph TD
105
115
  subgraph AWS Cloud
116
+ CF --> WAF
117
+ subgraph ApplicationStack
106
118
  CF[CloudFront Distribution] --> S3[S3 Bucket]
107
- CF --> WAF[WAF Rules]
108
119
  OAC[Origin Access Control] --> S3
120
+ end
121
+ subgraph "WafStack (us-east-1)"
122
+ WAF[WAF Rules]
123
+ end
109
124
  end
110
125
  ```
111
126
 
112
- The infrastructure stack deploys:
127
+ The website construct deploys:
128
+
113
129
  1. **CloudFront Distribution**
130
+
114
131
  - Global content delivery network
115
132
  - Edge caching for static assets
116
133
  - HTTPS enabled by default
117
134
 
118
135
  2. **S3 Bucket**
136
+
119
137
  - Static website content hosting
120
138
  - Private access through CloudFront
121
139
  - Versioning enabled
122
140
 
123
141
  3. **WAF (Web Application Firewall)**
142
+
143
+ - Deployed as a seperate stack in us-east-1
124
144
  - Web exploit protection
125
145
  - Rate limiting
126
146
  - IP-based filtering
@@ -129,36 +149,31 @@ The infrastructure stack deploys:
129
149
  - Secure S3 bucket access
130
150
  - Restricted to CloudFront only
131
151
 
132
- ## Using the StaticWebsite Construct
152
+ ## Using the generated Construct
133
153
 
134
- After generating the application, you can use the generated `StaticWebsite` construct in your CDK code:
154
+ After generating the application, you can use the generated construct in your CDK code:
135
155
 
136
156
  ```typescript
137
157
  import { App, Stack } from 'aws-cdk-lib';
138
- import { StaticWebsite } from ':my-org/common-constructs';
158
+ import { MyWebsite /* Use you website specific name */ } from ':my-org/common-constructs';
139
159
 
140
160
  export class MyWebsiteStack extends Stack {
141
161
  constructor(scope: App, id: string) {
142
162
  super(scope, id);
143
163
 
144
- // Create the static website with the pre-configured setup
145
- new StaticWebsite(this, 'MyWebsite');
164
+ new MyWebsite(this, 'MyWebsite');
146
165
  }
147
166
  }
148
167
  ```
149
168
 
150
- The StaticWebsite construct is pre-configured with:
169
+ The website construct is pre-configured with:
170
+
151
171
  - S3 bucket for hosting website content
152
172
  - CloudFront distribution with Origin Access Control
153
- - WAF rules for security
173
+ - WAF rules for security (deployed in us-east-1 via seperate stack)
154
174
  - Cross-region support for WAF configuration
155
175
 
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.
176
+ Since all the infrastructure code is generated in your project's `common/constructs` directory, you have full control to customize the implementation. The generated code serves as a starting point that you can adapt to your specific requirements.
162
177
 
163
178
  ## Runtime Configuration
164
179
 
@@ -183,9 +198,10 @@ export class MyWebsiteStack extends Stack {
183
198
  const runtimeConfig = RuntimeConfig.ensure(this);
184
199
 
185
200
  // Set configuration values
201
+ // Be sure to update the IRuntimeConfig interface first with your new definition
186
202
  runtimeConfig.config.myFeature = {
187
203
  apiEndpoint: 'https://api.example.com',
188
- region: Stack.of(this).region
204
+ region: Stack.of(this).region,
189
205
  };
190
206
  }
191
207
  }
@@ -196,16 +212,15 @@ export class MyWebsiteStack extends Stack {
196
212
  In your React components, you can access the runtime configuration using the RuntimeConfigContext:
197
213
 
198
214
  ```typescript
199
- import { useContext } from 'react';
200
- import { RuntimeConfigContext } from './components/RuntimeConfig';
215
+ import { useRuntimeConfig } from './hooks/useRuntimeConfig';
201
216
 
202
217
  const MyComponent = () => {
203
- const runtimeConfig = useContext(RuntimeConfigContext);
218
+ const { myFeature } = useRuntimeConfig();
204
219
 
205
220
  return (
206
221
  <div>
207
- <p>API Endpoint: {runtimeConfig?.myFeature?.apiEndpoint}</p>
208
- <p>Region: {runtimeConfig?.myFeature?.region}</p>
222
+ <p>API Endpoint: {myFeature.apiEndpoint}</p>
223
+ <p>Region: {myFeature.region}</p>
209
224
  </div>
210
225
  );
211
226
  };
@@ -218,14 +233,13 @@ import RuntimeConfigProvider from './components/RuntimeConfig';
218
233
 
219
234
  const App = () => (
220
235
  <RuntimeConfigProvider>
221
- <BrowserRouter>
222
- {/* Your app components */}
223
- </BrowserRouter>
236
+ <BrowserRouter>{/* Your app components */}</BrowserRouter>
224
237
  </RuntimeConfigProvider>
225
238
  );
226
239
  ```
227
240
 
228
241
  This configuration system is particularly useful when:
242
+
229
243
  - Integrating with AWS services that require runtime configuration (e.g., Cognito, API Gateway)
230
244
  - Managing environment-specific settings
231
245
  - Sharing infrastructure outputs with your frontend application
@@ -233,13 +247,17 @@ This configuration system is particularly useful when:
233
247
  ## Building the Application
234
248
 
235
249
  ### Development Build
250
+
236
251
  To run the application in development mode with hot-reload:
252
+
237
253
  ```bash
238
254
  nx serve my-website
239
255
  ```
240
256
 
241
257
  ### Production Build
258
+
242
259
  To create a production build:
260
+
243
261
  ```bash
244
262
  nx build my-website
245
263
  ```
@@ -247,7 +265,25 @@ nx build my-website
247
265
  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
266
 
249
267
  The production build:
268
+
250
269
  - Minifies JavaScript and CSS
251
270
  - Optimizes assets
252
271
  - Generates source maps
253
- - Creates a deployment-ready bundle
272
+ - Creates a deployment-ready bundle
273
+
274
+ ## Local development
275
+
276
+ Once you have deployed your application for the first time, we can pull down a copy of the `runtime-config.json` associated with the website so our local website server will operate as expected. To do this run the following command:
277
+
278
+ ```bash
279
+ AWS_REGION=<YOUR_REGION> CDK_APP_DIR=<CDK_OUT_DIR>/cdk.out pnpm exec nx run @my-org/website:load:runtime-config
280
+ ```
281
+
282
+ - **<YOUR_REGION>:** _the aws region you deployed into i.e: ap-southeast-2_
283
+ - **<CDK_OUT_DIR>:** _the relative path (from the root) to the `cdk.out` directory._
284
+
285
+ For example:
286
+
287
+ ```bash
288
+ AWS_REGION=ap-southeast-2 CDK_APP_DIR=./dist/packages/infra/cdk.out pnpm exec nx run @my-org/website:load:runtime-config
289
+ ```