@byaga/cdk-patterns 0.9.3 → 0.11.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.
Files changed (117) hide show
  1. package/.fleet/run.json +11 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +43 -0
  4. package/archive/ApiAttachPoint.ts +9 -0
  5. package/archive/ApiCertificate.ts +32 -0
  6. package/{lib/CognitoApiGatewayAuthorizer.d.ts → archive/CognitoApiGatewayAuthorizer.ts} +13 -7
  7. package/archive/DynamoDbTable.ts +40 -0
  8. package/archive/ICorsConfig.ts +5 -0
  9. package/archive/IDomainConfig.ts +8 -0
  10. package/archive/IHostedZoneConfig.ts +5 -0
  11. package/archive/NodeJsLambdaLayer.ts +42 -0
  12. package/archive/Output.ts +11 -0
  13. package/{lib/RestApi.js → archive/RestApi.ts} +96 -60
  14. package/{lib/Role.d.ts → archive/Role.ts} +165 -139
  15. package/archive/StaticWebSite.ts +159 -0
  16. package/archive/index.ts +18 -0
  17. package/archive/methods/apply-schema-to-method-options.ts +38 -0
  18. package/archive/methods/attach-function-to-api.ts +69 -0
  19. package/lib/build/copy-files.d.ts +8 -0
  20. package/lib/{methods/empty-directory.js → build/copy-files.js} +22 -15
  21. package/lib/build/generate-hash.d.ts +7 -0
  22. package/lib/build/generate-hash.js +31 -0
  23. package/lib/build/get-files.d.ts +9 -0
  24. package/lib/build/get-files.js +38 -0
  25. package/lib/build/get-source-directory.d.ts +18 -0
  26. package/lib/build/get-source-directory.js +38 -0
  27. package/lib/build/hash-file.d.ts +18 -0
  28. package/lib/build/hash-file.js +45 -0
  29. package/lib/build/nodejs/build-ecmascript.d.ts +9 -0
  30. package/lib/build/nodejs/build-ecmascript.js +20 -0
  31. package/lib/build/nodejs/build-node-source.d.ts +12 -0
  32. package/lib/build/nodejs/build-node-source.js +39 -0
  33. package/lib/build/nodejs/build-typescript.d.ts +8 -0
  34. package/lib/build/nodejs/build-typescript.js +33 -0
  35. package/lib/build/nodejs/install-node-modules.d.ts +12 -0
  36. package/lib/build/nodejs/install-node-modules.js +30 -0
  37. package/lib/create-stack.d.ts +38 -0
  38. package/lib/create-stack.js +46 -0
  39. package/lib/generate-identifier.d.ts +27 -0
  40. package/lib/generate-identifier.js +65 -0
  41. package/lib/index.d.ts +7 -15
  42. package/lib/index.js +40 -25
  43. package/lib/lambda/create-function.d.ts +20 -0
  44. package/lib/lambda/create-function.js +39 -0
  45. package/lib/lambda/create-nodejs-lambda.d.ts +28 -0
  46. package/lib/lambda/create-nodejs-lambda.js +38 -0
  47. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +2 -0
  48. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +25 -0
  49. package/lib/lambda-layer/get-layer.d.ts +2 -0
  50. package/lib/lambda-layer/get-layer.js +20 -0
  51. package/lib/lambda-layer/layer-cache.d.ts +3 -0
  52. package/lib/lambda-layer/layer-cache.js +12 -0
  53. package/lib/ssm/SsmParameter.d.ts +12 -0
  54. package/lib/ssm/get-existing-parameter.d.ts +9 -0
  55. package/lib/ssm/get-existing-parameter.js +41 -0
  56. package/lib/ssm/grant-read.d.ts +7 -0
  57. package/lib/ssm/grant-read.js +24 -0
  58. package/lib/ssm/index.d.ts +3 -0
  59. package/lib/ssm/index.js +9 -0
  60. package/lib/ssm/parameter-cache.d.ts +13 -0
  61. package/lib/ssm/parameter-cache.js +23 -0
  62. package/lib/ssm/string-value.d.ts +8 -0
  63. package/lib/ssm/string-value.js +14 -0
  64. package/lib/tools/duration.d.ts +10 -0
  65. package/lib/tools/duration.js +28 -0
  66. package/package.json +25 -11
  67. package/jest.config.js +0 -16
  68. package/lib/ApiCertificate.d.ts +0 -10
  69. package/lib/ApiCertificate.js +0 -31
  70. package/lib/CognitoApiGatewayAuthorizer.js +0 -24
  71. package/lib/DeployStack.d.ts +0 -23
  72. package/lib/DeployStack.js +0 -58
  73. package/lib/DynamoDbTable.d.ts +0 -12
  74. package/lib/DynamoDbTable.js +0 -34
  75. package/lib/FunctionIntegration.d.ts +0 -25
  76. package/lib/FunctionIntegration.js +0 -65
  77. package/lib/ICorsConfig.d.ts +0 -5
  78. package/lib/IDeployStack.d.ts +0 -20
  79. package/lib/IDeployStack.js +0 -48
  80. package/lib/IDomainConfig.d.ts +0 -7
  81. package/lib/IDomainConfig.js +0 -2
  82. package/lib/IHostedZoneConfig.d.ts +0 -5
  83. package/lib/IHostedZoneConfig.js +0 -2
  84. package/lib/IStackArguments.d.ts +0 -8
  85. package/lib/IStackArguments.js +0 -2
  86. package/lib/NodeJsLambda.d.ts +0 -13
  87. package/lib/NodeJsLambda.js +0 -28
  88. package/lib/NodeJsLambdaLayer.d.ts +0 -12
  89. package/lib/NodeJsLambdaLayer.js +0 -24
  90. package/lib/Output.d.ts +0 -5
  91. package/lib/Output.js +0 -13
  92. package/lib/RestApi.d.ts +0 -28
  93. package/lib/Role.js +0 -27
  94. package/lib/SsmParameter.d.ts +0 -18
  95. package/lib/SsmParameter.js +0 -40
  96. package/lib/StaticWebSite.d.ts +0 -17
  97. package/lib/StaticWebSite.js +0 -122
  98. package/lib/methods/apply-honeycomb-to-lambda.d.ts +0 -3
  99. package/lib/methods/apply-honeycomb-to-lambda.js +0 -23
  100. package/lib/methods/apply-honeycomb-to-lambda.spec.d.ts +0 -1
  101. package/lib/methods/apply-honeycomb-to-lambda.spec.js +0 -61
  102. package/lib/methods/build-node-source.d.ts +0 -13
  103. package/lib/methods/build-node-source.js +0 -105
  104. package/lib/methods/duration.d.ts +0 -8
  105. package/lib/methods/duration.js +0 -22
  106. package/lib/methods/empty-directory.d.ts +0 -2
  107. package/lib/methods/generate-hash.d.ts +0 -15
  108. package/lib/methods/generate-hash.js +0 -59
  109. package/lib/methods/get-source-directory.d.ts +0 -4
  110. package/lib/methods/get-source-directory.js +0 -37
  111. package/lib/methods/walk-directory.d.ts +0 -14
  112. package/lib/methods/walk-directory.js +0 -48
  113. package/test-results/html/index.html +0 -1
  114. package/test-results/html/jest-html-reporters-attach/index/index.js +0 -3
  115. package/test-results/html/jest-html-reporters-attach/index/result.js +0 -1
  116. package/test-results/junit/junit.xml +0 -13
  117. /package/lib/{ICorsConfig.js → ssm/SsmParameter.js} +0 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateHash = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const fs_1 = require("fs");
6
+ /**
7
+ * Generates a hash for each file in the provided file paths and combines them into a single hash.
8
+ * @function generateHash
9
+ * @param {string[]} filePaths - The file paths to generate hashes for.
10
+ * @returns {string} - The combined hash of all the files.
11
+ */
12
+ function generateHash(filePaths) {
13
+ // Map over each file path
14
+ const hashes = filePaths.map((filePath) => {
15
+ // Create a new hash object
16
+ const hash = (0, crypto_1.createHash)('sha256');
17
+ // Read the file data
18
+ const data = (0, fs_1.readFileSync)(filePath);
19
+ // Update the hash with the file data
20
+ hash.update(data);
21
+ // Compute the hash digest
22
+ return hash.digest('hex');
23
+ });
24
+ // Create a new hash object for the combined hash
25
+ const combinedHash = (0, crypto_1.createHash)('sha256');
26
+ // Update the combined hash with each individual file hash
27
+ hashes.forEach((hash) => combinedHash.update(hash));
28
+ // Return the combined hash digest
29
+ return combinedHash.digest('hex');
30
+ }
31
+ exports.generateHash = generateHash;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns an array of file paths from a directory, excluding files specified in an ignore file.
3
+ *
4
+ * @param {string} dir - The directory to get files from.
5
+ * @param {string} [ignoreFile='.cdkignore'] - The ignore file in the directory. Defaults to '.cdkignore'.
6
+ *
7
+ * @returns {string[]} An array of file paths.
8
+ */
9
+ export declare const getFiles: (dir: string, ignoreFile?: string) => string[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getFiles = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const ignore_1 = __importDefault(require("ignore"));
10
+ const glob_1 = require("glob");
11
+ /**
12
+ * Returns an array of file paths from a directory, excluding files specified in an ignore file.
13
+ *
14
+ * @param {string} dir - The directory to get files from.
15
+ * @param {string} [ignoreFile='.cdkignore'] - The ignore file in the directory. Defaults to '.cdkignore'.
16
+ *
17
+ * @returns {string[]} An array of file paths.
18
+ */
19
+ const getFiles = (dir, ignoreFile = '.cdkignore') => {
20
+ // Create a new ignore manager
21
+ const ig = (0, ignore_1.default)();
22
+ // Resolve the path to the ignore file
23
+ const ignoreFilePath = (0, path_1.resolve)(dir, ignoreFile);
24
+ // If the ignore file exists, add its contents to the ignore manager
25
+ if ((0, fs_1.existsSync)(ignoreFilePath)) {
26
+ ig.add((0, fs_1.readFileSync)(ignoreFilePath, 'utf8'));
27
+ }
28
+ // Get all files in the directory
29
+ const files = (0, glob_1.sync)('**', {
30
+ cwd: dir,
31
+ nodir: true,
32
+ dot: false,
33
+ absolute: true
34
+ });
35
+ // Filter out the files that should be ignored
36
+ return files.filter(file => !ig.ignores((0, path_1.relative)(dir, file)));
37
+ };
38
+ exports.getFiles = getFiles;
@@ -0,0 +1,18 @@
1
+ export declare const sourceRoot: string;
2
+ export declare const distributionRoot: string;
3
+ /**
4
+ * Returns the source directory path for a given type and id.
5
+ * @param {string} type - The type of the source.
6
+ * @param {string} id - The id of the source.
7
+ * @param {string} [subdir=''] - An optional subdirectory.
8
+ * @returns {string} The source directory path.
9
+ */
10
+ export declare function getSourceDirectory(type: string, id: string, subdir?: string): string;
11
+ /**
12
+ * Returns the build directory path for a given type and id.
13
+ * @param {string} type - The type of the build.
14
+ * @param {string} id - The id of the build.
15
+ * @param {string} [subdir=''] - An optional subdirectory.
16
+ * @returns {string} The build directory path.
17
+ */
18
+ export declare function getBuildDirectory(type: string, id: string, subdir?: string): string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBuildDirectory = exports.getSourceDirectory = exports.distributionRoot = exports.sourceRoot = void 0;
4
+ const path_1 = require("path");
5
+ // The root directory for the source files
6
+ exports.sourceRoot = (0, path_1.resolve)(process.cwd(), "../src");
7
+ // The root directory for the distribution files
8
+ exports.distributionRoot = (0, path_1.resolve)(process.cwd(), "../dist");
9
+ /**
10
+ * Returns the source directory path for a given type and id.
11
+ * @param {string} type - The type of the source.
12
+ * @param {string} id - The id of the source.
13
+ * @param {string} [subdir=''] - An optional subdirectory.
14
+ * @returns {string} The source directory path.
15
+ */
16
+ function getSourceDirectory(type, id, subdir = '') {
17
+ return joinPopulated(exports.sourceRoot, type, id, subdir);
18
+ }
19
+ exports.getSourceDirectory = getSourceDirectory;
20
+ /**
21
+ * Returns the build directory path for a given type and id.
22
+ * @param {string} type - The type of the build.
23
+ * @param {string} id - The id of the build.
24
+ * @param {string} [subdir=''] - An optional subdirectory.
25
+ * @returns {string} The build directory path.
26
+ */
27
+ function getBuildDirectory(type, id, subdir = '') {
28
+ return joinPopulated(exports.distributionRoot, type, id, subdir);
29
+ }
30
+ exports.getBuildDirectory = getBuildDirectory;
31
+ /**
32
+ * Joins the given parts into a path, ignoring any empty parts.
33
+ * @param {...string} parts - The parts to join.
34
+ * @returns {string} The joined path.
35
+ */
36
+ function joinPopulated(...parts) {
37
+ return (0, path_1.join)(...parts.filter(part => !!part));
38
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The root directory for the hash.
3
+ */
4
+ export declare const hashRoot: string;
5
+ /**
6
+ * Retrieves the stored hash for the specified source code.
7
+ * @param {string} type - The type of the source code.
8
+ * @param {string} id - The ID of the source code.
9
+ * @returns {string} - The stored hash, or an empty string if no hash is stored.
10
+ */
11
+ export declare function getStoredHash(type: string, id: string): string;
12
+ /**
13
+ * Stores a hash for the specified source code.
14
+ * @param {string} type - The type of the source code.
15
+ * @param {string} id - The ID of the source code.
16
+ * @param {string} hash - The hash to store.
17
+ */
18
+ export declare function storeHash(type: string, id: string, hash: string): void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storeHash = exports.getStoredHash = exports.hashRoot = void 0;
4
+ const path_1 = require("path");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const fs_1 = require("fs");
7
+ const get_source_directory_1 = require("./get-source-directory");
8
+ /**
9
+ * The root directory for the hash.
10
+ */
11
+ exports.hashRoot = (0, path_1.join)(get_source_directory_1.distributionRoot, "hash");
12
+ /**
13
+ * Constructs the file path for the hash file.
14
+ * @param {string} type - The type of the source code.
15
+ * @param {string} id - The ID of the source code.
16
+ * @returns {string} - The file path for the hash file.
17
+ */
18
+ function getHashFilePath(type, id) {
19
+ return (0, path_1.join)(exports.hashRoot, `${type}-${id}-hash.txt`);
20
+ }
21
+ /**
22
+ * Retrieves the stored hash for the specified source code.
23
+ * @param {string} type - The type of the source code.
24
+ * @param {string} id - The ID of the source code.
25
+ * @returns {string} - The stored hash, or an empty string if no hash is stored.
26
+ */
27
+ function getStoredHash(type, id) {
28
+ const hashFilePath = getHashFilePath(type, id);
29
+ const folderExists = (0, fs_extra_1.existsSync)((0, get_source_directory_1.getBuildDirectory)(type, id));
30
+ const hashFileExists = folderExists && (0, fs_extra_1.existsSync)(hashFilePath);
31
+ return hashFileExists ? (0, fs_extra_1.readFileSync)(hashFilePath).toString() : '';
32
+ }
33
+ exports.getStoredHash = getStoredHash;
34
+ /**
35
+ * Stores a hash for the specified source code.
36
+ * @param {string} type - The type of the source code.
37
+ * @param {string} id - The ID of the source code.
38
+ * @param {string} hash - The hash to store.
39
+ */
40
+ function storeHash(type, id, hash) {
41
+ const hashFilePath = getHashFilePath(type, id);
42
+ (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(hashFilePath));
43
+ (0, fs_1.writeFileSync)(hashFilePath, hash);
44
+ }
45
+ exports.storeHash = storeHash;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Builds ECMAScript files.
3
+ * Copies the files from the source directory to the build directory and installs the necessary node modules.
4
+ * @function buildEcmaScript
5
+ * @param {string[]} files - The files to build.
6
+ * @param {string} srcDir - The source directory.
7
+ * @param {string} buildDir - The build directory.
8
+ */
9
+ export declare function buildEcmaScript(files: string[], srcDir: string, buildDir: string): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildEcmaScript = void 0;
4
+ const copy_files_1 = require("../copy-files");
5
+ const install_node_modules_1 = require("./install-node-modules");
6
+ /**
7
+ * Builds ECMAScript files.
8
+ * Copies the files from the source directory to the build directory and installs the necessary node modules.
9
+ * @function buildEcmaScript
10
+ * @param {string[]} files - The files to build.
11
+ * @param {string} srcDir - The source directory.
12
+ * @param {string} buildDir - The build directory.
13
+ */
14
+ function buildEcmaScript(files, srcDir, buildDir) {
15
+ // Copies the files from the source directory to the build directory
16
+ (0, copy_files_1.copyFiles)(files, srcDir, buildDir);
17
+ // Installs the necessary node modules
18
+ (0, install_node_modules_1.installNodeModules)(buildDir, ['dev', 'optional', 'peer']);
19
+ }
20
+ exports.buildEcmaScript = buildEcmaScript;
@@ -0,0 +1,12 @@
1
+ export interface BuildOptions {
2
+ subdirectory?: string;
3
+ }
4
+ /**
5
+ * Builds the source code for a Node.js project.
6
+ * @function buildNodeSource
7
+ * @param {string} type - The type of the source code.
8
+ * @param {string} id - The ID of the source code.
9
+ * @param {BuildOptions} [options] - Options for building the source code.
10
+ * @returns - The build directory containing the resulting source code
11
+ */
12
+ export declare function buildNodeSource(type: string, id: string, options?: BuildOptions): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildNodeSource = void 0;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const get_source_directory_1 = require("../get-source-directory");
9
+ const get_files_1 = require("../get-files");
10
+ const generate_hash_1 = require("../generate-hash");
11
+ const duration_1 = __importDefault(require("../../tools/duration"));
12
+ const build_ecmascript_1 = require("./build-ecmascript");
13
+ const build_typescript_1 = require("./build-typescript");
14
+ const hash_file_1 = require("../hash-file");
15
+ /**
16
+ * Builds the source code for a Node.js project.
17
+ * @function buildNodeSource
18
+ * @param {string} type - The type of the source code.
19
+ * @param {string} id - The ID of the source code.
20
+ * @param {BuildOptions} [options] - Options for building the source code.
21
+ * @returns - The build directory containing the resulting source code
22
+ */
23
+ function buildNodeSource(type, id, options) {
24
+ const srcDir = (0, get_source_directory_1.getSourceDirectory)(type, id, options?.subdirectory);
25
+ const buildDir = (0, get_source_directory_1.getBuildDirectory)(type, id, options?.subdirectory);
26
+ const files = (0, get_files_1.getFiles)(srcDir);
27
+ const hash = (0, generate_hash_1.generateHash)(files);
28
+ if ((0, hash_file_1.getStoredHash)(type, id) === hash)
29
+ return buildDir;
30
+ const rmComplete = (0, duration_1.default)();
31
+ if ((0, fs_extra_1.existsSync)(buildDir))
32
+ (0, fs_extra_1.emptyDirSync)(buildDir);
33
+ console.log('Cleanup Duration (ms)', rmComplete());
34
+ const isTypeScript = !!files.find(file => file.endsWith('tsconfig.json'));
35
+ isTypeScript ? (0, build_typescript_1.buildTypeScript)(srcDir, buildDir) : (0, build_ecmascript_1.buildEcmaScript)(files, srcDir, buildDir);
36
+ (0, hash_file_1.storeHash)(type, id, hash);
37
+ return buildDir;
38
+ }
39
+ exports.buildNodeSource = buildNodeSource;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Builds TypeScript source code.
3
+ * Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
4
+ * @function buildTypeScript
5
+ * @param {string} srcDir - The source directory containing the TypeScript code.
6
+ * @param {string} buildDir - The output directory for the compiled JavaScript code.
7
+ */
8
+ export declare function buildTypeScript(srcDir: string, buildDir: string): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildTypeScript = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const duration_1 = __importDefault(require("../../tools/duration"));
9
+ const fs_extra_1 = require("fs-extra");
10
+ const install_node_modules_1 = require("./install-node-modules");
11
+ /**
12
+ * Builds TypeScript source code.
13
+ * Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
14
+ * @function buildTypeScript
15
+ * @param {string} srcDir - The source directory containing the TypeScript code.
16
+ * @param {string} buildDir - The output directory for the compiled JavaScript code.
17
+ */
18
+ function buildTypeScript(srcDir, buildDir) {
19
+ // Ensure the build directory exists
20
+ (0, fs_extra_1.ensureDirSync)(buildDir);
21
+ // Install necessary node modules
22
+ (0, install_node_modules_1.installNodeModules)(srcDir);
23
+ // Measure the duration of the build process
24
+ const done = (0, duration_1.default)();
25
+ // Compile the TypeScript code
26
+ (0, child_process_1.execSync)(`npm run build -- --outDir ${buildDir}`, {
27
+ cwd: srcDir,
28
+ stdio: 'inherit'
29
+ });
30
+ // Log the duration of the build process
31
+ console.log('NPM Install Duration (ms)', done());
32
+ }
33
+ exports.buildTypeScript = buildTypeScript;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Installs node modules in a specified directory.
3
+ *
4
+ * This function runs the `npm install` command in the specified directory,
5
+ * omitting certain types of dependencies if specified.
6
+ * It also measures and logs the duration of the `npm install` command.
7
+ *
8
+ * @function installNodeModules
9
+ * @param {string} dir - The directory in which to run `npm install`.
10
+ * @param {string[]} [omit=[]] - The types of dependencies to omit. Possible values are 'dev', 'optional', and 'peer'.
11
+ */
12
+ export declare function installNodeModules(dir: string, omit?: string[]): void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.installNodeModules = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const duration_1 = __importDefault(require("../../tools/duration"));
9
+ /**
10
+ * Installs node modules in a specified directory.
11
+ *
12
+ * This function runs the `npm install` command in the specified directory,
13
+ * omitting certain types of dependencies if specified.
14
+ * It also measures and logs the duration of the `npm install` command.
15
+ *
16
+ * @function installNodeModules
17
+ * @param {string} dir - The directory in which to run `npm install`.
18
+ * @param {string[]} [omit=[]] - The types of dependencies to omit. Possible values are 'dev', 'optional', and 'peer'.
19
+ */
20
+ function installNodeModules(dir, omit = []) {
21
+ // Start measuring the duration of the `npm install` command
22
+ const installComplete = (0, duration_1.default)();
23
+ // Run the `npm install` command in the specified directory, omitting certain types of dependencies if specified
24
+ (0, child_process_1.execSync)(`npm i${omit.join(' --omit=')} --quite`, {
25
+ cwd: dir
26
+ });
27
+ // Log the duration of the `npm install` command
28
+ console.log('NPM Install Duration (ms)', installComplete());
29
+ }
30
+ exports.installNodeModules = installNodeModules;
@@ -0,0 +1,38 @@
1
+ import { IConstruct } from "constructs";
2
+ import { Stack } from "aws-cdk-lib";
3
+ import { StackProps } from "aws-cdk-lib/core";
4
+ /**
5
+ * Interface for the arguments when creating a stack.
6
+ */
7
+ export interface StackArguments extends StackProps {
8
+ stackName: string;
9
+ stage?: string;
10
+ project: string;
11
+ owner: string;
12
+ region: string;
13
+ }
14
+ /**
15
+ * Interface for the deploy stack.
16
+ */
17
+ export interface DeployStack {
18
+ stack: Stack;
19
+ name: string;
20
+ stage: string;
21
+ project: string;
22
+ }
23
+ /**
24
+ * Creates a new stack.
25
+ * @param {IConstruct} scope - The scope in which to define this construct.
26
+ * @param {StackArguments} props - The arguments for creating the stack.
27
+ * @returns {DeployStack} The created stack.
28
+ */
29
+ export declare function createStack(scope: IConstruct, props: StackArguments): DeployStack;
30
+ /**
31
+ * Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
32
+ */
33
+ export declare function getCurrentStack(): DeployStack;
34
+ /**
35
+ * This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
36
+ * @param stack
37
+ */
38
+ export declare function setCurrentStack(stack: DeployStack): DeployStack;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setCurrentStack = exports.getCurrentStack = exports.createStack = void 0;
4
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ const generate_identifier_1 = require("./generate-identifier");
6
+ /**
7
+ * Creates a new stack.
8
+ * @param {IConstruct} scope - The scope in which to define this construct.
9
+ * @param {StackArguments} props - The arguments for creating the stack.
10
+ * @returns {DeployStack} The created stack.
11
+ */
12
+ function createStack(scope, props) {
13
+ const { stage = 'develop' } = props;
14
+ const stack = new aws_cdk_lib_1.Stack(scope, (0, generate_identifier_1.genId)(props.stackName, stage), {
15
+ ...props,
16
+ stackName: (0, generate_identifier_1.genName)(props.stackName, stage)
17
+ });
18
+ stack.tags.setTag('stage', stage);
19
+ stack.tags.setTag('stack', (0, generate_identifier_1.genName)(props.stackName, stage));
20
+ stack.tags.setTag('project', props.project);
21
+ stack.tags.setTag('owner', props.owner);
22
+ return setCurrentStack({
23
+ stack,
24
+ name: props.stackName,
25
+ stage,
26
+ project: props.project,
27
+ });
28
+ }
29
+ exports.createStack = createStack;
30
+ let currentStack;
31
+ /**
32
+ * Helpful method to get the 'current' stack that is being defined. Hopefully this will reduce the need to pass the stack around everywhere.
33
+ */
34
+ function getCurrentStack() {
35
+ return currentStack;
36
+ }
37
+ exports.getCurrentStack = getCurrentStack;
38
+ /**
39
+ * This sets the 'current' stack. This should be automatic everywhere, but in case something goes wrong here is a way to force the issue
40
+ * @param stack
41
+ */
42
+ function setCurrentStack(stack) {
43
+ currentStack = stack;
44
+ return stack;
45
+ }
46
+ exports.setCurrentStack = setCurrentStack;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Generates a name by joining the provided strings with a hyphen.
3
+ * Each string is converted to lowercase and any uppercase letters are replaced with a hyphen followed by the lowercase letter.
4
+ * @param {...string} name - The strings to join.
5
+ * @returns {string} The generated name.
6
+ */
7
+ export declare function genName(...name: string[]): string;
8
+ /**
9
+ * Generates an ID by joining the provided strings with a hyphen.
10
+ * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
11
+ * @param {...string} name - The strings to join.
12
+ * @returns {string} The generated ID.
13
+ */
14
+ export declare function genId(...name: string[]): string;
15
+ /**
16
+ * Generates a resource name for a stack by joining the stack name, resource, and stage with a hyphen.
17
+ * @param {...} resource - The resource.
18
+ * @returns The generated resource name.
19
+ */
20
+ export declare function genStackResourceName(...resource: string[]): string;
21
+ /**
22
+ * Generates a resource ID for a stack by joining the stack name, stage, and resource.
23
+ * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
24
+ * @param {...} resource - The resource.
25
+ * @returns The generated resource ID.
26
+ */
27
+ export declare function genStackResourceId(...resource: string[]): string;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genStackResourceId = exports.genStackResourceName = exports.genId = exports.genName = void 0;
4
+ const create_stack_1 = require("./create-stack");
5
+ /**
6
+ * Generates a name by joining the provided strings with a hyphen.
7
+ * Each string is converted to lowercase and any uppercase letters are replaced with a hyphen followed by the lowercase letter.
8
+ * @param {...string} name - The strings to join.
9
+ * @returns {string} The generated name.
10
+ */
11
+ function genName(...name) {
12
+ return replaceMultipleDashesWithSingleDash(name
13
+ .filter(n => !!n)
14
+ .map(removeSpecialCharacters)
15
+ .map(toKebabCase)
16
+ .join('-')
17
+ .toLowerCase());
18
+ }
19
+ exports.genName = genName;
20
+ /**
21
+ * Generates an ID by joining the provided strings with a hyphen.
22
+ * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
23
+ * @param {...string} name - The strings to join.
24
+ * @returns {string} The generated ID.
25
+ */
26
+ function genId(...name) {
27
+ return toProperCase(genName(...name));
28
+ }
29
+ exports.genId = genId;
30
+ /**
31
+ * Generates a resource name for a stack by joining the stack name, resource, and stage with a hyphen.
32
+ * @param {...} resource - The resource.
33
+ * @returns The generated resource name.
34
+ */
35
+ function genStackResourceName(...resource) {
36
+ const stack = (0, create_stack_1.getCurrentStack)();
37
+ return genName(stack.name, ...resource, stack.stage);
38
+ }
39
+ exports.genStackResourceName = genStackResourceName;
40
+ /**
41
+ * Generates a resource ID for a stack by joining the stack name, stage, and resource.
42
+ * The first letter of the ID is capitalized and any hyphen followed by a letter is replaced with the uppercase letter.
43
+ * @param {...} resource - The resource.
44
+ * @returns The generated resource ID.
45
+ */
46
+ function genStackResourceId(...resource) {
47
+ const stack = (0, create_stack_1.getCurrentStack)();
48
+ return genId(stack.name, ...resource, stack.stage);
49
+ }
50
+ exports.genStackResourceId = genStackResourceId;
51
+ function removeSpecialCharacters(name) {
52
+ return name.replace(/[_/\\]/g, '-');
53
+ }
54
+ function replaceMultipleDashesWithSingleDash(name) {
55
+ return name.replace(/-{2,}/g, '-');
56
+ }
57
+ function toKebabCase(name) {
58
+ return name[0] + name.substring(1).replace(/[A-Z]/g, v => '-' + v.toLowerCase());
59
+ }
60
+ function toProperCase(name) {
61
+ return name.split('-')
62
+ .filter(n => !!n)
63
+ .map(v => v[0].toUpperCase() + v.substring(1))
64
+ .join('');
65
+ }
package/lib/index.d.ts CHANGED
@@ -1,15 +1,7 @@
1
- export { ApiCertificate } from "./ApiCertificate";
2
- export { CognitoApiGatewayAuthorizer } from "./CognitoApiGatewayAuthorizer";
3
- export { DeployStack } from "./DeployStack";
4
- export { DynamoDbTable } from "./DynamoDbTable";
5
- export { FunctionIntegration } from "./FunctionIntegration";
6
- export { IHostedZoneConfig } from "./IHostedZoneConfig";
7
- export { IDomainConfig } from "./IDomainConfig";
8
- export { IStackArguments } from "./IStackArguments";
9
- export { NodeJsLambda } from "./NodeJsLambda";
10
- export { NodeJsLambdaLayer } from "./NodeJsLambdaLayer";
11
- export { Output } from "./Output";
12
- export { RestApi } from "./RestApi";
13
- export { Role } from "./Role";
14
- export { SsmParameter } from "./SsmParameter";
15
- export { StaticWebSite } from "./StaticWebSite";
1
+ export { buildNodeSource } from './build/nodejs/build-node-source';
2
+ export { buildEcmaScript } from './build/nodejs/build-ecmascript';
3
+ export { buildTypeScript } from './build/nodejs/build-typescript';
4
+ export { createNodeJsLambda } from './lambda/create-nodejs-lambda';
5
+ export { createStack } from './create-stack';
6
+ export { genName, genId, genStackResourceName, genStackResourceId } from './generate-identifier';
7
+ export * as ssm from "./ssm";