@aws/nx-plugin 0.13.0 → 0.14.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.
- package/LICENSE-THIRD-PARTY +1103 -309
- package/package.json +7 -7
- package/src/api-connection/schema.json +5 -5
- package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/cloudscape-website/app/generator.js +9 -19
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/cloudscape-website/app/schema.d.ts +0 -24
- package/src/cloudscape-website/app/schema.json +0 -125
- package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +179 -0
- package/src/cloudscape-website/cognito-auth/generator.js +10 -31
- package/src/cloudscape-website/cognito-auth/generator.js.map +1 -1
- package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/cloudscape-website/runtime-config/generator.js +5 -16
- package/src/cloudscape-website/runtime-config/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +48 -10
- package/src/infra/app/generator.js +8 -0
- package/src/infra/app/generator.js.map +1 -1
- package/src/license/README.md +2 -2
- package/src/license/schema.json +2 -2
- package/src/open-api/ts-client/__snapshots__/generator.spec.ts.snap +24 -24
- package/src/open-api/ts-client/__snapshots__/generator.streaming.spec.ts.snap +6 -6
- package/src/open-api/ts-client/files/client.gen.ts.template +1 -1
- package/src/open-api/ts-hooks/generator.js +1 -1
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/py/fast-api/generator.js +1 -1
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/generator.js +2 -2
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/fast-api/schema.json +8 -3
- package/src/trpc/backend/schema.json +2 -2
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +4 -1
- package/src/trpc/react/files/src/components/TrpcClients/TrpcProvider.tsx.template +1 -1
- package/src/trpc/react/generator.js +10 -17
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +95 -36
- package/src/ts/lib/eslint.d.ts +1 -1
- package/src/ts/lib/eslint.js +9 -22
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/lib/generator.js +39 -10
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/vitest.js +14 -52
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/utils/ast.d.ts +27 -7
- package/src/utils/ast.js +143 -64
- package/src/utils/ast.js.map +1 -1
- package/src/utils/config/__snapshots__/utils.spec.ts.snap +1 -0
- package/src/utils/http-api.js +6 -16
- package/src/utils/http-api.js.map +1 -1
- package/src/utils/shared-constructs.js +2 -2
- package/src/utils/shared-constructs.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws/nx-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"generators": "./generators.json",
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"prettier": "^3.4.2",
|
|
15
|
-
"nx": "20.4.
|
|
15
|
+
"nx": "20.4.6"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@apidevtools/swagger-parser": "^10.1.1",
|
|
19
19
|
"@hey-api/openapi-ts": "0.64.4",
|
|
20
20
|
"@iarna/toml": "^2.2.5",
|
|
21
|
-
"@nx/devkit": "
|
|
22
|
-
"@nx/eslint": "
|
|
23
|
-
"@nx/js": "
|
|
24
|
-
"@nx/react": "
|
|
25
|
-
"@nx/vite": "
|
|
21
|
+
"@nx/devkit": "20.4.6",
|
|
22
|
+
"@nx/eslint": "20.4.6",
|
|
23
|
+
"@nx/js": "20.4.6",
|
|
24
|
+
"@nx/react": "20.4.6",
|
|
25
|
+
"@nx/vite": "20.4.6",
|
|
26
26
|
"@nxlv/python": "^20.5.1",
|
|
27
27
|
"@phenomnomnominal/tsquery": "6.1.3",
|
|
28
28
|
"fast-glob": "^3.3.3",
|
|
@@ -6,23 +6,23 @@
|
|
|
6
6
|
"properties": {
|
|
7
7
|
"sourceProject": {
|
|
8
8
|
"type": "string",
|
|
9
|
-
"description": "",
|
|
9
|
+
"description": "The source project which will call the API",
|
|
10
10
|
"$default": {
|
|
11
11
|
"$source": "argv",
|
|
12
12
|
"index": 0
|
|
13
13
|
},
|
|
14
|
-
"x-prompt": "
|
|
14
|
+
"x-prompt": "Select the source project which will call the API",
|
|
15
15
|
"x-dropdown": "projects"
|
|
16
16
|
},
|
|
17
17
|
"targetProject": {
|
|
18
18
|
"type": "string",
|
|
19
|
-
"description": "",
|
|
20
|
-
"x-prompt": "
|
|
19
|
+
"description": "The target project containing your API",
|
|
20
|
+
"x-prompt": "Select the target project containing your API",
|
|
21
21
|
"x-dropdown": "projects"
|
|
22
22
|
},
|
|
23
23
|
"auth": {
|
|
24
24
|
"type": "string",
|
|
25
|
-
"description": "",
|
|
25
|
+
"description": "Authentication strategy (choose from IAM or None)",
|
|
26
26
|
"enum": ["IAM", "None"],
|
|
27
27
|
"x-prompt": "Select your API authentication strategy",
|
|
28
28
|
"default": "IAM"
|
|
@@ -28,6 +28,7 @@ import { defineConfig } from 'vite';
|
|
|
28
28
|
import react from '@vitejs/plugin-react';
|
|
29
29
|
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
30
30
|
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
31
|
+
|
|
31
32
|
export default defineConfig({
|
|
32
33
|
define: {
|
|
33
34
|
global: {},
|
|
@@ -7,7 +7,6 @@ const tslib_1 = require("tslib");
|
|
|
7
7
|
* SPDX-License-Identifier: Apache-2.0
|
|
8
8
|
*/
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
11
10
|
const typescript_1 = require("typescript");
|
|
12
11
|
const react_1 = require("@nx/react");
|
|
13
12
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
@@ -22,7 +21,7 @@ const path_1 = require("path");
|
|
|
22
21
|
const nx_1 = require("../../utils/nx");
|
|
23
22
|
function appGenerator(tree, schema) {
|
|
24
23
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b
|
|
24
|
+
var _a, _b;
|
|
26
25
|
const npmScopePrefix = (0, npm_scope_1.getNpmScopePrefix)(tree);
|
|
27
26
|
const websiteNameClassName = (0, names_1.toClassName)(schema.name);
|
|
28
27
|
const websiteNameKebabCase = (0, names_1.toKebabCase)(schema.name);
|
|
@@ -30,7 +29,7 @@ function appGenerator(tree, schema) {
|
|
|
30
29
|
const websiteContentPath = (0, devkit_1.joinPathFragments)((_a = schema.directory) !== null && _a !== void 0 ? _a : '.', websiteNameKebabCase);
|
|
31
30
|
// TODO: consider exposing and supporting e2e tests
|
|
32
31
|
const e2eTestRunner = 'none';
|
|
33
|
-
yield (0, react_1.applicationGenerator)(tree, Object.assign(Object.assign({}, schema), { name: websiteNameKebabCase, directory: websiteContentPath, routing: false, e2eTestRunner, linter: 'eslint', bundler: 'vite', unitTestRunner: 'vitest', alwaysGenerateProjectJson: true }));
|
|
32
|
+
yield (0, react_1.applicationGenerator)(tree, Object.assign(Object.assign({}, schema), { name: websiteNameKebabCase, directory: websiteContentPath, routing: false, e2eTestRunner, linter: 'eslint', bundler: 'vite', unitTestRunner: 'vitest', alwaysGenerateProjectJson: true, style: 'css' }));
|
|
34
33
|
// Replace with simpler sample source code
|
|
35
34
|
tree.delete((0, devkit_1.joinPathFragments)(websiteContentPath, 'src'));
|
|
36
35
|
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, fullyQualifiedName);
|
|
@@ -129,13 +128,10 @@ function appGenerator(tree, schema) {
|
|
|
129
128
|
});
|
|
130
129
|
}
|
|
131
130
|
const viteConfigPath = (0, devkit_1.joinPathFragments)(libraryRoot, 'vite.config.ts');
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
viteConfigUpdatedContents = (0, ast_1.singleImport)(tree, viteConfigPath, 'tsconfigPaths', 'vite-tsconfig-paths');
|
|
137
|
-
viteConfigUpdatedContents = tsquery_1.tsquery
|
|
138
|
-
.map((0, tsquery_1.ast)(viteConfigUpdatedContents), 'ObjectLiteralExpression', (node) => {
|
|
131
|
+
if (tree.exists(viteConfigPath)) {
|
|
132
|
+
(0, ast_1.addDestructuredImport)(tree, viteConfigPath, ['TanStackRouterVite'], '@tanstack/router-plugin/vite');
|
|
133
|
+
(0, ast_1.addSingleImport)(tree, viteConfigPath, 'tsconfigPaths', 'vite-tsconfig-paths');
|
|
134
|
+
(0, ast_1.replaceIfExists)(tree, viteConfigPath, 'ObjectLiteralExpression', (node) => {
|
|
139
135
|
const updatedProperties = node.properties.map((prop) => {
|
|
140
136
|
if ((0, typescript_1.isPropertyAssignment)(prop) && prop.name.getText() === 'build') {
|
|
141
137
|
const buildConfig = prop.initializer;
|
|
@@ -159,21 +155,15 @@ function appGenerator(tree, schema) {
|
|
|
159
155
|
return prop;
|
|
160
156
|
});
|
|
161
157
|
return typescript_1.factory.createObjectLiteralExpression(updatedProperties, true);
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
viteConfigUpdatedContents = tsquery_1.tsquery
|
|
165
|
-
.map((0, tsquery_1.ast)(viteConfigUpdatedContents), 'ObjectLiteralExpression', (node) => {
|
|
158
|
+
});
|
|
159
|
+
(0, ast_1.replaceIfExists)(tree, viteConfigPath, 'ObjectLiteralExpression', (node) => {
|
|
166
160
|
return typescript_1.factory.createObjectLiteralExpression([
|
|
167
161
|
typescript_1.factory.createPropertyAssignment('define', typescript_1.factory.createObjectLiteralExpression([
|
|
168
162
|
typescript_1.factory.createPropertyAssignment('global', typescript_1.factory.createObjectLiteralExpression()),
|
|
169
163
|
], true)),
|
|
170
164
|
...node.properties,
|
|
171
165
|
], true);
|
|
172
|
-
})
|
|
173
|
-
.getFullText();
|
|
174
|
-
if (viteConfigContents !== viteConfigUpdatedContents) {
|
|
175
|
-
tree.write(viteConfigPath, viteConfigUpdatedContents);
|
|
176
|
-
}
|
|
166
|
+
});
|
|
177
167
|
}
|
|
178
168
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(websiteContentPath, 'tsconfig.json'), (tsconfig) => (Object.assign(Object.assign({}, tsconfig), { compilerOptions: Object.assign(Object.assign({}, tsconfig.compilerOptions), { moduleResolution: 'Bundler', module: 'Preserve' }) })));
|
|
179
169
|
const outDirToRootRelativePath = (0, path_1.relative)((0, devkit_1.joinPathFragments)(tree.root, websiteContentPath), tree.root);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/app/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/app/generator.ts"],"names":[],"mappings":";;AA8CA,oCAwYC;;AAtbD;;;GAGG;AACH,uCAaoB;AACpB,2CAKoB;AAEpB,qCAAiD;AACjD,qEAIuC;AACvC,qDAAwE;AACxE,oEAAmE;AACnE,mDAAoD;AACpD,6CAA0D;AAC1D,6CAA6D;AAC7D,yCAKyB;AACzB,+CAA0D;AAC1D,+BAAgC;AAChC,uCAAgD;AAEhD,SAAsB,YAAY,CAAC,IAAU,EAAE,MAA0B;;;QACvE,MAAM,cAAc,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,M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F,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBACxB,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CAAA;AACD,kBAAe,YAAY,CAAC"}
|
|
@@ -6,30 +6,6 @@ import { SupportedStyles } from '@nx/react';
|
|
|
6
6
|
|
|
7
7
|
export interface AppGeneratorSchema {
|
|
8
8
|
name: string;
|
|
9
|
-
style: SupportedStyles;
|
|
10
|
-
skipFormat?: boolean;
|
|
11
9
|
directory?: string;
|
|
12
|
-
tags?: string;
|
|
13
|
-
// unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
14
|
-
inSourceTests?: boolean;
|
|
15
|
-
// TODO: consider exposing if swc paths issue can be addressed https://github.com/swc-project/swc/discussions/8396
|
|
16
|
-
// or if alternative compiler can be used for e2e tests
|
|
17
|
-
// e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
18
|
-
// linter: Linter;
|
|
19
|
-
pascalCaseFiles?: boolean;
|
|
20
|
-
classComponent?: boolean;
|
|
21
|
-
routing?: boolean;
|
|
22
|
-
skipNxJson?: boolean;
|
|
23
|
-
js?: boolean;
|
|
24
|
-
globalCss?: boolean;
|
|
25
|
-
strict?: boolean;
|
|
26
|
-
setParserOptionsProject?: boolean;
|
|
27
|
-
compiler?: 'babel' | 'swc';
|
|
28
|
-
remotes?: string[];
|
|
29
|
-
devServerPort?: number;
|
|
30
|
-
skipPackageJson?: boolean;
|
|
31
|
-
rootProject?: boolean;
|
|
32
|
-
// bundler?: 'webpack' | 'vite' | 'rspack';
|
|
33
|
-
minimal?: boolean;
|
|
34
10
|
skipInstall?: boolean;
|
|
35
11
|
}
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
{
|
|
9
9
|
"command": "nx g app myapp --directory=myorg",
|
|
10
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
11
|
}
|
|
16
12
|
],
|
|
17
13
|
"type": "object",
|
|
@@ -33,127 +29,6 @@
|
|
|
33
29
|
"x-priority": "important",
|
|
34
30
|
"default": "packages",
|
|
35
31
|
"x-prompt": "What directory would you like to store your application in?"
|
|
36
|
-
},
|
|
37
|
-
"style": {
|
|
38
|
-
"description": "The file extension to be used for style files.",
|
|
39
|
-
"type": "string",
|
|
40
|
-
"default": "css",
|
|
41
|
-
"alias": "s",
|
|
42
|
-
"x-prompt": {
|
|
43
|
-
"message": "Which stylesheet format would you like to use?",
|
|
44
|
-
"type": "list",
|
|
45
|
-
"items": [
|
|
46
|
-
{
|
|
47
|
-
"value": "css",
|
|
48
|
-
"label": "CSS"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"value": "scss",
|
|
52
|
-
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"value": "less",
|
|
56
|
-
"label": "LESS [ https://lesscss.org ]"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"value": "tailwind",
|
|
60
|
-
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"value": "styled-components",
|
|
64
|
-
"label": "styled-components [ https://styled-components.com ]"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"value": "@emotion/styled",
|
|
68
|
-
"label": "emotion [ https://emotion.sh ]"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"value": "styled-jsx",
|
|
72
|
-
"label": "styled-jsx [ https://www.npmjs.com/package/styled-jsx ]"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"value": "none",
|
|
76
|
-
"label": "None"
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
"skipFormat": {
|
|
82
|
-
"description": "Skip formatting files.",
|
|
83
|
-
"type": "boolean",
|
|
84
|
-
"default": false,
|
|
85
|
-
"x-priority": "internal"
|
|
86
|
-
},
|
|
87
|
-
"skipNxJson": {
|
|
88
|
-
"description": "Skip updating `nx.json` with default options based on values provided to this app.",
|
|
89
|
-
"type": "boolean",
|
|
90
|
-
"default": false,
|
|
91
|
-
"x-priority": "internal"
|
|
92
|
-
},
|
|
93
|
-
"inSourceTests": {
|
|
94
|
-
"type": "boolean",
|
|
95
|
-
"default": false,
|
|
96
|
-
"description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html"
|
|
97
|
-
},
|
|
98
|
-
"tags": {
|
|
99
|
-
"type": "string",
|
|
100
|
-
"description": "Add tags to the application (used for linting).",
|
|
101
|
-
"alias": "t"
|
|
102
|
-
},
|
|
103
|
-
"pascalCaseFiles": {
|
|
104
|
-
"type": "boolean",
|
|
105
|
-
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
106
|
-
"alias": "P",
|
|
107
|
-
"default": false
|
|
108
|
-
},
|
|
109
|
-
"classComponent": {
|
|
110
|
-
"type": "boolean",
|
|
111
|
-
"description": "Use class components instead of functional component.",
|
|
112
|
-
"alias": "C",
|
|
113
|
-
"default": false
|
|
114
|
-
},
|
|
115
|
-
"js": {
|
|
116
|
-
"type": "boolean",
|
|
117
|
-
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
118
|
-
"default": false
|
|
119
|
-
},
|
|
120
|
-
"globalCss": {
|
|
121
|
-
"type": "boolean",
|
|
122
|
-
"description": "Default is `false`. When `true`, the component is generated with `*.css`/`*.scss` instead of `*.module.css`/`*.module.scss`.",
|
|
123
|
-
"default": false
|
|
124
|
-
},
|
|
125
|
-
"strict": {
|
|
126
|
-
"type": "boolean",
|
|
127
|
-
"description": "Creates an application with strict mode and strict type checking.",
|
|
128
|
-
"default": true
|
|
129
|
-
},
|
|
130
|
-
"setParserOptionsProject": {
|
|
131
|
-
"type": "boolean",
|
|
132
|
-
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
133
|
-
"default": false
|
|
134
|
-
},
|
|
135
|
-
"compiler": {
|
|
136
|
-
"type": "string",
|
|
137
|
-
"description": "The compiler to use.",
|
|
138
|
-
"enum": ["babel", "swc"],
|
|
139
|
-
"default": "swc"
|
|
140
|
-
},
|
|
141
|
-
"skipPackageJson": {
|
|
142
|
-
"description": "Do not add dependencies to `package.json`.",
|
|
143
|
-
"type": "boolean",
|
|
144
|
-
"default": false,
|
|
145
|
-
"x-priority": "internal"
|
|
146
|
-
},
|
|
147
|
-
"rootProject": {
|
|
148
|
-
"description": "Create a application at the root of the workspace",
|
|
149
|
-
"type": "boolean",
|
|
150
|
-
"default": false,
|
|
151
|
-
"hidden": true
|
|
152
|
-
},
|
|
153
|
-
"minimal": {
|
|
154
|
-
"description": "Generate a React app with a minimal setup, no separate test files.",
|
|
155
|
-
"type": "boolean",
|
|
156
|
-
"default": false
|
|
157
32
|
}
|
|
158
33
|
},
|
|
159
34
|
"required": ["name"],
|
|
@@ -245,11 +245,190 @@ export class UserIdentity extends Construct {
|
|
|
245
245
|
|
|
246
246
|
exports[`cognito-auth generator > should not be able to run the generator multiple times 1`] = `[Error: This generator has already been run on test-project.]`;
|
|
247
247
|
|
|
248
|
+
exports[`cognito-auth generator > should update AppLayout > app-layout-with-auth 1`] = `
|
|
249
|
+
"import { useAuth } from 'react-oidc-context';
|
|
250
|
+
import * as React from 'react';
|
|
251
|
+
import { createContext, useCallback, useEffect, useState } from 'react';
|
|
252
|
+
import { NavItems } from './navitems';
|
|
253
|
+
import Config from '../../config';
|
|
254
|
+
|
|
255
|
+
import {
|
|
256
|
+
BreadcrumbGroup,
|
|
257
|
+
BreadcrumbGroupProps,
|
|
258
|
+
SideNavigation,
|
|
259
|
+
TopNavigation,
|
|
260
|
+
} from '@cloudscape-design/components';
|
|
261
|
+
|
|
262
|
+
import CloudscapeAppLayout, {
|
|
263
|
+
AppLayoutProps,
|
|
264
|
+
} from '@cloudscape-design/components/app-layout';
|
|
265
|
+
|
|
266
|
+
import { matchByPath, useLocation, useNavigate } from '@tanstack/react-router';
|
|
267
|
+
import { Outlet } from '@tanstack/react-router';
|
|
268
|
+
|
|
269
|
+
const getBreadcrumbs = (
|
|
270
|
+
pathName: string,
|
|
271
|
+
search: string,
|
|
272
|
+
defaultBreadcrumb: string,
|
|
273
|
+
availableRoutes?: string[],
|
|
274
|
+
) => {
|
|
275
|
+
const segments = [
|
|
276
|
+
defaultBreadcrumb,
|
|
277
|
+
...pathName.split('/').filter((segment) => segment !== ''),
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
return segments.map((segment, i) => {
|
|
281
|
+
const href =
|
|
282
|
+
i === 0
|
|
283
|
+
? '/'
|
|
284
|
+
: \`/\${segments
|
|
285
|
+
.slice(1, i + 1)
|
|
286
|
+
.join('/')
|
|
287
|
+
.replace('//', '/')}\`;
|
|
288
|
+
|
|
289
|
+
const matched =
|
|
290
|
+
!availableRoutes || availableRoutes.find((r) => matchByPath(r, href, {}));
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
href: matched ? \`\${href}\${search}\` : '#',
|
|
294
|
+
text: segment,
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export interface AppLayoutContext {
|
|
300
|
+
appLayoutProps: AppLayoutProps;
|
|
301
|
+
setAppLayoutProps: (props: AppLayoutProps) => void;
|
|
302
|
+
displayHelpPanel: (helpContent: React.ReactNode) => void;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Context for updating/retrieving the AppLayout.
|
|
307
|
+
*/
|
|
308
|
+
export const AppLayoutContext = createContext({
|
|
309
|
+
appLayoutProps: {},
|
|
310
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
311
|
+
setAppLayoutProps: (_: AppLayoutProps) => {},
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
313
|
+
displayHelpPanel: (_: React.ReactNode) => {},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Defines the App layout and contains logic for routing.
|
|
318
|
+
*/
|
|
319
|
+
const AppLayout: React.FC = () => {
|
|
320
|
+
const { user, removeUser, signoutRedirect, clearStaleState } = useAuth();
|
|
321
|
+
const navigate = useNavigate();
|
|
322
|
+
const appLayout = React.useRef<AppLayoutProps.Ref>(null);
|
|
323
|
+
const [activeBreadcrumbs, setActiveBreadcrumbs] = useState<
|
|
324
|
+
BreadcrumbGroupProps.Item[]
|
|
325
|
+
>([{ text: '/', href: '/' }]);
|
|
326
|
+
const [appLayoutProps, setAppLayoutProps] = useState<AppLayoutProps>({});
|
|
327
|
+
const { pathname, search } = useLocation();
|
|
328
|
+
const setAppLayoutPropsSafe = useCallback(
|
|
329
|
+
(props: AppLayoutProps) => {
|
|
330
|
+
JSON.stringify(appLayoutProps) !== JSON.stringify(props) &&
|
|
331
|
+
setAppLayoutProps(props);
|
|
332
|
+
},
|
|
333
|
+
[appLayoutProps],
|
|
334
|
+
);
|
|
335
|
+
useEffect(() => {
|
|
336
|
+
const breadcrumbs = getBreadcrumbs(
|
|
337
|
+
pathname,
|
|
338
|
+
Object.entries(search).reduce((p, [k, v]) => p + \`\${k}=\${v}\`, ''),
|
|
339
|
+
'/',
|
|
340
|
+
);
|
|
341
|
+
setActiveBreadcrumbs(breadcrumbs);
|
|
342
|
+
}, [pathname, search]);
|
|
343
|
+
const onNavigate = useCallback(
|
|
344
|
+
(
|
|
345
|
+
e: CustomEvent<{
|
|
346
|
+
href: string;
|
|
347
|
+
external?: boolean;
|
|
348
|
+
}>,
|
|
349
|
+
) => {
|
|
350
|
+
if (!e.detail.external) {
|
|
351
|
+
e.preventDefault();
|
|
352
|
+
setAppLayoutPropsSafe({
|
|
353
|
+
contentType: undefined,
|
|
354
|
+
});
|
|
355
|
+
navigate({ to: e.detail.href });
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
[navigate, setAppLayoutPropsSafe],
|
|
359
|
+
);
|
|
360
|
+
return (
|
|
361
|
+
<AppLayoutContext.Provider
|
|
362
|
+
value={{
|
|
363
|
+
appLayoutProps,
|
|
364
|
+
setAppLayoutProps: setAppLayoutPropsSafe,
|
|
365
|
+
displayHelpPanel: (helpContent: React.ReactNode) => {
|
|
366
|
+
setAppLayoutPropsSafe({ tools: helpContent, toolsHide: false });
|
|
367
|
+
appLayout.current?.openTools();
|
|
368
|
+
},
|
|
369
|
+
}}
|
|
370
|
+
>
|
|
371
|
+
<TopNavigation
|
|
372
|
+
identity={{
|
|
373
|
+
href: '/',
|
|
374
|
+
title: Config.applicationName,
|
|
375
|
+
logo: {
|
|
376
|
+
src: Config.logo,
|
|
377
|
+
},
|
|
378
|
+
}}
|
|
379
|
+
utilities={[
|
|
380
|
+
{
|
|
381
|
+
type: 'menu-dropdown',
|
|
382
|
+
text: \`\${user?.profile?.['cognito:username']}\`,
|
|
383
|
+
iconName: 'user-profile-active',
|
|
384
|
+
onItemClick: (e) => {
|
|
385
|
+
if (e.detail.id === 'signout') {
|
|
386
|
+
removeUser();
|
|
387
|
+
signoutRedirect({
|
|
388
|
+
post_logout_redirect_uri: window.location.origin,
|
|
389
|
+
extraQueryParams: {
|
|
390
|
+
redirect_uri: window.location.origin,
|
|
391
|
+
response_type: 'code',
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
clearStaleState();
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
items: [{ id: 'signout', text: 'Sign out' }],
|
|
398
|
+
},
|
|
399
|
+
]}
|
|
400
|
+
/>
|
|
401
|
+
<CloudscapeAppLayout
|
|
402
|
+
ref={appLayout}
|
|
403
|
+
breadcrumbs={
|
|
404
|
+
<BreadcrumbGroup onFollow={onNavigate} items={activeBreadcrumbs} />
|
|
405
|
+
}
|
|
406
|
+
toolsHide
|
|
407
|
+
navigation={
|
|
408
|
+
<SideNavigation
|
|
409
|
+
header={{ text: Config.applicationName, href: '/' }}
|
|
410
|
+
activeHref={pathname}
|
|
411
|
+
onFollow={onNavigate}
|
|
412
|
+
items={NavItems}
|
|
413
|
+
/>
|
|
414
|
+
}
|
|
415
|
+
content={<Outlet />}
|
|
416
|
+
{...appLayoutProps}
|
|
417
|
+
/>
|
|
418
|
+
</AppLayoutContext.Provider>
|
|
419
|
+
);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
export default AppLayout;
|
|
423
|
+
"
|
|
424
|
+
`;
|
|
425
|
+
|
|
248
426
|
exports[`cognito-auth generator > should update main.tsx when RuntimeConfigProvider exists > main-tsx-with-runtime-config 1`] = `
|
|
249
427
|
"import CognitoAuth from './components/CognitoAuth';
|
|
250
428
|
import RuntimeConfigProvider from './components/RuntimeConfig';
|
|
251
429
|
import { RuntimeConfigProvider } from './components/RuntimeConfig';
|
|
252
430
|
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
|
431
|
+
|
|
253
432
|
export function App() {
|
|
254
433
|
return (
|
|
255
434
|
<RuntimeConfigProvider>
|
|
@@ -9,7 +9,6 @@ const tslib_1 = require("tslib");
|
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
10
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
11
11
|
const generator_1 = require("../runtime-config/generator");
|
|
12
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
13
12
|
const typescript_1 = require("typescript");
|
|
14
13
|
const versions_1 = require("../../utils/versions");
|
|
15
14
|
const ast_1 = require("../../utils/ast");
|
|
@@ -26,13 +25,10 @@ function cognitoAuthGenerator(tree, options) {
|
|
|
26
25
|
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree);
|
|
27
26
|
// Add ICognitoProps interface and update IRuntimeConfig
|
|
28
27
|
const runtimeConfigPath = (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.TYPE_DEFINITIONS_DIR, 'src', 'runtime-config.ts');
|
|
29
|
-
const runtimeConfigContent = tree.read(runtimeConfigPath).toString();
|
|
30
|
-
const sourceFile = (0, tsquery_1.ast)(runtimeConfigContent);
|
|
31
28
|
// Check if ICognitoProps interface exists
|
|
32
|
-
const existingCognitoProps =
|
|
29
|
+
const existingCognitoProps = (0, ast_1.query)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="ICognitoProps"]');
|
|
33
30
|
// Check if cognitoProps property exists in IRuntimeConfig
|
|
34
|
-
const existingCognitoPropsInConfig =
|
|
35
|
-
let updatedContent = sourceFile;
|
|
31
|
+
const existingCognitoPropsInConfig = (0, ast_1.query)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="IRuntimeConfig"] PropertySignature[name.text="cognitoProps"]');
|
|
36
32
|
// Add ICognitoProps interface if it doesn't exist
|
|
37
33
|
if (existingCognitoProps.length === 0) {
|
|
38
34
|
const cognitoPropsInterface = typescript_1.factory.createInterfaceDeclaration([typescript_1.factory.createModifier(typescript_1.SyntaxKind.ExportKeyword)], typescript_1.factory.createIdentifier('ICognitoProps'), undefined, undefined, [
|
|
@@ -41,26 +37,17 @@ function cognitoAuthGenerator(tree, options) {
|
|
|
41
37
|
typescript_1.factory.createPropertySignature(undefined, typescript_1.factory.createIdentifier('userPoolId'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.SyntaxKind.StringKeyword)),
|
|
42
38
|
typescript_1.factory.createPropertySignature(undefined, typescript_1.factory.createIdentifier('userPoolWebClientId'), undefined, typescript_1.factory.createKeywordTypeNode(typescript_1.SyntaxKind.StringKeyword)),
|
|
43
39
|
]);
|
|
44
|
-
|
|
45
|
-
return typescript_1.factory.updateSourceFile(node, [
|
|
46
|
-
cognitoPropsInterface,
|
|
47
|
-
...node.statements,
|
|
48
|
-
]);
|
|
49
|
-
});
|
|
40
|
+
(0, ast_1.prependStatements)(tree, runtimeConfigPath, [cognitoPropsInterface]);
|
|
50
41
|
}
|
|
51
42
|
// Add cognitoProps to IRuntimeConfig if it doesn't exist
|
|
52
43
|
if (existingCognitoPropsInConfig.length === 0) {
|
|
53
|
-
|
|
44
|
+
(0, ast_1.replace)(tree, runtimeConfigPath, 'InterfaceDeclaration[name.text="IRuntimeConfig"]', (node) => {
|
|
54
45
|
return typescript_1.factory.updateInterfaceDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [
|
|
55
46
|
...node.members,
|
|
56
47
|
typescript_1.factory.createPropertySignature(undefined, typescript_1.factory.createIdentifier('cognitoProps'), undefined, typescript_1.factory.createTypeReferenceNode('ICognitoProps', undefined)),
|
|
57
48
|
]);
|
|
58
49
|
});
|
|
59
50
|
}
|
|
60
|
-
// Only write if changes were made
|
|
61
|
-
if (updatedContent !== sourceFile) {
|
|
62
|
-
tree.write(runtimeConfigPath, updatedContent.getFullText());
|
|
63
|
-
}
|
|
64
51
|
const identityPath = (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'user-identity.ts');
|
|
65
52
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'app'), srcRoot, options, {
|
|
66
53
|
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
@@ -80,15 +67,13 @@ function cognitoAuthGenerator(tree, options) {
|
|
|
80
67
|
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './user-identity.js');
|
|
81
68
|
}
|
|
82
69
|
const mainTsxPath = (0, devkit_1.joinPathFragments)(srcRoot, 'main.tsx');
|
|
83
|
-
(0, ast_1.
|
|
70
|
+
(0, ast_1.addSingleImport)(tree, mainTsxPath, 'CognitoAuth', './components/CognitoAuth');
|
|
84
71
|
(0, ast_1.replace)(tree, mainTsxPath, 'JsxElement[openingElement.tagName.name="RuntimeConfigProvider"]', (node) => (0, ast_1.createJsxElement)(node.openingElement, [(0, ast_1.createJsxElementFromIdentifier)('CognitoAuth', node.children)], node.closingElement));
|
|
85
72
|
// Update App Layout
|
|
86
73
|
const appLayoutTsxPath = (0, devkit_1.joinPathFragments)(srcRoot, 'components', 'AppLayout', 'index.tsx');
|
|
87
74
|
if (tree.exists(appLayoutTsxPath)) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
updatedContents = tsquery_1.tsquery
|
|
91
|
-
.map((0, tsquery_1.ast)(updatedContents), 'VariableDeclaration', (node) => {
|
|
75
|
+
(0, ast_1.addDestructuredImport)(tree, appLayoutTsxPath, ['useAuth'], 'react-oidc-context');
|
|
76
|
+
(0, ast_1.replace)(tree, appLayoutTsxPath, 'VariableDeclaration', (node) => {
|
|
92
77
|
// Only process if this is the App component
|
|
93
78
|
if (node.name.getText() !== 'AppLayout') {
|
|
94
79
|
return node;
|
|
@@ -110,11 +95,9 @@ function cognitoAuthGenerator(tree, options) {
|
|
|
110
95
|
const newArrowFunction = typescript_1.factory.updateArrowFunction(arrowFunction, arrowFunction.modifiers, arrowFunction.typeParameters, arrowFunction.parameters, arrowFunction.type, arrowFunction.equalsGreaterThanToken, typescript_1.factory.createBlock(newStatements, true));
|
|
111
96
|
// Update the variable declaration
|
|
112
97
|
return typescript_1.factory.updateVariableDeclaration(node, node.name, node.exclamationToken, node.type, newArrowFunction);
|
|
113
|
-
})
|
|
114
|
-
.getFullText();
|
|
98
|
+
});
|
|
115
99
|
// TODO: update utils if they exist by appending to the array
|
|
116
|
-
|
|
117
|
-
.map((0, tsquery_1.ast)(updatedContents), 'JsxSelfClosingElement[tagName.text="TopNavigation"]', (node) => {
|
|
100
|
+
(0, ast_1.replace)(tree, appLayoutTsxPath, 'JsxSelfClosingElement[tagName.text="TopNavigation"]', (node) => {
|
|
118
101
|
// Create the utilities attribute
|
|
119
102
|
const utilitiesAttribute = typescript_1.factory.createJsxAttribute(typescript_1.factory.createIdentifier('utilities'), typescript_1.factory.createJsxExpression(undefined, typescript_1.factory.createArrayLiteralExpression([
|
|
120
103
|
typescript_1.factory.createObjectLiteralExpression([
|
|
@@ -153,11 +136,7 @@ function cognitoAuthGenerator(tree, options) {
|
|
|
153
136
|
...node.attributes.properties,
|
|
154
137
|
utilitiesAttribute,
|
|
155
138
|
]));
|
|
156
|
-
})
|
|
157
|
-
.getFullText();
|
|
158
|
-
if (contents !== updatedContents) {
|
|
159
|
-
tree.write(appLayoutTsxPath, updatedContents);
|
|
160
|
-
}
|
|
139
|
+
});
|
|
161
140
|
}
|
|
162
141
|
else {
|
|
163
142
|
console.info(`Skipping update to ${appLayoutTsxPath} as it does not exist.`);
|