@byaga/cdk-patterns 0.11.5 → 0.11.6

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 (111) hide show
  1. package/LICENSE.md +20 -20
  2. package/README.md +42 -42
  3. package/eslint.config.mjs +12 -0
  4. package/lib/build/copy-files.d.ts +4 -5
  5. package/lib/build/copy-files.js +26 -21
  6. package/lib/build/generate-hash.d.ts +2 -3
  7. package/lib/build/generate-hash.js +3 -5
  8. package/lib/build/get-files.d.ts +3 -3
  9. package/lib/build/get-files.js +3 -3
  10. package/lib/build/get-source-directory.d.ts +8 -8
  11. package/lib/build/get-source-directory.js +13 -13
  12. package/lib/build/hash-file.js +4 -5
  13. package/lib/build/index.d.ts +2 -0
  14. package/lib/build/index.js +21 -0
  15. package/lib/build/nodejs/build-ecmascript.d.ts +3 -3
  16. package/lib/build/nodejs/build-ecmascript.js +4 -5
  17. package/lib/build/nodejs/build-node-source.d.ts +9 -3
  18. package/lib/build/nodejs/build-node-source.js +10 -11
  19. package/lib/build/nodejs/build-typescript.d.ts +3 -3
  20. package/lib/build/nodejs/build-typescript.js +7 -10
  21. package/lib/build/nodejs/index.d.ts +1 -0
  22. package/lib/build/nodejs/index.js +5 -0
  23. package/lib/build/nodejs/install-node-modules.d.ts +4 -3
  24. package/lib/build/nodejs/install-node-modules.js +6 -6
  25. package/lib/cloud-formation/DeployStack.d.ts +11 -0
  26. package/lib/cloud-formation/DeployStack.js +2 -0
  27. package/lib/cloud-formation/create-stack.d.ts +20 -0
  28. package/lib/cloud-formation/create-stack.js +31 -0
  29. package/lib/cloud-formation/current-stack.d.ts +10 -0
  30. package/lib/cloud-formation/current-stack.js +19 -0
  31. package/lib/{generate-identifier.js → cloud-formation/generate-identifier.js} +7 -8
  32. package/lib/cloud-formation/index.d.ts +5 -0
  33. package/lib/cloud-formation/index.js +14 -0
  34. package/lib/cloud-formation/output.d.ts +2 -0
  35. package/lib/cloud-formation/output.js +12 -0
  36. package/lib/cloud-front/distribution.d.ts +16 -0
  37. package/lib/cloud-front/distribution.js +43 -0
  38. package/lib/cloud-front/index.d.ts +1 -0
  39. package/lib/cloud-front/index.js +5 -0
  40. package/lib/cloud-watch/create-log-group.js +4 -6
  41. package/lib/cloud-watch/index.d.ts +1 -0
  42. package/lib/cloud-watch/index.js +5 -0
  43. package/lib/cloud-watch/set-log-retention.d.ts +2 -0
  44. package/lib/cloud-watch/set-log-retention.js +14 -0
  45. package/lib/index.d.ts +11 -8
  46. package/lib/index.js +13 -29
  47. package/lib/lambda/create-function.d.ts +4 -2
  48. package/lib/lambda/create-function.js +15 -23
  49. package/lib/lambda/create-nodejs-lambda.d.ts +2 -2
  50. package/lib/lambda/create-nodejs-lambda.js +3 -4
  51. package/lib/lambda/index.d.ts +1 -0
  52. package/lib/lambda/index.js +5 -0
  53. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +1 -1
  54. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +4 -5
  55. package/lib/lambda-layer/get-layer.js +4 -6
  56. package/lib/lambda-layer/index.d.ts +2 -0
  57. package/lib/lambda-layer/index.js +7 -0
  58. package/lib/lambda-layer/layer-cache.d.ts +3 -3
  59. package/lib/lambda-layer/layer-cache.js +3 -9
  60. package/lib/load-configuration.d.ts +3 -8
  61. package/lib/load-configuration.js +20 -11
  62. package/lib/recipes/ICorsConfig.d.ts +5 -0
  63. package/lib/recipes/ICorsConfig.js +2 -0
  64. package/lib/recipes/index.d.ts +1 -0
  65. package/lib/recipes/index.js +5 -0
  66. package/lib/recipes/staticWebSite.d.ts +13 -0
  67. package/lib/recipes/staticWebSite.js +54 -0
  68. package/lib/route53/IDomainConfig.d.ts +7 -0
  69. package/lib/route53/IDomainConfig.js +2 -0
  70. package/lib/route53/IHostedZoneConfig.d.ts +5 -0
  71. package/lib/route53/IHostedZoneConfig.js +2 -0
  72. package/lib/route53/apiCertificate.d.ts +13 -0
  73. package/lib/route53/apiCertificate.js +30 -0
  74. package/lib/route53/index.d.ts +3 -0
  75. package/lib/route53/index.js +5 -0
  76. package/lib/s3/bucket.d.ts +8 -0
  77. package/lib/s3/bucket.js +21 -0
  78. package/lib/s3/index.d.ts +1 -0
  79. package/lib/s3/index.js +5 -0
  80. package/lib/ssm/SsmParameter.d.ts +2 -2
  81. package/lib/ssm/StringParameter.d.ts +9 -0
  82. package/lib/ssm/StringParameter.js +15 -0
  83. package/lib/ssm/get-existing-parameter.js +4 -6
  84. package/lib/ssm/grant-read.js +1 -2
  85. package/lib/ssm/index.d.ts +1 -0
  86. package/lib/ssm/index.js +3 -1
  87. package/lib/ssm/parameter-cache.js +2 -3
  88. package/lib/ssm/string-value.js +1 -2
  89. package/lib/tools/index.d.ts +3 -0
  90. package/lib/tools/index.js +10 -0
  91. package/package.json +21 -15
  92. package/tsconfig.json +2 -2
  93. package/.fleet/run.json +0 -11
  94. package/archive/ApiAttachPoint.ts +0 -9
  95. package/archive/ApiCertificate.ts +0 -32
  96. package/archive/CognitoApiGatewayAuthorizer.ts +0 -25
  97. package/archive/DynamoDbTable.ts +0 -40
  98. package/archive/ICorsConfig.ts +0 -5
  99. package/archive/IDomainConfig.ts +0 -8
  100. package/archive/IHostedZoneConfig.ts +0 -5
  101. package/archive/NodeJsLambdaLayer.ts +0 -42
  102. package/archive/Output.ts +0 -11
  103. package/archive/RestApi.ts +0 -180
  104. package/archive/Role.ts +0 -165
  105. package/archive/StaticWebSite.ts +0 -158
  106. package/archive/index.ts +0 -18
  107. package/archive/methods/apply-schema-to-method-options.ts +0 -38
  108. package/archive/methods/attach-function-to-api.ts +0 -69
  109. package/lib/create-stack.d.ts +0 -40
  110. package/lib/create-stack.js +0 -48
  111. /package/lib/{generate-identifier.d.ts → cloud-formation/generate-identifier.d.ts} +0 -0
package/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 VeryFineHat
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 VeryFineHat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,43 +1,43 @@
1
- # @byaga/cdk-patterns
2
-
3
- This package provides a set of reusable patterns for the AWS Cloud Development Kit (CDK).
4
-
5
- NOTE: This package is highly opinionated and is intended to be used by the author. Use at your own risk/joy.
6
-
7
- ## Installation
8
-
9
- To install the package, use the following command:
10
-
11
- ```bash
12
- npm install @byaga/cdk-patterns
13
- ```
14
-
15
- ## Usage
16
-
17
- Import the package in your TypeScript or JavaScript file:
18
-
19
- ```typescript
20
- import { Pattern } from '@byaga/cdk-patterns';
21
- ```
22
-
23
- Then, you can use the patterns provided by the package in your CDK stacks.
24
-
25
- ## Patterns
26
-
27
- The package includes the following patterns:
28
-
29
- - [createStack](./src/create-stack.md)
30
- - [createNodeJsLambda](./src/create-nodejs-lambda.md)
31
-
32
- And the below helpful functions:
33
-
34
- - [Building Code](./src/build-code.md)
35
- - [Generating Identifiers](./src/generate-identifier.md)
36
-
37
- ## Contributing
38
-
39
- Contributions are welcome! Please read our contributing guidelines for details.
40
-
41
- ## License
42
-
1
+ # @byaga/cdk-patterns
2
+
3
+ This package provides a set of reusable patterns for the AWS Cloud Development Kit (CDK).
4
+
5
+ NOTE: This package is highly opinionated and is intended to be used by the author. Use at your own risk/joy.
6
+
7
+ ## Installation
8
+
9
+ To install the package, use the following command:
10
+
11
+ ```bash
12
+ npm install @byaga/cdk-patterns
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Import the package in your TypeScript or JavaScript file:
18
+
19
+ ```typescript
20
+ import { Pattern } from '@byaga/cdk-patterns';
21
+ ```
22
+
23
+ Then, you can use the patterns provided by the package in your CDK stacks.
24
+
25
+ ## Patterns
26
+
27
+ The package includes the following patterns:
28
+
29
+ - [createStack](./src/cloud-formation/create-stack.md)
30
+ - [createNodeJsLambda](./src/lambda/createNodeJsLambda.md)
31
+
32
+ And the below helpful functions:
33
+
34
+ - [Building Code](./src/build-code.md)
35
+ - [Generating Identifiers](./src/generate-identifier.md)
36
+
37
+ ## Contributing
38
+
39
+ Contributions are welcome! Please read our contributing guidelines for details.
40
+
41
+ ## License
42
+
43
43
  This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,12 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+
5
+
6
+ /** @type {import('eslint').Linter.Config[]} */
7
+ export default [
8
+ {files: ["**/*.{js,mjs,cjs,ts}"]},
9
+ {languageOptions: { globals: globals.node }},
10
+ pluginJs.configs.recommended,
11
+ ...tseslint.configs.recommended,
12
+ ];
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Copies files from the source directory to the build directory.
3
- * @function copyFiles
4
- * @param {string[]} files - The files to copy.
5
- * @param {string} srcDir - The source directory.
6
- * @param {string} buildDir - The build directory.
3
+ * @param files - List of files to copy.
4
+ * @param src - Where the files are being copied from.
5
+ * @param dest - Where the copies should be placed
7
6
  */
8
- export declare function copyFiles(files: string[], srcDir: string, buildDir: string): void;
7
+ export declare function copyFiles(files: string[], src: string, dest: string): void;
@@ -15,39 +15,44 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
28
35
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.copyFiles = void 0;
36
+ exports.copyFiles = copyFiles;
30
37
  const path = __importStar(require("path"));
31
38
  const fse = __importStar(require("fs-extra"));
32
- const duration_1 = __importDefault(require("../tools/duration"));
39
+ const tools_1 = require("../tools");
33
40
  /**
34
41
  * Copies files from the source directory to the build directory.
35
- * @function copyFiles
36
- * @param {string[]} files - The files to copy.
37
- * @param {string} srcDir - The source directory.
38
- * @param {string} buildDir - The build directory.
42
+ * @param files - List of files to copy.
43
+ * @param src - Where the files are being copied from.
44
+ * @param dest - Where the copies should be placed
39
45
  */
40
- function copyFiles(files, srcDir, buildDir) {
46
+ function copyFiles(files, src, dest) {
41
47
  // Measure the duration of the copy process
42
- const copyComplete = (0, duration_1.default)();
48
+ const copyComplete = (0, tools_1.duration)();
43
49
  // For each file, calculate the relative path from the source directory,
44
50
  // resolve the target path in the build directory, and copy the file
45
51
  files.forEach((filePath) => {
46
- const relativePath = path.relative(srcDir, filePath);
47
- const targetPath = path.resolve(buildDir, relativePath);
52
+ const relativePath = path.relative(src, filePath);
53
+ const targetPath = path.resolve(dest, relativePath);
48
54
  fse.copySync(filePath, targetPath);
49
55
  });
50
56
  // Log the duration of the copy process
51
57
  console.log('Copy Duration (ms)', copyComplete());
52
58
  }
53
- exports.copyFiles = copyFiles;
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Generates a hash for each file in the provided file paths and combines them into a single hash.
3
- * @function generateHash
4
- * @param {string[]} filePaths - The file paths to generate hashes for.
5
- * @returns {string} - The combined hash of all the files.
3
+ * @param filePaths - The file paths to generate hashes for.
4
+ * @returns A hash string representing the combination of each file
6
5
  */
7
6
  export declare function generateHash(filePaths: string[]): string;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateHash = void 0;
3
+ exports.generateHash = generateHash;
4
4
  const crypto_1 = require("crypto");
5
5
  const fs_1 = require("fs");
6
6
  /**
7
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.
8
+ * @param filePaths - The file paths to generate hashes for.
9
+ * @returns A hash string representing the combination of each file
11
10
  */
12
11
  function generateHash(filePaths) {
13
12
  // Map over each file path
@@ -28,4 +27,3 @@ function generateHash(filePaths) {
28
27
  // Return the combined hash digest
29
28
  return combinedHash.digest('hex');
30
29
  }
31
- exports.generateHash = generateHash;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Returns an array of file paths from a directory, excluding files specified in an ignore file.
3
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'.
4
+ * @param dir - The directory to get files from.
5
+ * @param ignoreFile - The ignore file in the directory. Defaults to '.cdkignore'.
6
6
  *
7
- * @returns {string[]} An array of file paths.
7
+ * @returns An array of file paths.
8
8
  */
9
9
  export declare const getFiles: (dir: string, ignoreFile?: string) => string[];
@@ -11,10 +11,10 @@ const glob_1 = require("glob");
11
11
  /**
12
12
  * Returns an array of file paths from a directory, excluding files specified in an ignore file.
13
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'.
14
+ * @param dir - The directory to get files from.
15
+ * @param ignoreFile - The ignore file in the directory. Defaults to '.cdkignore'.
16
16
  *
17
- * @returns {string[]} An array of file paths.
17
+ * @returns An array of file paths.
18
18
  */
19
19
  const getFiles = (dir, ignoreFile = '.cdkignore') => {
20
20
  // Create a new ignore manager
@@ -2,17 +2,17 @@ export declare const sourceRoot: string;
2
2
  export declare const distributionRoot: string;
3
3
  /**
4
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.
5
+ * @param type - The type of the source.
6
+ * @param id - The id of the source.
7
+ * @param subdir - An optional subdirectory.
8
+ * @returns The source directory path.
9
9
  */
10
10
  export declare function getSourceDirectory(type: string, id: string, subdir?: string): string;
11
11
  /**
12
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.
13
+ * @param type - The type of the build.
14
+ * @param id - The id of the build.
15
+ * @param subdir - An optional subdirectory.
16
+ * @returns The build directory path.
17
17
  */
18
18
  export declare function getBuildDirectory(type: string, id: string, subdir?: string): string;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBuildDirectory = exports.getSourceDirectory = exports.distributionRoot = exports.sourceRoot = void 0;
3
+ exports.distributionRoot = exports.sourceRoot = void 0;
4
+ exports.getSourceDirectory = getSourceDirectory;
5
+ exports.getBuildDirectory = getBuildDirectory;
4
6
  const path_1 = require("path");
5
7
  // The root directory for the source files
6
8
  exports.sourceRoot = (0, path_1.resolve)(process.cwd(), "../src");
@@ -8,30 +10,28 @@ exports.sourceRoot = (0, path_1.resolve)(process.cwd(), "../src");
8
10
  exports.distributionRoot = (0, path_1.resolve)(process.cwd(), "../dist");
9
11
  /**
10
12
  * 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.
13
+ * @param type - The type of the source.
14
+ * @param id - The id of the source.
15
+ * @param subdir - An optional subdirectory.
16
+ * @returns The source directory path.
15
17
  */
16
18
  function getSourceDirectory(type, id, subdir = '') {
17
19
  return joinPopulated(exports.sourceRoot, type, id, subdir);
18
20
  }
19
- exports.getSourceDirectory = getSourceDirectory;
20
21
  /**
21
22
  * 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.
23
+ * @param type - The type of the build.
24
+ * @param id - The id of the build.
25
+ * @param subdir - An optional subdirectory.
26
+ * @returns The build directory path.
26
27
  */
27
28
  function getBuildDirectory(type, id, subdir = '') {
28
29
  return joinPopulated(exports.distributionRoot, type, id, subdir);
29
30
  }
30
- exports.getBuildDirectory = getBuildDirectory;
31
31
  /**
32
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.
33
+ * @param parts - The parts to join.
34
+ * @returns The joined path.
35
35
  */
36
36
  function joinPopulated(...parts) {
37
37
  return (0, path_1.join)(...parts.filter(part => !!part));
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storeHash = exports.getStoredHash = exports.hashRoot = void 0;
3
+ exports.hashRoot = void 0;
4
+ exports.getStoredHash = getStoredHash;
5
+ exports.storeHash = storeHash;
4
6
  const path_1 = require("path");
5
7
  const fs_extra_1 = require("fs-extra");
6
- const fs_1 = require("fs");
7
8
  const get_source_directory_1 = require("./get-source-directory");
8
9
  /**
9
10
  * The root directory for the hash.
@@ -30,7 +31,6 @@ function getStoredHash(type, id) {
30
31
  const hashFileExists = folderExists && (0, fs_extra_1.existsSync)(hashFilePath);
31
32
  return hashFileExists ? (0, fs_extra_1.readFileSync)(hashFilePath).toString() : '';
32
33
  }
33
- exports.getStoredHash = getStoredHash;
34
34
  /**
35
35
  * Stores a hash for the specified source code.
36
36
  * @param {string} type - The type of the source code.
@@ -40,6 +40,5 @@ exports.getStoredHash = getStoredHash;
40
40
  function storeHash(type, id, hash) {
41
41
  const hashFilePath = getHashFilePath(type, id);
42
42
  (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(hashFilePath));
43
- (0, fs_1.writeFileSync)(hashFilePath, hash);
43
+ (0, fs_extra_1.writeFileSync)(hashFilePath, hash);
44
44
  }
45
- exports.storeHash = storeHash;
@@ -0,0 +1,2 @@
1
+ export { getBuildDirectory, getSourceDirectory } from './get-source-directory';
2
+ export * from './nodejs';
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getSourceDirectory = exports.getBuildDirectory = void 0;
18
+ var get_source_directory_1 = require("./get-source-directory");
19
+ Object.defineProperty(exports, "getBuildDirectory", { enumerable: true, get: function () { return get_source_directory_1.getBuildDirectory; } });
20
+ Object.defineProperty(exports, "getSourceDirectory", { enumerable: true, get: function () { return get_source_directory_1.getSourceDirectory; } });
21
+ __exportStar(require("./nodejs"), exports);
@@ -2,8 +2,8 @@
2
2
  * Builds ECMAScript files.
3
3
  * Copies the files from the source directory to the build directory and installs the necessary node modules.
4
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.
5
+ * @param files - The files to build.
6
+ * @param srcDir - The source directory.
7
+ * @param buildDir - The build directory.
8
8
  */
9
9
  export declare function buildEcmaScript(files: string[], srcDir: string, buildDir: string): void;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildEcmaScript = void 0;
3
+ exports.buildEcmaScript = buildEcmaScript;
4
4
  const copy_files_1 = require("../copy-files");
5
5
  const install_node_modules_1 = require("./install-node-modules");
6
6
  /**
7
7
  * Builds ECMAScript files.
8
8
  * Copies the files from the source directory to the build directory and installs the necessary node modules.
9
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.
10
+ * @param files - The files to build.
11
+ * @param srcDir - The source directory.
12
+ * @param buildDir - The build directory.
13
13
  */
14
14
  function buildEcmaScript(files, srcDir, buildDir) {
15
15
  // Copies the files from the source directory to the build directory
@@ -17,4 +17,3 @@ function buildEcmaScript(files, srcDir, buildDir) {
17
17
  // Installs the necessary node modules
18
18
  (0, install_node_modules_1.installNodeModules)(buildDir, ['dev', 'optional', 'peer']);
19
19
  }
20
- exports.buildEcmaScript = buildEcmaScript;
@@ -1,12 +1,18 @@
1
+ /**
2
+ * Additional Build options which can be used to customize the build process.
3
+ */
1
4
  export interface BuildOptions {
5
+ /**
6
+ * @prop subdirectory - optional subdirectory to build, useful for a-standard builds such as lambda-layers which nest the modules in a '/nodejs/' directory
7
+ */
2
8
  subdirectory?: string;
3
9
  }
4
10
  /**
5
11
  * Builds the source code for a Node.js project.
6
12
  * @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.
13
+ * @param type - The type of the source code.
14
+ * @param id - The ID of the source code.
15
+ * @param options - Options for building the source code.
10
16
  * @returns - The build directory containing the resulting source code
11
17
  */
12
18
  export declare function buildNodeSource(type: string, id: string, options?: BuildOptions): string;
@@ -1,23 +1,20 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildNodeSource = void 0;
3
+ exports.buildNodeSource = buildNodeSource;
7
4
  const fs_extra_1 = require("fs-extra");
8
5
  const get_source_directory_1 = require("../get-source-directory");
9
6
  const get_files_1 = require("../get-files");
10
7
  const generate_hash_1 = require("../generate-hash");
11
- const duration_1 = __importDefault(require("../../tools/duration"));
8
+ const tools_1 = require("../../tools");
12
9
  const build_ecmascript_1 = require("./build-ecmascript");
13
10
  const build_typescript_1 = require("./build-typescript");
14
11
  const hash_file_1 = require("../hash-file");
15
12
  /**
16
13
  * Builds the source code for a Node.js project.
17
14
  * @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.
15
+ * @param type - The type of the source code.
16
+ * @param id - The ID of the source code.
17
+ * @param options - Options for building the source code.
21
18
  * @returns - The build directory containing the resulting source code
22
19
  */
23
20
  function buildNodeSource(type, id, options) {
@@ -27,13 +24,15 @@ function buildNodeSource(type, id, options) {
27
24
  const hash = (0, generate_hash_1.generateHash)(files);
28
25
  if ((0, hash_file_1.getStoredHash)(type, id) === hash)
29
26
  return buildDir;
30
- const rmComplete = (0, duration_1.default)();
27
+ const rmComplete = (0, tools_1.duration)();
31
28
  if ((0, fs_extra_1.existsSync)(buildDir))
32
29
  (0, fs_extra_1.emptyDirSync)(buildDir);
33
30
  console.log('Cleanup Duration (ms)', rmComplete());
34
31
  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);
32
+ if (isTypeScript)
33
+ (0, build_typescript_1.buildTypeScript)(srcDir, buildDir);
34
+ else
35
+ (0, build_ecmascript_1.buildEcmaScript)(files, srcDir, buildDir);
36
36
  (0, hash_file_1.storeHash)(type, id, hash);
37
37
  return buildDir;
38
38
  }
39
- exports.buildNodeSource = buildNodeSource;
@@ -2,7 +2,7 @@
2
2
  * Builds TypeScript source code.
3
3
  * Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
4
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.
5
+ * @param srcDir - The source directory containing the TypeScript code.
6
+ * @param buildDir - The output directory for the compiled JavaScript code.
7
7
  */
8
- export declare function buildTypeScript(srcDir: string, buildDir: string): void;
8
+ export declare function buildTypeScript(srcDir: string, buildDir: string): string;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildTypeScript = void 0;
3
+ exports.buildTypeScript = buildTypeScript;
7
4
  const child_process_1 = require("child_process");
8
- const duration_1 = __importDefault(require("../../tools/duration"));
5
+ const tools_1 = require("../../tools");
9
6
  const fs_extra_1 = require("fs-extra");
10
7
  const install_node_modules_1 = require("./install-node-modules");
11
8
  const copy_files_1 = require("../copy-files");
@@ -14,8 +11,8 @@ const path_1 = require("path");
14
11
  * Builds TypeScript source code.
15
12
  * Ensures the build directory exists, installs necessary node modules, and compiles the TypeScript code.
16
13
  * @function buildTypeScript
17
- * @param {string} srcDir - The source directory containing the TypeScript code.
18
- * @param {string} buildDir - The output directory for the compiled JavaScript code.
14
+ * @param srcDir - The source directory containing the TypeScript code.
15
+ * @param buildDir - The output directory for the compiled JavaScript code.
19
16
  */
20
17
  function buildTypeScript(srcDir, buildDir) {
21
18
  // Ensure the build directory exists
@@ -23,9 +20,9 @@ function buildTypeScript(srcDir, buildDir) {
23
20
  // Install necessary node modules
24
21
  (0, install_node_modules_1.installNodeModules)(srcDir);
25
22
  // Measure the duration of the build process
26
- const done = (0, duration_1.default)();
23
+ const done = (0, tools_1.duration)();
27
24
  // Compile the TypeScript code
28
- (0, child_process_1.execSync)(`npm run build -- --outDir ${buildDir}`, {
25
+ (0, child_process_1.spawnSync)('npm', ['run', 'build', '--', '--outDir', buildDir], {
29
26
  cwd: srcDir,
30
27
  stdio: 'inherit'
31
28
  });
@@ -37,5 +34,5 @@ function buildTypeScript(srcDir, buildDir) {
37
34
  (0, install_node_modules_1.installNodeModules)(buildDir, ['dev', 'optional', 'peer']);
38
35
  // Log the duration of the build process
39
36
  console.log('NPM Install Duration (ms)', done());
37
+ return buildDir;
40
38
  }
41
- exports.buildTypeScript = buildTypeScript;
@@ -0,0 +1 @@
1
+ export { buildNodeSource } from './build-node-source';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodeSource = void 0;
4
+ var build_node_source_1 = require("./build-node-source");
5
+ Object.defineProperty(exports, "buildNodeSource", { enumerable: true, get: function () { return build_node_source_1.buildNodeSource; } });
@@ -1,3 +1,4 @@
1
+ export type OmitType = 'dev' | 'optional' | 'peer' | string;
1
2
  /**
2
3
  * Installs node modules in a specified directory.
3
4
  *
@@ -6,7 +7,7 @@
6
7
  * It also measures and logs the duration of the `npm install` command.
7
8
  *
8
9
  * @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'.
10
+ * @param dir - The directory in which to run `npm install`.
11
+ * @param omit - The types of dependencies to omit. Possible values are 'dev', 'optional', and 'peer'.
11
12
  */
12
- export declare function installNodeModules(dir: string, omit?: string[]): void;
13
+ export declare function installNodeModules(dir: string, omit?: OmitType[]): void;