@aligent/nx-cdk 0.5.0 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aligent/nx-cdk",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "typings": "./src/index.d.ts",
@@ -1,20 +1,16 @@
1
1
  import { Stack, Stage, StackProps, Tags } from 'aws-cdk-lib';
2
- import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
3
- import { IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';
4
2
  import { Construct } from 'constructs';
3
+ <% if (example) { %>import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
4
+ import { IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';<% } %>
5
5
 
6
- // EXAMPLE ONLY: The following interface, class, and all related resource references
7
- // (eCommerceBaseUrl, eCommerceCredentials, etc.) are illustrative examples.
8
- // Replace them with your own resources and props that match your actual infrastructure.
9
6
  export interface SharedInfraProps {
10
- // eCommerceBaseUrl: IStringParameter;
11
- // eCommerceCredentials: Secret;
7
+ <% if (example) { %>paramExample: IStringParameter;
8
+ secretExample: Secret;<% } %>
12
9
  }
13
10
 
14
11
  export class SharedInfraStack extends Stack {
15
- // EXAMPLE: Replace these properties with your own shared resources
16
- // readonly eCommerceBaseUrl: IStringParameter;
17
- // readonly eCommerceCredentials: Secret;
12
+ <% if (example) { %>readonly paramExample: IStringParameter;
13
+ readonly secretExample: Secret;<% } %>
18
14
 
19
15
  constructor(scope: Construct, id: string, props?: StackProps) {
20
16
  super(scope, id, props);
@@ -24,25 +20,24 @@ export class SharedInfraStack extends Stack {
24
20
  }
25
21
 
26
22
  Tags.of(this).add('SERVICE', id);
27
-
28
- // EXAMPLE: Replace with your own SSM parameter lookup
29
- // this.eCommerceBaseUrl = StringParameter.fromStringParameterName(
30
- // this,
31
- // 'ECommerceBaseUrl',
32
- // `/e-commerce/base-url`
33
- // );
34
-
35
- // EXAMPLE: Replace with your own secrets/resources
36
- // this.eCommerceCredentials = new Secret(this, 'ECommerceCredentials', {
37
- // description: 'E-Commerce API credentials shared across services',
38
- // });
23
+ <% if (example) { %>
24
+ this.paramExample = StringParameter.fromStringParameterName(
25
+ this,
26
+ 'ParamExample',
27
+ `/example/param`
28
+ );
29
+
30
+ this.secretExample = new Secret(this, 'SecretExample', {
31
+ description: 'Example secret shared across services',
32
+ });
33
+ <% } %>
39
34
  }
40
35
 
41
- // EXAMPLE: Update getProps() to return your own resource props
42
36
  getProps(): SharedInfraProps {
43
37
  return {
44
- // eCommerceBaseUrl: this.eCommerceBaseUrl,
45
- // eCommerceCredentials: this.eCommerceCredentials,
38
+ <% if (example) { %>paramExample: this.paramExample,
39
+ secretExample: this.secretExample,
40
+ <% } %>
46
41
  };
47
42
  }
48
43
  }
@@ -2,6 +2,6 @@
2
2
  export interface PresetGeneratorSchema {
3
3
  name: string;
4
4
  nodeVersion: string;
5
- // FIXME: [MI-281] Add this into schema.json once we move to our own cli tool
6
5
  destination?: string;
6
+ example?: boolean;
7
7
  }
@@ -26,6 +26,17 @@
26
26
  "x-prompt": "What is the target Node.js version the project?",
27
27
  "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$",
28
28
  "patternErrorMessage": "Node.js version must be a valid semantic version (semver), e.g. 22.10.0 or 24.10.0"
29
+ },
30
+ "destination": {
31
+ "type": "string",
32
+ "description": "The destination directory for the generated workspace",
33
+ "pattern": "^[a-zA-Z0-9_./-]+$",
34
+ "patternErrorMessage": "Destination must be a valid path containing only alphanumeric characters, dashes, underscores, dots, and slashes"
35
+ },
36
+ "example": {
37
+ "type": "boolean",
38
+ "description": "Generate example code with sample resources",
39
+ "default": false
29
40
  }
30
41
  },
31
42
  "required": ["name"]
@@ -1,8 +1,6 @@
1
1
  import { SharedInfraProps } from '@libs/infra';
2
2
  import { Stack, StackProps, Stage, Tags } from 'aws-cdk-lib';
3
- import { Code } from 'aws-cdk-lib/aws-lambda';
4
3
  import { Construct } from 'constructs';
5
- import path from 'node:path';
6
4
 
7
5
  /**
8
6
  * @important
@@ -24,7 +22,20 @@ interface Props extends StackProps, SharedInfraProps {
24
22
  *
25
23
  * Instantiate in a CDK Application Stage to deploy to AWS.
26
24
  *
27
- * Use 'resolve' helpers below when referencing lambda handlers, step function files etc.
25
+ * @note Aligent provides the following standard CDK constructs:
26
+ * - {@link NodejsFunctionFromEntry} from '@aligent/cdk-nodejs-function-from-entry'
27
+ * - {@link StepFunctionFromFile} from '@aligent/cdk-step-function-from-file'
28
+ *
29
+ * @example
30
+ * new NodejsFunctionFromEntry(this, 'ExampleLambda', {
31
+ * baseDir: import.meta.dirname,
32
+ * entry: 'runtime/handlers/example.ts',
33
+ * });
34
+ *
35
+ * new StepFunctionFromFile(this, 'ExampleStepFunction', {
36
+ * baseDir: import.meta.dirname,
37
+ * filepath: 'infra/stepfunctions/example.json',
38
+ * });
28
39
  */
29
40
  export class <%= stack %> extends Stack {
30
41
  constructor(scope: Construct, id: Id, props: Props) {
@@ -37,39 +48,3 @@ export class <%= stack %> extends Stack {
37
48
  Tags.of(this).add('SERVICE', id);
38
49
  }
39
50
  }
40
-
41
- /**
42
- * Resolves a path to infra assets relative to this stack
43
- *
44
- * @param assetPath - The path to the asset.
45
- * @returns The resolved path.
46
- */
47
- export function resolveAssetPath(assetPath: `${'infra/'}${string}`) {
48
- return path.resolve(import.meta.dirname, assetPath);
49
- }
50
-
51
- /**
52
- * Return an object with the default bundled code asset and
53
- * handler property for use with the NodejsFunction construct.
54
- *
55
- * @example
56
- * ```ts
57
- * new NodejsFunction(this, 'FetchData', {
58
- * ...resolveLambdaHandler('runtime/handlers/fetch-data.ts'),
59
- * });
60
- * ```
61
- *
62
- * @param assetPath - The path to the typescript handler file.
63
- * @returns The resolved bundled code path and handler name.
64
- */
65
- export function resolveLambdaHandler(assetPath: `${'runtime/handlers/'}${string}${'.ts'}`) {
66
- // Replace 'runtime/handlers/' with '..dist/' and remove the file extension
67
- const bundledPath = assetPath.replace(
68
- /^runtime\/handlers\/(?<path>.*)\.ts$/,
69
- '../dist/$<path>'
70
- );
71
- return {
72
- code: Code.fromAsset(path.resolve(import.meta.dirname, bundledPath)),
73
- handler: 'index.handler',
74
- };
75
- }