@aligent/nx-cdk 0.0.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.
Files changed (61) hide show
  1. package/README.md +130 -0
  2. package/generators.json +15 -0
  3. package/package.json +20 -0
  4. package/src/generators/helpers/configs/nxJson.d.ts +4 -0
  5. package/src/generators/helpers/configs/nxJson.js +52 -0
  6. package/src/generators/helpers/configs/packageJson.d.ts +61 -0
  7. package/src/generators/helpers/configs/packageJson.js +65 -0
  8. package/src/generators/helpers/configs/tsConfigs.d.ts +12 -0
  9. package/src/generators/helpers/configs/tsConfigs.js +40 -0
  10. package/src/generators/helpers/utilities.d.ts +82 -0
  11. package/src/generators/helpers/utilities.js +100 -0
  12. package/src/generators/preset/files/.editorconfig.template +18 -0
  13. package/src/generators/preset/files/.git-hooks/pre-push.template +68 -0
  14. package/src/generators/preset/files/.github/CODEOWNERS.template +3 -0
  15. package/src/generators/preset/files/.github/dependabot.yml.template +7 -0
  16. package/src/generators/preset/files/.github/workflows/ci-cd.yml.template +27 -0
  17. package/src/generators/preset/files/.gitignore.template +62 -0
  18. package/src/generators/preset/files/.nvmrc.template +1 -0
  19. package/src/generators/preset/files/.prettierignore.template +10 -0
  20. package/src/generators/preset/files/.yarnrc.yml.template +6 -0
  21. package/src/generators/preset/files/LICENSE.template +21 -0
  22. package/src/generators/preset/files/README.md.template +77 -0
  23. package/src/generators/preset/files/application/README.md.template +61 -0
  24. package/src/generators/preset/files/application/_internal/log-group-defaults-injector.ts.template +100 -0
  25. package/src/generators/preset/files/application/_internal/microservice-checks.ts.template +58 -0
  26. package/src/generators/preset/files/application/_internal/nodejs-function-defaults-injector.ts.template +110 -0
  27. package/src/generators/preset/files/application/_internal/step-function-defaults-injector.ts.template +126 -0
  28. package/src/generators/preset/files/application/_internal/version-functions-aspect.ts.template +74 -0
  29. package/src/generators/preset/files/application/bin/main.ts.template +72 -0
  30. package/src/generators/preset/files/application/cdk.context.json.template +4 -0
  31. package/src/generators/preset/files/application/cdk.json.template +92 -0
  32. package/src/generators/preset/files/application/eslint.config.mjs.template +3 -0
  33. package/src/generators/preset/files/application/lib/service-stacks.ts.template +21 -0
  34. package/src/generators/preset/files/application/package.json.template +27 -0
  35. package/src/generators/preset/files/cdk-config.yml.template +16 -0
  36. package/src/generators/preset/files/eslint.config.mjs.template +54 -0
  37. package/src/generators/preset/files/prettier.config.mjs.template +3 -0
  38. package/src/generators/preset/files/rolldown.config.base.mjs.template +46 -0
  39. package/src/generators/preset/files/tsconfig.json.template +6 -0
  40. package/src/generators/preset/files/vitest.config.base.mjs.template +39 -0
  41. package/src/generators/preset/files/vitest.global.setup.mjs.template +109 -0
  42. package/src/generators/preset/preset.d.ts +4 -0
  43. package/src/generators/preset/preset.js +35 -0
  44. package/src/generators/preset/schema.d.ts +7 -0
  45. package/src/generators/preset/schema.json +32 -0
  46. package/src/generators/service/files/README.md.template +29 -0
  47. package/src/generators/service/files/eslint.config.mjs.template +20 -0
  48. package/src/generators/service/files/package.json.template +32 -0
  49. package/src/generators/service/files/rolldown.config.mjs.template +3 -0
  50. package/src/generators/service/files/src/index.ts.template +75 -0
  51. package/src/generators/service/files/src/infra/.gitkeep.template +0 -0
  52. package/src/generators/service/files/src/runtime/handlers/.gitkeep.template +0 -0
  53. package/src/generators/service/files/src/runtime/lib/utils/.gitkeep.template +0 -0
  54. package/src/generators/service/files/tests/__data__/.gitkeep.template +0 -0
  55. package/src/generators/service/files/vitest.config.mjs.template +18 -0
  56. package/src/generators/service/generator.d.ts +4 -0
  57. package/src/generators/service/generator.js +43 -0
  58. package/src/generators/service/schema.d.ts +4 -0
  59. package/src/generators/service/schema.json +20 -0
  60. package/src/index.d.ts +2 -0
  61. package/src/index.js +19 -0
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Nx Cloud Development Kit
2
+
3
+ The `@aligent/nx-cdk` package provides Nx generators for AWS CDK development. It helps you scaffold new CDK projects and services within an Nx monorepo structure.
4
+
5
+ ## Generators
6
+
7
+ ### Preset Generator
8
+
9
+ The preset generator initializes a new CDK project with a complete workspace structure, including configuration files, build tools, and an application scaffold.
10
+
11
+ #### Usage
12
+
13
+ ```bash
14
+ npx create-nx-workspace@latest --preset=@aligent/nx-cdk
15
+ ```
16
+
17
+ #### Options
18
+
19
+ | Option | Type | Required | Default | Description |
20
+ | ------------- | ------ | -------- | --------- | -------------------------------------------------------------------------------- |
21
+ | `name` | string | Yes | - | The name of the project/application (alphanumeric and dashes only) |
22
+ | `nodeVersion` | string | No | `24.11.0` | The target Node.js version for the project (must be valid semver, e.g., 22.10.0) |
23
+
24
+ #### What it creates
25
+
26
+ The preset generator scaffolds:
27
+
28
+ - **Root configuration files**:
29
+ - `eslint.config.mjs` - ESLint configuration
30
+ - `prettier.config.mjs` - Prettier configuration
31
+ - `rolldown.config.base.mjs` - Base Rolldown configuration
32
+ - `vitest.config.base.mjs` - Base Vitest configuration
33
+ - `vitest.global.setup.mjs` - Global Vitest setup
34
+ - `tsconfig.json` - Root TypeScript configuration
35
+ - `nx.json` - Nx workspace configuration
36
+ - `package.json` - Project dependencies and scripts
37
+ - `cdk-config.yml` - CDK configuration
38
+ - `LICENSE` - Project license
39
+
40
+ - **Application folder** (`application/`):
41
+ - `cdk.json` - CDK app configuration
42
+ - `cdk.context.json` - CDK context
43
+ - `bin/main.ts` - CDK app entry point
44
+ - `lib/service-stacks.ts` - Service stacks definition
45
+ - TypeScript configurations (`tsconfig.json`, `tsconfig.lib.json`, `tsconfig.spec.json`)
46
+
47
+ ### Service Generator
48
+
49
+ The service generator creates a new CDK service within the `services/` folder of your existing CDK project. Each service is configured as a separate package with its own build configuration and testing setup.
50
+
51
+ #### Usage
52
+
53
+ ```bash
54
+ npx nx g @aligent/nx-cdk:service <service-name>
55
+ ```
56
+
57
+ #### Options
58
+
59
+ | Option | Type | Required | Description |
60
+ | ------ | ------ | -------- | ------------------------------------------------------------------------- |
61
+ | `name` | string | Yes | The name of the service (cannot contain 'Stack' or 'Service' in the name) |
62
+
63
+ #### What it creates
64
+
65
+ The service generator creates a new service in `services/<service-name>/` with:
66
+
67
+ - **Service files**:
68
+ - `src/index.ts` - Service entry point
69
+ - `package.json` - Service-specific dependencies
70
+ - `README.md` - Service documentation
71
+ - `eslint.config.mjs` - ESLint configuration
72
+ - `rolldown.config.mjs` - Rolldown configuration
73
+ - `vitest.config.mjs` - Vitest configuration
74
+ - TypeScript configurations (`tsconfig.json`, `tsconfig.lib.json`, `tsconfig.spec.json`)
75
+
76
+ - **Root updates**:
77
+ - Adds the service to the root `tsconfig.json` references for proper TypeScript project references
78
+
79
+ - **Application updates**:
80
+ - Adds the stack to the main CDK application
81
+
82
+ #### Example
83
+
84
+ ```bash
85
+ # Create a new service named "user-management"
86
+ npx nx g @aligent/nx-cdk:service user-management
87
+
88
+ # Create a new service named "payment-processing"
89
+ npx nx g @aligent/nx-cdk:service payment-processing
90
+ ```
91
+
92
+ ## Project Structure
93
+
94
+ After using both generators, your project structure will look like:
95
+
96
+ ```
97
+ my-cdk-app/
98
+ ├── application/
99
+ │ ├── bin/
100
+ │ │ └── main.ts
101
+ │ ├── lib/
102
+ │ │ └── service-stacks.ts
103
+ │ ├── _internal/
104
+ │ │ ├── version-functions-aspect.ts
105
+ │ │ ├── nodejs-function-defaults-injector.ts
106
+ │ │ ├── step-function-defaults-injector.ts
107
+ │ │ ├── log-group-defaults-injector.ts
108
+ │ │ └── microservice-checks.ts
109
+ │ ├── cdk.json
110
+ │ ├── cdk.context.json
111
+ │ └── package.json
112
+ ├── services/
113
+ │ ├── user-management/
114
+ │ │ ├── src/
115
+ │ │ │ └── index.ts
116
+ │ │ ├── package.json
117
+ │ │ └── ...
118
+ │ └── payment-processing/
119
+ │ ├── src/
120
+ │ │ └── index.ts
121
+ │ ├── package.json
122
+ │ └── ...
123
+ ├── nx.json
124
+ ├── package.json
125
+ └── tsconfig.json
126
+ ```
127
+
128
+ ## License
129
+
130
+ MIT
@@ -0,0 +1,15 @@
1
+ {
2
+ "generators": {
3
+ "preset": {
4
+ "factory": "./src/generators/preset/preset",
5
+ "schema": "./src/generators/preset/schema.json",
6
+ "description": "preset generator",
7
+ "x-use-standalone-layout": true
8
+ },
9
+ "service": {
10
+ "factory": "./src/generators/service/generator",
11
+ "schema": "./src/generators/service/schema.json",
12
+ "description": "Generate a new service"
13
+ }
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@aligent/nx-cdk",
3
+ "version": "0.0.1",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "typings": "./src/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/aligent/microservice-development-utilities.git",
10
+ "directory": "packages/nx-cdk"
11
+ },
12
+ "dependencies": {
13
+ "@nx/devkit": "20.8.1",
14
+ "ts-morph": "^27.0.2"
15
+ },
16
+ "generators": "./generators.json",
17
+ "author": "Aligent",
18
+ "license": "MIT",
19
+ "types": "./src/index.d.ts"
20
+ }
@@ -0,0 +1,4 @@
1
+ import { NxJsonConfiguration } from '@nx/devkit';
2
+ export declare const NX_JSON: NxJsonConfiguration & {
3
+ $schema: string;
4
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NX_JSON = void 0;
4
+ exports.NX_JSON = {
5
+ $schema: './node_modules/nx/schemas/nx-schema.json',
6
+ defaultBase: 'origin/staging',
7
+ plugins: [
8
+ { plugin: '@nx/eslint/plugin', options: {} },
9
+ { plugin: '@nx/vite/plugin', options: {} },
10
+ { plugin: '@nx/js/typescript', options: { build: false } },
11
+ ],
12
+ namedInputs: {
13
+ default: ['{projectRoot}/**/*', 'sharedGlobals'],
14
+ production: [
15
+ 'default',
16
+ '!{projectRoot}/.eslintrc.json',
17
+ '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
18
+ '!{projectRoot}/tsconfig.spec.json',
19
+ '!{projectRoot}/vitest.config.m[jt]s',
20
+ '!{projectRoot}/src/test-setup.[jt]s',
21
+ ],
22
+ sharedGlobals: [],
23
+ },
24
+ targetDefaults: {
25
+ build: {
26
+ cache: true,
27
+ dependsOn: ['^build'],
28
+ inputs: ['production', '^production'],
29
+ outputs: ['{projectRoot}/dist'],
30
+ },
31
+ cdk: { dependsOn: ['^build', '^build:lambda'], inputs: ['production', '^production'] },
32
+ lint: { cache: true, inputs: ['default'] },
33
+ test: {
34
+ cache: true,
35
+ inputs: ['default', '^production'],
36
+ outputs: ['{projectRoot}/coverage'],
37
+ // Stack tests may require lambda handlers to be built first
38
+ dependsOn: ['^build', 'build:lambda'],
39
+ configurations: { coverage: { coverage: true } },
40
+ },
41
+ typecheck: { cache: true, dependsOn: ['^build'], inputs: ['production', '^production'] },
42
+ parameters: {
43
+ executor: 'nx:run-commands',
44
+ options: { color: true, cwd: '{projectRoot}/parameters', file: '.env.csv' },
45
+ defaultConfiguration: 'export',
46
+ configurations: {
47
+ import: { command: 'store-parameters import {args.file}' },
48
+ export: { command: 'store-parameters export {args.file} --path={args.path}' },
49
+ },
50
+ },
51
+ },
52
+ };
@@ -0,0 +1,61 @@
1
+ export declare const PACKAGE_JSON: {
2
+ readonly author: "Aligent";
3
+ readonly private: true;
4
+ readonly license: "MIT";
5
+ readonly type: "module";
6
+ readonly scripts: {
7
+ readonly test: "nx affected -t test --coverage";
8
+ readonly 'test:all': "nx run-many -t test --coverage";
9
+ readonly lint: "nx affected -t lint";
10
+ readonly 'lint:all': "nx run-many -t lint";
11
+ readonly typecheck: "nx affected -t typecheck";
12
+ readonly 'typecheck:all': "nx run-many -t typecheck";
13
+ readonly postinstall: "[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true";
14
+ readonly 'pg:synth': "nx run application:cdk synth 'development/**' --exclusively --profile playground";
15
+ readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' 'development/**' --exclusively --require-approval never --profile playground";
16
+ readonly 'pg:destroy': "nx run application:cdk destroy 'development/**' --profile playground";
17
+ readonly audit: "nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache";
18
+ };
19
+ readonly dependencies: {
20
+ readonly '@aligent/microservice-util-lib': "^1.2.0";
21
+ };
22
+ readonly devDependencies: {
23
+ readonly '@aligent/cdk-step-function-from-file': "^0.3.2";
24
+ readonly '@aligent/nx-openapi': "^1.0.0";
25
+ readonly '@aligent/ts-code-standards': "^4.1.0";
26
+ readonly '@nx/eslint': "22.1.3";
27
+ readonly '@nx/eslint-plugin': "22.1.3";
28
+ readonly '@nx/js': "22.1.3";
29
+ readonly '@nx/vite': "22.1.3";
30
+ readonly '@swc-node/register': "^1.10.10";
31
+ readonly '@swc/core': "^1.13.3";
32
+ readonly '@swc/helpers': "^0.5.17";
33
+ readonly '@types/aws-lambda': "^8.10.152";
34
+ readonly '@types/node': "^22.17.0";
35
+ readonly '@typescript-eslint/eslint-plugin': "8.44.0";
36
+ readonly '@typescript-eslint/parser': "8.44.0";
37
+ readonly '@vitest/coverage-v8': "^3.2.4";
38
+ readonly '@vitest/ui': "^3.2.4";
39
+ readonly 'aws-cdk': "^2.1033.0";
40
+ readonly 'aws-cdk-lib': "^2.230.0";
41
+ readonly 'cdk-nag': "^2.37.55";
42
+ readonly constructs: "^10.4.3";
43
+ readonly eslint: "^9.32.0";
44
+ readonly 'eslint-config-prettier': "^10.1.8";
45
+ readonly 'eslint-plugin-import': "^2.32.0";
46
+ readonly 'fast-glob': "^3.3.3";
47
+ readonly jiti: "2.5.1";
48
+ readonly 'jsonc-eslint-parser': "^2.4.0";
49
+ readonly nx: "22.1.3";
50
+ readonly prettier: "^3.6.2";
51
+ readonly rolldown: "1.0.0-beta.53";
52
+ readonly 'store-parameters': "^1.1.3";
53
+ readonly tslib: "^2.8.1";
54
+ readonly tsx: "^4.21.0";
55
+ readonly typescript: "~5.9.2";
56
+ readonly vite: "^7.2.6";
57
+ readonly vitest: "^3.2.4";
58
+ };
59
+ readonly workspaces: readonly ["application", "clients", "libs/*", "services/*"];
60
+ readonly packageManager: "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8";
61
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PACKAGE_JSON = void 0;
4
+ exports.PACKAGE_JSON = {
5
+ author: 'Aligent',
6
+ private: true,
7
+ license: 'MIT',
8
+ type: 'module',
9
+ scripts: {
10
+ test: 'nx affected -t test --coverage',
11
+ 'test:all': 'nx run-many -t test --coverage',
12
+ lint: 'nx affected -t lint',
13
+ 'lint:all': 'nx run-many -t lint',
14
+ typecheck: 'nx affected -t typecheck',
15
+ 'typecheck:all': 'nx run-many -t typecheck',
16
+ postinstall: `[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true`,
17
+ 'pg:synth': `nx run application:cdk synth 'development/**' --exclusively --profile playground`,
18
+ 'pg:deploy': `nx run application:cdk deploy --method 'direct' 'development/**' --exclusively --require-approval never --profile playground`,
19
+ 'pg:destroy': "nx run application:cdk destroy 'development/**' --profile playground",
20
+ audit: 'nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache',
21
+ },
22
+ dependencies: {
23
+ '@aligent/microservice-util-lib': '^1.2.0',
24
+ },
25
+ devDependencies: {
26
+ '@aligent/cdk-step-function-from-file': '^0.3.2',
27
+ '@aligent/nx-openapi': '^1.0.0',
28
+ '@aligent/ts-code-standards': '^4.1.0',
29
+ '@nx/eslint': '22.1.3',
30
+ '@nx/eslint-plugin': '22.1.3',
31
+ '@nx/js': '22.1.3',
32
+ '@nx/vite': '22.1.3',
33
+ '@swc-node/register': '^1.10.10',
34
+ '@swc/core': '^1.13.3',
35
+ '@swc/helpers': '^0.5.17',
36
+ '@types/aws-lambda': '^8.10.152',
37
+ '@types/node': '^22.17.0',
38
+ '@typescript-eslint/eslint-plugin': '8.44.0',
39
+ '@typescript-eslint/parser': '8.44.0',
40
+ '@vitest/coverage-v8': '^3.2.4',
41
+ '@vitest/ui': '^3.2.4',
42
+ 'aws-cdk': '^2.1033.0',
43
+ 'aws-cdk-lib': '^2.230.0',
44
+ 'cdk-nag': '^2.37.55',
45
+ constructs: '^10.4.3',
46
+ eslint: '^9.32.0',
47
+ 'eslint-config-prettier': '^10.1.8',
48
+ 'eslint-plugin-import': '^2.32.0',
49
+ 'fast-glob': '^3.3.3',
50
+ jiti: '2.5.1',
51
+ 'jsonc-eslint-parser': '^2.4.0',
52
+ nx: '22.1.3',
53
+ prettier: '^3.6.2',
54
+ // FIXME: [MI-251] Rolldown is still in beta. We pin the version and can upgrade with precaution.
55
+ rolldown: '1.0.0-beta.53',
56
+ 'store-parameters': '^1.1.3',
57
+ tslib: '^2.8.1',
58
+ tsx: '^4.21.0',
59
+ typescript: '~5.9.2',
60
+ vite: '^7.2.6',
61
+ vitest: '^3.2.4',
62
+ },
63
+ workspaces: ['application', 'clients', 'libs/*', 'services/*'],
64
+ packageManager: 'yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8',
65
+ };
@@ -0,0 +1,12 @@
1
+ interface TsConfig {
2
+ extends: string;
3
+ compilerOptions?: Record<string, unknown>;
4
+ files?: string[];
5
+ include: string[];
6
+ exclude?: string[];
7
+ references: Array<Record<string, string>>;
8
+ }
9
+ export declare const TS_CONFIG_JSON: TsConfig;
10
+ export declare const TS_CONFIG_LIB_JSON: TsConfig;
11
+ export declare const TS_CONFIG_SPEC_JSON: TsConfig;
12
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TS_CONFIG_SPEC_JSON = exports.TS_CONFIG_LIB_JSON = exports.TS_CONFIG_JSON = void 0;
4
+ const BASE_CONFIG = '@aligent/ts-code-standards/tsconfigs-extend';
5
+ exports.TS_CONFIG_JSON = {
6
+ extends: BASE_CONFIG,
7
+ files: [],
8
+ include: [],
9
+ references: [],
10
+ };
11
+ exports.TS_CONFIG_LIB_JSON = {
12
+ extends: BASE_CONFIG,
13
+ compilerOptions: {
14
+ baseUrl: '.',
15
+ rootDir: 'src',
16
+ outDir: 'dist',
17
+ tsBuildInfoFile: 'dist/tsconfig.lib.tsbuildinfo',
18
+ types: ['node'],
19
+ },
20
+ include: ['src/**/*.ts'],
21
+ exclude: ['vite.config.mjs', 'src/**/*.spec.ts', 'src/**/*.test.ts'],
22
+ references: [],
23
+ };
24
+ exports.TS_CONFIG_SPEC_JSON = {
25
+ extends: BASE_CONFIG,
26
+ compilerOptions: {
27
+ outDir: './out-tsc/vitest',
28
+ types: ['vitest/globals', 'vitest/importMeta', 'vite/client', 'node', 'vitest'],
29
+ },
30
+ include: [
31
+ 'vite.config.mjs',
32
+ 'src/**/*.test.ts',
33
+ 'src/**/*.spec.ts',
34
+ 'src/**/*.d.ts',
35
+ 'tests/**/*.test.ts',
36
+ 'tests/**/*.spec.ts',
37
+ 'tests/**/*.d.ts',
38
+ ],
39
+ references: [{ path: './tsconfig.lib.json' }],
40
+ };
@@ -0,0 +1,82 @@
1
+ import { Tree } from '@nx/devkit';
2
+ interface PackageJsonInput {
3
+ name: string;
4
+ projectName: string;
5
+ version: string;
6
+ nodeVersion: string;
7
+ }
8
+ interface Service {
9
+ name: string;
10
+ constant: string;
11
+ stack: string;
12
+ }
13
+ export declare function constructPackageJsonFile(input: PackageJsonInput): {
14
+ [k: string]: string | true | readonly ["application", "clients", "libs/*", "services/*"] | {
15
+ readonly test: "nx affected -t test --coverage";
16
+ readonly 'test:all': "nx run-many -t test --coverage";
17
+ readonly lint: "nx affected -t lint";
18
+ readonly 'lint:all': "nx run-many -t lint";
19
+ readonly typecheck: "nx affected -t typecheck";
20
+ readonly 'typecheck:all': "nx run-many -t typecheck";
21
+ readonly postinstall: "[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true";
22
+ readonly 'pg:synth': "nx run application:cdk synth 'development/**' --exclusively --profile playground";
23
+ readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' 'development/**' --exclusively --require-approval never --profile playground";
24
+ readonly 'pg:destroy': "nx run application:cdk destroy 'development/**' --profile playground";
25
+ readonly audit: "nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache";
26
+ } | {
27
+ readonly '@aligent/microservice-util-lib': "^1.2.0";
28
+ } | {
29
+ [k: string]: string;
30
+ } | {
31
+ node: string;
32
+ };
33
+ };
34
+ export declare function constructProjectTsConfigFiles(type: 'application' | 'service'): {
35
+ tsConfig: {
36
+ extends: string;
37
+ compilerOptions?: Record<string, unknown>;
38
+ files?: string[];
39
+ include: string[];
40
+ exclude?: string[];
41
+ references: Array<Record<string, string>>;
42
+ };
43
+ tsConfigLib: {
44
+ extends: string;
45
+ compilerOptions?: Record<string, unknown>;
46
+ files?: string[];
47
+ include: string[];
48
+ exclude?: string[];
49
+ references: Array<Record<string, string>>;
50
+ };
51
+ tsConfigSpec: {
52
+ extends: string;
53
+ compilerOptions?: Record<string, unknown>;
54
+ files?: string[];
55
+ include: string[];
56
+ exclude?: string[];
57
+ references: Array<Record<string, string>>;
58
+ };
59
+ };
60
+ export declare function getGeneratorVersion(): string;
61
+ /**
62
+ * Automatically registers a service stack to the main CDK application's ApplicationStage.
63
+ *
64
+ * This function modifies the service-stacks.ts file by:
65
+ * 1. Adding import statements for the service's stack class and constants
66
+ * 2. Instantiating the stack within the ApplicationStage constructor
67
+ *
68
+ * @param tree - The Nx virtual file system tree
69
+ * @param service - Service information containing name, constant, and stack class names
70
+ * @param projectName - The name of the main application project to register the service to
71
+ *
72
+ * @throws {Error} If the ApplicationStage constructor cannot be found in service-stacks.ts
73
+ */
74
+ export declare function addServiceStackToMainApplication(tree: Tree, service: Service, projectName: string): Promise<void>;
75
+ /**
76
+ * Splits a kebab-case name into an array of capitalized parts.
77
+ *
78
+ * @param name - The kebab-case string to split (e.g., "my-service-name")
79
+ * @returns An array of strings with each part capitalized (e.g., ["My", "Service", "Name"])
80
+ */
81
+ export declare function splitInputName(name: string): string[];
82
+ export {};
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructPackageJsonFile = constructPackageJsonFile;
4
+ exports.constructProjectTsConfigFiles = constructProjectTsConfigFiles;
5
+ exports.getGeneratorVersion = getGeneratorVersion;
6
+ exports.addServiceStackToMainApplication = addServiceStackToMainApplication;
7
+ exports.splitInputName = splitInputName;
8
+ /* v8 ignore start */
9
+ const devkit_1 = require("@nx/devkit");
10
+ const fs_1 = require("fs");
11
+ const path_1 = require("path");
12
+ const ts_morph_1 = require("ts-morph");
13
+ const packageJson_1 = require("./configs/packageJson");
14
+ const tsConfigs_1 = require("./configs/tsConfigs");
15
+ function constructPackageJsonFile(input) {
16
+ const devDependencies = Object.fromEntries(Object.entries({
17
+ '@aligent/nx-cdk': input.version,
18
+ ...packageJson_1.PACKAGE_JSON.devDependencies,
19
+ }).sort());
20
+ const packageJson = Object.fromEntries(Object.entries({
21
+ name: `@${input.name}/integrations`,
22
+ description: `${input.projectName} integrations mono-repository`,
23
+ version: input.version,
24
+ ...packageJson_1.PACKAGE_JSON,
25
+ devDependencies,
26
+ engines: { node: `^${input.nodeVersion}` },
27
+ }));
28
+ return packageJson;
29
+ }
30
+ function constructProjectTsConfigFiles(type) {
31
+ const tsConfig = { ...tsConfigs_1.TS_CONFIG_JSON };
32
+ if (type === 'service') {
33
+ tsConfig.references = [{ path: './tsconfig.lib.json' }, { path: './tsconfig.spec.json' }];
34
+ }
35
+ return {
36
+ tsConfig,
37
+ tsConfigLib: { ...tsConfigs_1.TS_CONFIG_LIB_JSON },
38
+ tsConfigSpec: { ...tsConfigs_1.TS_CONFIG_SPEC_JSON },
39
+ };
40
+ }
41
+ function isPackageJsonWithVersion(obj) {
42
+ return (typeof obj === 'object' &&
43
+ obj !== null &&
44
+ 'version' in obj &&
45
+ typeof obj.version === 'string');
46
+ }
47
+ function getGeneratorVersion() {
48
+ const packagePath = (0, path_1.join)(__dirname, '../../../package.json');
49
+ const packageJson = (0, devkit_1.readJsonFile)(packagePath);
50
+ if (isPackageJsonWithVersion(packageJson)) {
51
+ return packageJson.version;
52
+ }
53
+ throw new Error(`Unable to get generator version from ${packagePath}`);
54
+ }
55
+ /**
56
+ * Automatically registers a service stack to the main CDK application's ApplicationStage.
57
+ *
58
+ * This function modifies the service-stacks.ts file by:
59
+ * 1. Adding import statements for the service's stack class and constants
60
+ * 2. Instantiating the stack within the ApplicationStage constructor
61
+ *
62
+ * @param tree - The Nx virtual file system tree
63
+ * @param service - Service information containing name, constant, and stack class names
64
+ * @param projectName - The name of the main application project to register the service to
65
+ *
66
+ * @throws {Error} If the ApplicationStage constructor cannot be found in service-stacks.ts
67
+ */
68
+ async function addServiceStackToMainApplication(tree, service, projectName) {
69
+ const application = (0, devkit_1.readProjectConfiguration)(tree, projectName);
70
+ if (application.root.includes('..')) {
71
+ throw new Error('Invalid application root path');
72
+ }
73
+ const stacksPath = (0, path_1.join)(tree.root, application.root, 'lib/service-stacks.ts');
74
+ if (!(0, fs_1.existsSync)(stacksPath)) {
75
+ console.log('Service Stacks does not exist, skipping service stacks registration.');
76
+ return;
77
+ }
78
+ const project = new ts_morph_1.Project();
79
+ const stackSource = project.addSourceFileAtPath(stacksPath);
80
+ const applicationStage = stackSource.getClassOrThrow('ApplicationStage');
81
+ const stageConstructors = applicationStage?.getConstructors();
82
+ if (!stageConstructors?.length) {
83
+ throw new Error('Unable to find main application stage constructor');
84
+ }
85
+ stackSource.addImportDeclaration({
86
+ moduleSpecifier: `@services/${service.name}`,
87
+ namedImports: [service.constant, service.stack],
88
+ });
89
+ stageConstructors[0]?.addStatements(`new ${service.stack}(this, ${service.constant}.NAME, { ...props, description: ${service.constant}.DESCRIPTION });`);
90
+ await stackSource?.save();
91
+ }
92
+ /**
93
+ * Splits a kebab-case name into an array of capitalized parts.
94
+ *
95
+ * @param name - The kebab-case string to split (e.g., "my-service-name")
96
+ * @returns An array of strings with each part capitalized (e.g., ["My", "Service", "Name"])
97
+ */
98
+ function splitInputName(name) {
99
+ return name.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1));
100
+ }
@@ -0,0 +1,18 @@
1
+ # Editor configuration, see http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ indent_size = 4
8
+ indent_style = space
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+ max_line_length = 100
12
+
13
+ [{package.json,*.yml,*.md}]
14
+ indent_size = 2
15
+ indent_style = space
16
+
17
+ [*.md]
18
+ trim_trailing_whitespace = false