@aws/nx-plugin 0.1.6 → 0.2.1
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 +1554 -3241
- package/generators.json +1 -13
- package/package.json +14 -14
- package/src/cloudscape-website/app/README.md +84 -48
- package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +168 -233
- package/src/cloudscape-website/app/files/app/README.md.template +44 -0
- package/src/cloudscape-website/app/files/app/src/layouts/App/index.tsx.template +40 -43
- package/src/cloudscape-website/app/files/app/src/layouts/App/navitems.ts.template +3 -3
- package/src/cloudscape-website/app/files/app/src/layouts/Routes/index.tsx.template +4 -6
- package/src/cloudscape-website/app/files/app/src/main.tsx.template +7 -10
- package/src/cloudscape-website/app/files/app/src/pages/Home/index.tsx.template +0 -2
- package/src/cloudscape-website/app/files/common/constructs/src/app/static-websites/__websiteNameKebabCase__.ts.template +13 -0
- package/src/cloudscape-website/app/files/common/constructs/src/{__websiteNameKebabCase__ → core}/static-website.ts.template +79 -144
- package/src/cloudscape-website/app/generator.js +90 -74
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/cloudscape-website/app/schema.d.ts +3 -5
- package/src/cloudscape-website/app/schema.json +1 -24
- package/src/cloudscape-website/cognito-auth/README.md +53 -32
- package/src/cloudscape-website/cognito-auth/__snapshots__/generator.spec.ts.snap +162 -124
- package/src/cloudscape-website/cognito-auth/files/app/components/CognitoAuth/index.tsx.template +53 -39
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/core/user-identity.ts.template +168 -0
- package/src/cloudscape-website/cognito-auth/generator.js +130 -47
- package/src/cloudscape-website/cognito-auth/generator.js.map +1 -1
- package/src/cloudscape-website/cognito-auth/schema.d.ts +1 -0
- package/src/cloudscape-website/cognito-auth/schema.json +7 -1
- package/src/cloudscape-website/runtime-config/__snapshots__/generator.spec.ts.snap +20 -15
- package/src/cloudscape-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +7 -10
- package/src/cloudscape-website/runtime-config/files/app/hooks/useRuntimeConfig.tsx.template +13 -0
- package/src/cloudscape-website/runtime-config/generator.js +4 -2
- package/src/cloudscape-website/runtime-config/generator.js.map +1 -1
- package/src/infra/app/README.md +71 -46
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +184 -305
- package/src/infra/app/files/app/README.md.template +76 -0
- package/src/infra/app/files/app/src/main.ts.template +18 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/aws-prototyping.guard +1282 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/cfn-nag.guard +6839 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/hipaa-security.guard +2807 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/nist-csf.guard +2585 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/pci-dss-3-2-1.guard +2236 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-reliability-pillar.guard +885 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard-rules/wa-security-pillar.guard +2205 -0
- package/src/infra/app/files/common/constructs/src/core/cfn-guard.ts.template +63 -0
- package/src/infra/app/generator.js +36 -7
- package/src/infra/app/generator.js.map +1 -1
- package/src/infra/app/schema.d.ts +10 -1
- package/src/infra/app/schema.json +16 -8
- package/src/trpc/backend/README.md +102 -80
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +42 -19
- package/src/trpc/backend/files/backend/README.md.template +33 -0
- package/src/trpc/backend/files/common/constructs/src/app/trpc-apis/__apiNameKebabCase__.ts.template +18 -0
- package/src/trpc/backend/files/common/constructs/src/{__apiNameKebabCase__/index.ts.template → core/trpc-api.ts.template} +12 -16
- package/src/trpc/backend/files/schema/README.md.template +33 -0
- package/src/trpc/backend/generator.js +30 -44
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +3 -1
- package/src/trpc/backend/schema.json +8 -13
- package/src/trpc/react/README.md +46 -66
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +104 -65
- package/src/trpc/react/files/src/components/TrpcClients/IsolatedTrpcProvider.tsx.template +75 -0
- package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +1 -0
- package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +10 -0
- package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +5 -0
- package/src/trpc/react/files/src/hooks/useSigV4.tsx.template +38 -0
- package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +3 -0
- package/src/trpc/react/generator.js +124 -25
- package/src/trpc/react/generator.js.map +1 -1
- package/src/trpc/react/schema.json +2 -2
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +47 -93
- package/src/ts/lib/eslint.d.ts +1 -2
- package/src/ts/lib/eslint.js +62 -21
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/lib/files/README.md.template +33 -0
- package/src/ts/lib/generator.js +44 -5
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/schema.d.ts +1 -4
- package/src/ts/lib/schema.json +2 -21
- package/src/ts/lib/ts-project-utils.js +3 -18
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.js +12 -0
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/utils/ast.d.ts +13 -0
- package/src/utils/ast.js +102 -0
- package/src/utils/ast.js.map +1 -0
- package/src/utils/files/common/constructs/src/app/index.ts.template +0 -0
- package/src/utils/files/common/constructs/src/{runtime-config → core}/runtime-config.ts.template +3 -5
- package/src/utils/files/common/constructs/src/index.ts.template +2 -1
- package/src/utils/files/common/readme/README.md.template +33 -0
- package/src/utils/files/common/types/src/runtime-config.ts.template +2 -13
- package/src/utils/format.d.ts +1 -1
- package/src/utils/format.js +2 -2
- package/src/utils/format.js.map +1 -1
- package/src/utils/names.d.ts +2 -0
- package/src/utils/names.js +27 -0
- package/src/utils/names.js.map +1 -0
- package/src/utils/npm-scope.js.map +1 -1
- package/src/utils/paths.js.map +1 -1
- package/src/utils/shared-constructs.js +37 -4
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/test.d.ts +2 -0
- package/src/utils/test.js +19 -0
- package/src/utils/test.js.map +1 -0
- package/src/utils/versions.d.ts +15 -9
- package/src/utils/versions.js +14 -8
- package/src/utils/versions.js.map +1 -1
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/cloudfront-web-acl.ts.template +0 -317
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/index.ts.template +0 -4
- package/src/cloudscape-website/app/files/common/constructs/src/__websiteNameKebabCase__/webacl_event_handler/index.ts.template +0 -301
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/index.ts.template +0 -4
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/user-identity.ts.template +0 -66
- package/src/cloudscape-website/cognito-auth/files/common/constructs/src/identity/userpool-with-mfa.ts.template +0 -70
- package/src/gitlab/generator.d.ts +0 -8
- package/src/gitlab/generator.js +0 -16
- package/src/gitlab/generator.js.map +0 -1
- package/src/gitlab/schema.d.ts +0 -9
- package/src/gitlab/schema.json +0 -52
- package/src/infra/app/files/src/main.ts.template +0 -37
- package/src/trpc/react/files/src/components/TRPCClientProvider/index.tsx.template +0 -34
- package/src/trpc/react/files/src/hooks/useTrpc.tsx.template +0 -5
- package/src/ts/cjs-to-esm/generator.d.ts +0 -12
- package/src/ts/cjs-to-esm/generator.js +0 -189
- package/src/ts/cjs-to-esm/generator.js.map +0 -1
- package/src/ts/cjs-to-esm/schema.d.ts +0 -9
- package/src/ts/cjs-to-esm/schema.json +0 -28
- /package/src/infra/app/files/{cdk.json → app/cdk.json} +0 -0
- /package/src/infra/app/files/{src → app/src}/stacks/application-stack.ts.template +0 -0
- /package/src/utils/files/common/constructs/src/{runtime-config → core}/index.ts.template +0 -0
|
@@ -16,11 +16,37 @@ export type IEcho = z.TypeOf<typeof EchoSchema>;
|
|
|
16
16
|
"
|
|
17
17
|
`;
|
|
18
18
|
|
|
19
|
-
exports[`trpc backend generator > should set up shared constructs >
|
|
19
|
+
exports[`trpc backend generator > should set up shared constructs > index.ts 1`] = `
|
|
20
|
+
"export * from './test-api.js';
|
|
21
|
+
"
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`trpc backend generator > should set up shared constructs > test-api.ts 1`] = `
|
|
25
|
+
"import { Construct } from 'constructs';
|
|
26
|
+
import * as url from 'url';
|
|
27
|
+
import { TrpcApi } from '../../core/trpc-api.js';
|
|
28
|
+
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
29
|
+
|
|
30
|
+
export class TestApi extends TrpcApi {
|
|
31
|
+
constructor(scope: Construct, id: string) {
|
|
32
|
+
super(scope, id, {
|
|
33
|
+
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
34
|
+
handlerFilePath: url.fileURLToPath(
|
|
35
|
+
new URL(
|
|
36
|
+
'../../../../../../apps/test-api/backend/src/lambdas/router.ts',
|
|
37
|
+
import.meta.url,
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
"
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
exports[`trpc backend generator > should set up shared constructs > trpc-api.ts 1`] = `
|
|
20
47
|
"import { Construct } from 'constructs';
|
|
21
48
|
import { Runtime, RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
|
|
22
49
|
import { CfnOutput, Duration } from 'aws-cdk-lib';
|
|
23
|
-
import * as url from 'url';
|
|
24
50
|
import {
|
|
25
51
|
CorsHttpMethod,
|
|
26
52
|
HttpApi,
|
|
@@ -30,35 +56,31 @@ import {
|
|
|
30
56
|
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
31
57
|
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
32
58
|
import { Effect, IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
33
|
-
import { RuntimeConfig } from '
|
|
59
|
+
import { RuntimeConfig } from './runtime-config.js';
|
|
34
60
|
|
|
35
|
-
export interface
|
|
61
|
+
export interface TrpcApiProps {
|
|
62
|
+
readonly handlerFilePath: string;
|
|
36
63
|
readonly defaultAuthorizer: IHttpRouteAuthorizer;
|
|
37
64
|
readonly allowedOrigins?: string[];
|
|
38
65
|
}
|
|
39
66
|
|
|
40
|
-
export class
|
|
67
|
+
export class TrpcApi extends Construct {
|
|
41
68
|
public readonly api: HttpApi;
|
|
42
69
|
|
|
43
|
-
constructor(scope: Construct, id: string, props:
|
|
70
|
+
constructor(scope: Construct, id: string, props: TrpcApiProps) {
|
|
44
71
|
super(scope, id);
|
|
45
72
|
|
|
46
|
-
const routerFunction = new NodejsFunction(this,
|
|
73
|
+
const routerFunction = new NodejsFunction(this, \`\${id}Handler\`, {
|
|
47
74
|
timeout: Duration.seconds(30),
|
|
48
75
|
runtime: new Runtime('nodejs20.x', RuntimeFamily.NODEJS),
|
|
49
76
|
handler: 'handler',
|
|
50
|
-
entry:
|
|
51
|
-
new URL(
|
|
52
|
-
'../../../../../apps/test-api/backend/src/lambdas/router.ts',
|
|
53
|
-
import.meta.url
|
|
54
|
-
)
|
|
55
|
-
),
|
|
77
|
+
entry: props.handlerFilePath,
|
|
56
78
|
environment: {
|
|
57
|
-
AWS_CONNECTION_REUSE_ENABLED: '1'
|
|
79
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
58
80
|
},
|
|
59
81
|
});
|
|
60
82
|
|
|
61
|
-
this.api = new HttpApi(this,
|
|
83
|
+
this.api = new HttpApi(this, id, {
|
|
62
84
|
corsPreflight: {
|
|
63
85
|
allowOrigins: props.allowedOrigins ?? ['*'],
|
|
64
86
|
allowMethods: [CorsHttpMethod.ANY],
|
|
@@ -85,14 +107,15 @@ export class TestApi extends Construct {
|
|
|
85
107
|
],
|
|
86
108
|
integration: new HttpLambdaIntegration(
|
|
87
109
|
'RouterIntegration',
|
|
88
|
-
routerFunction
|
|
110
|
+
routerFunction,
|
|
89
111
|
),
|
|
90
112
|
});
|
|
91
113
|
|
|
92
|
-
new CfnOutput(this,
|
|
114
|
+
new CfnOutput(this, \`\${id}Url\`, { value: this.api.url! });
|
|
93
115
|
|
|
94
116
|
RuntimeConfig.ensure(this).config.trpcApis = {
|
|
95
|
-
|
|
117
|
+
...RuntimeConfig.ensure(this).config.trpcApis!,
|
|
118
|
+
[id]: this.api.url!,
|
|
96
119
|
};
|
|
97
120
|
}
|
|
98
121
|
|
|
@@ -102,7 +125,7 @@ export class TestApi extends Construct {
|
|
|
102
125
|
effect: Effect.ALLOW,
|
|
103
126
|
actions: ['execute-api:Invoke'],
|
|
104
127
|
resources: [this.api.arnForExecuteApi('*', '/*', '*')],
|
|
105
|
-
})
|
|
128
|
+
}),
|
|
106
129
|
);
|
|
107
130
|
}
|
|
108
131
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# <%= backendProjectName %>
|
|
2
|
+
|
|
3
|
+
This library was generated with [@aws/nx-plugin](https://github.com/awslabs/nx-plugin-for-aws/).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `<%= pkgMgrCmd %> nx build <%= backendProjectName %> [--skip-nx-cache]` to build the application.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `<%= pkgMgrCmd %> nx test <%= backendProjectName %>` to execute the unit tests via Vitest.
|
|
12
|
+
|
|
13
|
+
### Updating snapshots
|
|
14
|
+
|
|
15
|
+
To update snapshots, run the following command:
|
|
16
|
+
|
|
17
|
+
`<%= pkgMgrCmd %> nx test <%= backendProjectName %> --configuration=update-snapshot`
|
|
18
|
+
|
|
19
|
+
## Run lint
|
|
20
|
+
|
|
21
|
+
Run `<%= pkgMgrCmd %> nx lint <%= backendProjectName %>`
|
|
22
|
+
|
|
23
|
+
### Fixable issues
|
|
24
|
+
|
|
25
|
+
You can also automatiaclly fix some lint errors by running the following command:
|
|
26
|
+
|
|
27
|
+
`<%= pkgMgrCmd %> nx lint <%= backendProjectName %> --configuration=fix`
|
|
28
|
+
|
|
29
|
+
## Useful links
|
|
30
|
+
|
|
31
|
+
- [Trpc reference docs](TODO)
|
|
32
|
+
- [Learn more about NX](https://nx.dev/getting-started/intro)
|
|
33
|
+
|
package/src/trpc/backend/files/common/constructs/src/app/trpc-apis/__apiNameKebabCase__.ts.template
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import * as url from 'url';
|
|
3
|
+
import { TrpcApi } from '../../core/trpc-api.js';
|
|
4
|
+
import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
|
|
5
|
+
|
|
6
|
+
export class <%= apiNameClassName %> extends TrpcApi {
|
|
7
|
+
constructor(scope: Construct, id: string) {
|
|
8
|
+
super(scope, id, {
|
|
9
|
+
defaultAuthorizer: new HttpIamAuthorizer(),
|
|
10
|
+
handlerFilePath: url.fileURLToPath(
|
|
11
|
+
new URL(
|
|
12
|
+
'../../../<%= relativePathToProjectRoot %>/backend/src/lambdas/router.ts',
|
|
13
|
+
import.meta.url
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Runtime, RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
|
|
3
3
|
import { CfnOutput, Duration } from 'aws-cdk-lib';
|
|
4
|
-
import * as url from 'url';
|
|
5
4
|
import {
|
|
6
5
|
CorsHttpMethod,
|
|
7
6
|
HttpApi,
|
|
@@ -11,35 +10,31 @@ import {
|
|
|
11
10
|
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
12
11
|
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
13
12
|
import { Effect, IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
14
|
-
import { RuntimeConfig } from '
|
|
13
|
+
import { RuntimeConfig } from './runtime-config.js';
|
|
15
14
|
|
|
16
|
-
export interface
|
|
15
|
+
export interface TrpcApiProps {
|
|
16
|
+
readonly handlerFilePath: string;
|
|
17
17
|
readonly defaultAuthorizer: IHttpRouteAuthorizer;
|
|
18
18
|
readonly allowedOrigins?: string[];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export class
|
|
21
|
+
export class TrpcApi extends Construct {
|
|
22
22
|
public readonly api: HttpApi;
|
|
23
23
|
|
|
24
|
-
constructor(scope: Construct, id: string, props:
|
|
24
|
+
constructor(scope: Construct, id: string, props: TrpcApiProps) {
|
|
25
25
|
super(scope, id);
|
|
26
26
|
|
|
27
|
-
const routerFunction = new NodejsFunction(this,
|
|
27
|
+
const routerFunction = new NodejsFunction(this, `${id}Handler`, {
|
|
28
28
|
timeout: Duration.seconds(30),
|
|
29
29
|
runtime: new Runtime('nodejs20.x', RuntimeFamily.NODEJS),
|
|
30
30
|
handler: 'handler',
|
|
31
|
-
entry:
|
|
32
|
-
new URL(
|
|
33
|
-
'../../<%= relativePathToProjectRoot %>/backend/src/lambdas/router.ts',
|
|
34
|
-
import.meta.url
|
|
35
|
-
)
|
|
36
|
-
),
|
|
31
|
+
entry: props.handlerFilePath,
|
|
37
32
|
environment: {
|
|
38
|
-
AWS_CONNECTION_REUSE_ENABLED: '1'
|
|
33
|
+
AWS_CONNECTION_REUSE_ENABLED: '1',
|
|
39
34
|
},
|
|
40
35
|
});
|
|
41
36
|
|
|
42
|
-
this.api = new HttpApi(this,
|
|
37
|
+
this.api = new HttpApi(this, id, {
|
|
43
38
|
corsPreflight: {
|
|
44
39
|
allowOrigins: props.allowedOrigins ?? ['*'],
|
|
45
40
|
allowMethods: [CorsHttpMethod.ANY],
|
|
@@ -70,10 +65,11 @@ export class <%= apiNameClassName %> extends Construct {
|
|
|
70
65
|
),
|
|
71
66
|
});
|
|
72
67
|
|
|
73
|
-
new CfnOutput(this,
|
|
68
|
+
new CfnOutput(this, `${id}Url`, { value: this.api.url! });
|
|
74
69
|
|
|
75
70
|
RuntimeConfig.ensure(this).config.trpcApis = {
|
|
76
|
-
|
|
71
|
+
...RuntimeConfig.ensure(this).config.trpcApis!,
|
|
72
|
+
[id]: this.api.url!,
|
|
77
73
|
};
|
|
78
74
|
}
|
|
79
75
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# <%= schemaProjectName %>
|
|
2
|
+
|
|
3
|
+
This library was generated with [@aws/nx-plugin](https://github.com/awslabs/nx-plugin-for-aws/).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `<%= pkgMgrCmd %> nx build <%= schemaProjectName %> [--skip-nx-cache]` to build the application.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `<%= pkgMgrCmd %> nx test <%= schemaProjectName %>` to execute the unit tests via Vitest.
|
|
12
|
+
|
|
13
|
+
### Updating snapshots
|
|
14
|
+
|
|
15
|
+
To update snapshots, run the following command:
|
|
16
|
+
|
|
17
|
+
`<%= pkgMgrCmd %> nx test <%= schemaProjectName %> --configuration=update-snapshot`
|
|
18
|
+
|
|
19
|
+
## Run lint
|
|
20
|
+
|
|
21
|
+
Run `<%= pkgMgrCmd %> nx lint <%= schemaProjectName %>`
|
|
22
|
+
|
|
23
|
+
### Fixable issues
|
|
24
|
+
|
|
25
|
+
You can also automatiaclly fix some lint errors by running the following command:
|
|
26
|
+
|
|
27
|
+
`<%= pkgMgrCmd %> nx lint <%= schemaProjectName %> --configuration=fix`
|
|
28
|
+
|
|
29
|
+
## Useful links
|
|
30
|
+
|
|
31
|
+
- [Trpc reference docs](TODO)
|
|
32
|
+
- [Learn more about NX](https://nx.dev/getting-started/intro)
|
|
33
|
+
|
|
@@ -9,71 +9,55 @@ const tslib_1 = require("tslib");
|
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
10
|
const lodash_kebabcase_1 = tslib_1.__importDefault(require("lodash.kebabcase"));
|
|
11
11
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
12
|
-
const typescript_1 = require("typescript");
|
|
13
|
-
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
14
12
|
const generator_1 = tslib_1.__importDefault(require("../../ts/lib/generator"));
|
|
15
13
|
const npm_scope_1 = require("../../utils/npm-scope");
|
|
16
14
|
const versions_1 = require("../../utils/versions");
|
|
17
15
|
const paths_1 = require("../../utils/paths");
|
|
16
|
+
const names_1 = require("../../utils/names");
|
|
17
|
+
const ast_1 = require("../../utils/ast");
|
|
18
18
|
const format_1 = require("../../utils/format");
|
|
19
|
-
const toClassName = (str) => {
|
|
20
|
-
const words = str.replace(/[^a-zA-Z0-9]/g, ' ').split(/\s+/);
|
|
21
|
-
return words
|
|
22
|
-
.map((word, index) => {
|
|
23
|
-
if (index === 0 && /^\d/.test(word)) {
|
|
24
|
-
return '_' + word;
|
|
25
|
-
}
|
|
26
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
27
|
-
})
|
|
28
|
-
.join('');
|
|
29
|
-
};
|
|
30
19
|
function trpcBackendGenerator(tree, options) {
|
|
31
20
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
21
|
var _a;
|
|
33
22
|
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree);
|
|
23
|
+
const apiNamespace = (0, npm_scope_1.getNpmScopePrefix)(tree);
|
|
34
24
|
const apiNameKebabCase = (0, lodash_kebabcase_1.default)(options.apiName);
|
|
35
|
-
const apiNameClassName = toClassName(options.apiName);
|
|
25
|
+
const apiNameClassName = (0, names_1.toClassName)(options.apiName);
|
|
36
26
|
const projectRoot = (0, devkit_1.joinPathFragments)((_a = options.directory) !== null && _a !== void 0 ? _a : '.', apiNameKebabCase);
|
|
37
27
|
const relativePathToProjectRoot = `${(0, devkit_1.joinPathFragments)((0, paths_1.getRelativePathToRoot)(tree, `${(0, npm_scope_1.getNpmScopePrefix)(tree)}common-constructs`), projectRoot)}`;
|
|
38
28
|
const schemaRoot = (0, devkit_1.joinPathFragments)(projectRoot, 'schema');
|
|
39
29
|
const backendRoot = (0, devkit_1.joinPathFragments)(projectRoot, 'backend');
|
|
40
30
|
const backendName = `${apiNameKebabCase}-backend`;
|
|
41
31
|
const schemaName = `${apiNameKebabCase}-schema`;
|
|
42
|
-
const backendProjectName = `${
|
|
43
|
-
const schemaProjectName = `${
|
|
32
|
+
const backendProjectName = `${apiNamespace}${backendName}`;
|
|
33
|
+
const schemaProjectName = `${apiNamespace}${schemaName}`;
|
|
44
34
|
const enhancedOptions = Object.assign({ backendProjectName, backendProjectAlias: (0, npm_scope_1.toScopeAlias)(backendProjectName), schemaProjectName, schemaProjectAlias: (0, npm_scope_1.toScopeAlias)(schemaProjectName), apiNameKebabCase,
|
|
45
35
|
apiNameClassName,
|
|
46
|
-
relativePathToProjectRoot }, options);
|
|
36
|
+
relativePathToProjectRoot, pkgMgrCmd: (0, devkit_1.getPackageManagerCommand)().exec }, options);
|
|
47
37
|
yield (0, generator_1.default)(tree, {
|
|
48
|
-
scope: options.apiNamespace,
|
|
49
38
|
name: backendName,
|
|
50
39
|
directory: projectRoot,
|
|
51
40
|
subDirectory: 'backend',
|
|
52
|
-
unitTestRunner: options.unitTestRunner,
|
|
53
41
|
});
|
|
54
42
|
yield (0, generator_1.default)(tree, {
|
|
55
|
-
scope: options.apiNamespace,
|
|
56
43
|
name: schemaName,
|
|
57
44
|
directory: projectRoot,
|
|
58
45
|
subDirectory: 'schema',
|
|
59
|
-
unitTestRunner: options.unitTestRunner,
|
|
60
46
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.
|
|
75
|
-
if (sharedConstructsIndexContents !== updatedIndex) {
|
|
76
|
-
tree.write(sharedConstructsIndexTsPath, updatedIndex);
|
|
47
|
+
if (!tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'trpc-apis', `${apiNameKebabCase}.ts`))) {
|
|
48
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), enhancedOptions, {
|
|
49
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
50
|
+
});
|
|
51
|
+
const shouldGenerateCoreTrpcApiConstruct = !tree.exists((0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'trpc-api.ts'));
|
|
52
|
+
if (shouldGenerateCoreTrpcApiConstruct) {
|
|
53
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core'), enhancedOptions, {
|
|
54
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './trpc-apis/index.js');
|
|
58
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'trpc-apis', 'index.ts'), `./${apiNameKebabCase}.js`);
|
|
59
|
+
if (shouldGenerateCoreTrpcApiConstruct) {
|
|
60
|
+
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_1.PACKAGES_DIR, shared_constructs_1.SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './trpc-api.js');
|
|
77
61
|
}
|
|
78
62
|
}
|
|
79
63
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(backendRoot, 'project.json'), (config) => {
|
|
@@ -82,23 +66,25 @@ function trpcBackendGenerator(tree, options) {
|
|
|
82
66
|
};
|
|
83
67
|
return config;
|
|
84
68
|
});
|
|
85
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'backend'), backendRoot, enhancedOptions
|
|
86
|
-
|
|
69
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'backend'), backendRoot, enhancedOptions, {
|
|
70
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite,
|
|
71
|
+
});
|
|
72
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'schema'), schemaRoot, enhancedOptions, {
|
|
73
|
+
overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite,
|
|
74
|
+
});
|
|
87
75
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'src', 'lib'));
|
|
88
76
|
tree.delete((0, devkit_1.joinPathFragments)(schemaRoot, 'src', 'lib'));
|
|
89
77
|
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
90
|
-
'zod',
|
|
91
|
-
'@trpc/server',
|
|
92
78
|
'aws-xray-sdk-core',
|
|
93
|
-
'
|
|
94
|
-
'constructs',
|
|
79
|
+
'zod',
|
|
95
80
|
'@aws-lambda-powertools/logger',
|
|
96
81
|
'@aws-lambda-powertools/metrics',
|
|
97
82
|
'@aws-lambda-powertools/tracer',
|
|
83
|
+
'@trpc/server',
|
|
98
84
|
]), (0, versions_1.withVersions)(['@types/aws-lambda']));
|
|
99
85
|
tree.delete((0, devkit_1.joinPathFragments)(backendRoot, 'package.json'));
|
|
100
86
|
tree.delete((0, devkit_1.joinPathFragments)(schemaRoot, 'package.json'));
|
|
101
|
-
yield (0, format_1.formatFilesInSubtree)(tree
|
|
87
|
+
yield (0, format_1.formatFilesInSubtree)(tree);
|
|
102
88
|
return () => {
|
|
103
89
|
(0, devkit_1.installPackagesTask)(tree);
|
|
104
90
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"names":[],"mappings":";;AA6BA,oDAqLC;;AAlND;;;GAGG;AACH,uCAUoB;AAEpB,gFAAyC;AACzC,qEAIuC;AACvC,+EAAoD;AACpD,qDAAwE;AACxE,mDAAoD;AACpD,6CAA0D;AAC1D,6CAAgD;AAChD,yCAAgD;AAChD,+CAA0D;AAC1D,SAAsB,oBAAoB,CACxC,IAAU,EACV,OAAmC;;;QAEnC,MAAM,IAAA,6CAAyB,EAAC,IAAI,CAAC,CAAC;QACtC,MAAM,YAAY,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,gBAAgB,GAAG,IAAA,0BAAS,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpD,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,WAAW,GAAG,IAAA,0BAAiB,EACnC,MAAA,OAAO,CAAC,SAAS,mCAAI,GAAG,EACxB,gBAAgB,CACjB,C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AC;QACjC,OAAO,GAAG,EAAE;YACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC;CAAA;AACD,kBAAe,oBAAoB,CAAC"}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
+
import { Linter } from '@nx/eslint';
|
|
6
|
+
|
|
5
7
|
export interface TrpcBackendGeneratorSchema {
|
|
6
8
|
apiName: string;
|
|
7
|
-
apiNamespace: string;
|
|
8
9
|
bundler: TsLibGeneratorSchema['bundler'];
|
|
9
10
|
directory?: TsLibGeneratorSchema['directory'];
|
|
10
11
|
unitTestRunner: TsLibGeneratorSchema['unitTestRunner'];
|
|
12
|
+
linter?: Linter;
|
|
11
13
|
}
|
|
@@ -13,16 +13,6 @@
|
|
|
13
13
|
},
|
|
14
14
|
"x-prompt": "What name would your API to be? i.e: MyApi"
|
|
15
15
|
},
|
|
16
|
-
"apiNamespace": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"description": "",
|
|
19
|
-
"$default": {
|
|
20
|
-
"$source": "argv",
|
|
21
|
-
"index": 0
|
|
22
|
-
},
|
|
23
|
-
"pattern": "^@[a-z0-9-]+(?:/[a-z0-9-]+)?$",
|
|
24
|
-
"x-prompt": "What namespace would you like your API to have? i.e: @myapi"
|
|
25
|
-
},
|
|
26
16
|
"directory": {
|
|
27
17
|
"description": "The directory of the new application.",
|
|
28
18
|
"type": "string",
|
|
@@ -36,9 +26,14 @@
|
|
|
36
26
|
"enum": ["jest", "vitest", "none"],
|
|
37
27
|
"description": "Test runner to use for unit tests.",
|
|
38
28
|
"x-prompt": "Which unit test runner would you like to use?",
|
|
39
|
-
"default": "vitest"
|
|
40
|
-
|
|
29
|
+
"default": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"linter": {
|
|
32
|
+
"description": "The tool to use for running lint checks.",
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": ["eslint", "none"],
|
|
35
|
+
"default": "eslint"
|
|
41
36
|
}
|
|
42
37
|
},
|
|
43
|
-
"required": ["apiName"
|
|
38
|
+
"required": ["apiName"]
|
|
44
39
|
}
|