@byaga/cdk-patterns 0.11.0 → 0.11.2
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/lib/create-stack.d.ts +2 -0
- package/lib/create-stack.js +2 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/lambda/create-function.d.ts +1 -1
- package/lib/lambda/create-function.js +3 -3
- package/lib/load-configuration.d.ts +12 -0
- package/lib/load-configuration.js +42 -0
- package/package.json +4 -3
package/lib/create-stack.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { IConstruct } from "constructs";
|
2
2
|
import { Stack } from "aws-cdk-lib";
|
3
3
|
import { StackProps } from "aws-cdk-lib/core";
|
4
|
+
import { StackConfiguration } from "./load-configuration";
|
4
5
|
/**
|
5
6
|
* Interface for the arguments when creating a stack.
|
6
7
|
*/
|
@@ -19,6 +20,7 @@ export interface DeployStack {
|
|
19
20
|
name: string;
|
20
21
|
stage: string;
|
21
22
|
project: string;
|
23
|
+
config: StackConfiguration;
|
22
24
|
}
|
23
25
|
/**
|
24
26
|
* Creates a new stack.
|
package/lib/create-stack.js
CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setCurrentStack = exports.getCurrentStack = exports.createStack = void 0;
|
4
4
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
5
|
const generate_identifier_1 = require("./generate-identifier");
|
6
|
+
const load_configuration_1 = require("./load-configuration");
|
6
7
|
/**
|
7
8
|
* Creates a new stack.
|
8
9
|
* @param {IConstruct} scope - The scope in which to define this construct.
|
@@ -24,6 +25,7 @@ function createStack(scope, props) {
|
|
24
25
|
name: props.stackName,
|
25
26
|
stage,
|
26
27
|
project: props.project,
|
28
|
+
config: (0, load_configuration_1.loadConfiguration)(stage)
|
27
29
|
});
|
28
30
|
}
|
29
31
|
exports.createStack = createStack;
|
package/lib/index.d.ts
CHANGED
@@ -2,6 +2,7 @@ export { buildNodeSource } from './build/nodejs/build-node-source';
|
|
2
2
|
export { buildEcmaScript } from './build/nodejs/build-ecmascript';
|
3
3
|
export { buildTypeScript } from './build/nodejs/build-typescript';
|
4
4
|
export { createNodeJsLambda } from './lambda/create-nodejs-lambda';
|
5
|
-
export { createStack } from './create-stack';
|
5
|
+
export { createStack, StackArguments, getCurrentStack } from './create-stack';
|
6
|
+
export { StackConfiguration } from './load-configuration';
|
6
7
|
export { genName, genId, genStackResourceName, genStackResourceId } from './generate-identifier';
|
7
8
|
export * as ssm from "./ssm";
|
package/lib/index.js
CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
|
26
|
+
exports.ssm = exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = exports.getCurrentStack = exports.createStack = exports.createNodeJsLambda = exports.buildTypeScript = exports.buildEcmaScript = exports.buildNodeSource = void 0;
|
27
27
|
var build_node_source_1 = require("./build/nodejs/build-node-source");
|
28
28
|
Object.defineProperty(exports, "buildNodeSource", { enumerable: true, get: function () { return build_node_source_1.buildNodeSource; } });
|
29
29
|
var build_ecmascript_1 = require("./build/nodejs/build-ecmascript");
|
@@ -34,6 +34,7 @@ var create_nodejs_lambda_1 = require("./lambda/create-nodejs-lambda");
|
|
34
34
|
Object.defineProperty(exports, "createNodeJsLambda", { enumerable: true, get: function () { return create_nodejs_lambda_1.createNodeJsLambda; } });
|
35
35
|
var create_stack_1 = require("./create-stack");
|
36
36
|
Object.defineProperty(exports, "createStack", { enumerable: true, get: function () { return create_stack_1.createStack; } });
|
37
|
+
Object.defineProperty(exports, "getCurrentStack", { enumerable: true, get: function () { return create_stack_1.getCurrentStack; } });
|
37
38
|
var generate_identifier_1 = require("./generate-identifier");
|
38
39
|
Object.defineProperty(exports, "genName", { enumerable: true, get: function () { return generate_identifier_1.genName; } });
|
39
40
|
Object.defineProperty(exports, "genId", { enumerable: true, get: function () { return generate_identifier_1.genId; } });
|
@@ -23,14 +23,14 @@ function createFunction(id, options) {
|
|
23
23
|
const { stack } = (0, create_stack_1.getCurrentStack)();
|
24
24
|
const details = {
|
25
25
|
id,
|
26
|
-
|
26
|
+
lambda: new aws_lambda_1.Function(stack, (0, generate_identifier_1.genStackResourceId)(id, 'lambda'), props)
|
27
27
|
};
|
28
28
|
new aws_cdk_lib_1.CfnOutput(stack, (0, generate_identifier_1.genStackResourceId)(id, 'function-name'), {
|
29
|
-
value: details.
|
29
|
+
value: details.lambda.functionName,
|
30
30
|
exportName: (0, generate_identifier_1.genStackResourceName)(id, 'function-name')
|
31
31
|
});
|
32
32
|
new aws_logs_1.LogRetention(stack, (0, generate_identifier_1.genStackResourceId)(id, 'log-retention'), {
|
33
|
-
logGroupName: details.
|
33
|
+
logGroupName: details.lambda.logGroup.logGroupName,
|
34
34
|
retention: aws_logs_1.RetentionDays.ONE_WEEK,
|
35
35
|
removalPolicy: core_1.RemovalPolicy.DESTROY,
|
36
36
|
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Interface for the stack configuration.
|
3
|
+
*/
|
4
|
+
export interface StackConfiguration {
|
5
|
+
}
|
6
|
+
/**
|
7
|
+
* Loads the configuration for a given stage.
|
8
|
+
* If the configuration file does not exist, an empty object is returned.
|
9
|
+
* @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
10
|
+
* @returns {StackConfiguration} The loaded configuration.
|
11
|
+
*/
|
12
|
+
export declare function loadConfiguration(stage?: string): StackConfiguration;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.loadConfiguration = void 0;
|
27
|
+
const yaml = __importStar(require("js-yaml"));
|
28
|
+
const fs = __importStar(require("fs-extra"));
|
29
|
+
/**
|
30
|
+
* Loads the configuration for a given stage.
|
31
|
+
* If the configuration file does not exist, an empty object is returned.
|
32
|
+
* @param {string} stage - The stage for which to load the configuration. Defaults to the value of the STAGE environment variable, or "develop" if STAGE is not set.
|
33
|
+
* @returns {StackConfiguration} The loaded configuration.
|
34
|
+
*/
|
35
|
+
function loadConfiguration(stage = process.env.STAGE || "develop") {
|
36
|
+
const path = `config/${stage}.yml`;
|
37
|
+
if (fs.existsSync(path)) {
|
38
|
+
return yaml.load(fs.readFileSync(`config/${stage}.yml`).toString());
|
39
|
+
}
|
40
|
+
return {};
|
41
|
+
}
|
42
|
+
exports.loadConfiguration = loadConfiguration;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@byaga/cdk-patterns",
|
3
|
-
"version": "0.11.
|
3
|
+
"version": "0.11.2",
|
4
4
|
"description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
|
5
5
|
"main": "./lib/index.js",
|
6
6
|
"types": "./lib/index.d.ts",
|
@@ -24,12 +24,14 @@
|
|
24
24
|
"constructs": "^10.3.0",
|
25
25
|
"fs-extra": "^11.2.0",
|
26
26
|
"glob": "^10.3.10",
|
27
|
-
"ignore": "^5.3.0"
|
27
|
+
"ignore": "^5.3.0",
|
28
|
+
"js-yaml": "^4.1.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
31
|
"@types/fs-extra": "^11.0.4",
|
31
32
|
"@types/glob": "^8.1.0",
|
32
33
|
"@types/jest": "^29.5.11",
|
34
|
+
"@types/js-yaml": "^4.0.9",
|
33
35
|
"@types/node": "^20.11.5",
|
34
36
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
35
37
|
"@typescript-eslint/parser": "^6.19.0",
|
@@ -38,7 +40,6 @@
|
|
38
40
|
"jest-html-reporters": "^3.1.7",
|
39
41
|
"jest-junit": "^16.0.0",
|
40
42
|
"ts-jest": "^29.1.1",
|
41
|
-
"ts-mockito": "^2.6.1",
|
42
43
|
"typescript": "^5.3.3"
|
43
44
|
},
|
44
45
|
"repository": {
|