@byaga/cdk-patterns 0.9.2 → 0.10.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/.fleet/run.json +11 -0
- package/LICENSE.md +21 -0
- package/README.md +37 -0
- package/lib/DeployStack.d.ts +3 -7
- package/lib/DeployStack.js +7 -8
- package/lib/NodeJsLambda.d.ts +22 -0
- package/lib/NodeJsLambda.js +18 -2
- package/lib/NodeJsLambdaLayer.d.ts +13 -0
- package/lib/NodeJsLambdaLayer.js +13 -2
- package/lib/StaticWebSite.d.ts +20 -4
- package/lib/StaticWebSite.js +29 -15
- package/lib/methods/BuildOptions.d.ts +3 -0
- package/lib/methods/BuildOptions.js +2 -0
- package/lib/methods/apply-honeycomb-to-lambda.js +1 -1
- package/lib/methods/build-ecmascript.d.ts +9 -0
- package/lib/methods/build-ecmascript.js +20 -0
- package/lib/methods/build-node-source.d.ts +10 -13
- package/lib/methods/build-node-source.js +30 -96
- package/lib/methods/build-typescript.d.ts +8 -0
- package/lib/methods/build-typescript.js +33 -0
- package/lib/methods/copy-files.d.ts +8 -0
- package/lib/methods/{empty-directory.js → copy-files.js} +21 -14
- package/lib/methods/duration.d.ts +8 -6
- package/lib/methods/duration.js +17 -11
- package/lib/methods/generate-hash.d.ts +7 -15
- package/lib/methods/generate-hash.js +25 -53
- package/lib/methods/get-files.d.ts +9 -0
- package/lib/methods/get-files.js +38 -0
- package/lib/methods/get-source-directory.d.ts +16 -2
- package/lib/methods/get-source-directory.js +31 -30
- package/lib/methods/hash-file.d.ts +18 -0
- package/lib/methods/hash-file.js +45 -0
- package/lib/methods/install-node-modules.d.ts +12 -0
- package/lib/methods/install-node-modules.js +30 -0
- package/package.json +30 -10
- package/tsconfig.json +1 -1
- package/lib/IDeployStack.d.ts +0 -20
- package/lib/IDeployStack.js +0 -48
- package/lib/methods/empty-directory.d.ts +0 -2
- package/lib/methods/walk-directory.d.ts +0 -14
- package/lib/methods/walk-directory.js +0 -48
@@ -26,21 +26,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.copyFiles = void 0;
|
30
|
+
const path = __importStar(require("path"));
|
29
31
|
const fse = __importStar(require("fs-extra"));
|
30
32
|
const duration_1 = __importDefault(require("./duration"));
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
/**
|
34
|
+
* 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.
|
39
|
+
*/
|
40
|
+
function copyFiles(files, srcDir, buildDir) {
|
41
|
+
// Measure the duration of the copy process
|
42
|
+
const copyComplete = (0, duration_1.default)();
|
43
|
+
// For each file, calculate the relative path from the source directory,
|
44
|
+
// resolve the target path in the build directory, and copy the file
|
45
|
+
files.forEach((filePath) => {
|
46
|
+
const relativePath = path.relative(srcDir, filePath);
|
47
|
+
const targetPath = path.resolve(buildDir, relativePath);
|
48
|
+
fse.copySync(filePath, targetPath);
|
43
49
|
});
|
44
|
-
|
50
|
+
// Log the duration of the copy process
|
51
|
+
console.log('Copy Duration (ms)', copyComplete());
|
45
52
|
}
|
46
|
-
exports.
|
53
|
+
exports.copyFiles = copyFiles;
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* Creates a function that, when called, returns the elapsed time in milliseconds since the function was created.
|
3
|
+
* @function hrDuration
|
4
|
+
* @returns {function} - A function that returns the elapsed time in milliseconds.
|
5
|
+
*/
|
6
|
+
export declare const hrDuration: () => {
|
2
7
|
(): number;
|
3
8
|
time: [number, number];
|
4
|
-
}
|
5
|
-
|
6
|
-
time: number;
|
7
|
-
});
|
8
|
-
export default duration;
|
9
|
+
};
|
10
|
+
export default hrDuration;
|
package/lib/methods/duration.js
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.hrDuration = void 0;
|
4
|
+
/**
|
5
|
+
* Creates a function that, when called, returns the elapsed time in milliseconds since the function was created.
|
6
|
+
* @function hrDuration
|
7
|
+
* @returns {function} - A function that returns the elapsed time in milliseconds.
|
8
|
+
*/
|
3
9
|
const hrDuration = () => {
|
10
|
+
// The high-resolution real time at which the function was created
|
4
11
|
const startTime = process.hrtime();
|
12
|
+
/**
|
13
|
+
* Returns the elapsed time in milliseconds since the function was created.
|
14
|
+
* @function duration
|
15
|
+
* @returns {number} - The elapsed time in milliseconds.
|
16
|
+
*/
|
5
17
|
const onEnd = function duration() {
|
18
|
+
// The high-resolution real time at which the function was called
|
6
19
|
const hrTime = process.hrtime(startTime);
|
20
|
+
// Calculate and return the elapsed time in milliseconds
|
7
21
|
return hrTime[0] * 1000 + hrTime[1] / 1000000;
|
8
22
|
};
|
23
|
+
// Attach the start time to the function for reference
|
9
24
|
onEnd.time = startTime;
|
10
25
|
return onEnd;
|
11
26
|
};
|
12
|
-
|
13
|
-
|
14
|
-
const onEnd = function duration() {
|
15
|
-
return Date.now() - startTime;
|
16
|
-
};
|
17
|
-
onEnd.time = startTime;
|
18
|
-
return onEnd;
|
19
|
-
};
|
20
|
-
// @ts-ignore
|
21
|
-
const duration = process.hrtime ? hrDuration : msDuration;
|
22
|
-
exports.default = duration;
|
27
|
+
exports.hrDuration = hrDuration;
|
28
|
+
exports.default = exports.hrDuration;
|
@@ -1,15 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
9
|
-
export interface HashItem {
|
10
|
-
hash: string;
|
11
|
-
path: string;
|
12
|
-
name: string;
|
13
|
-
}
|
14
|
-
export declare function generateHash(folder: string, opt: HashOptions): string;
|
15
|
-
export {};
|
1
|
+
/**
|
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.
|
6
|
+
*/
|
7
|
+
export declare function generateHash(filePaths: string[]): string;
|
@@ -1,59 +1,31 @@
|
|
1
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
-
};
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
3
|
exports.generateHash = void 0;
|
30
|
-
const
|
31
|
-
const
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
const
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
hash: fileHash.digest(ENCODING)
|
50
|
-
};
|
51
|
-
hash.update(file.hash);
|
52
|
-
return file;
|
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');
|
53
23
|
});
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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');
|
58
30
|
}
|
59
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;
|
@@ -1,4 +1,18 @@
|
|
1
1
|
export declare const sourceRoot: string;
|
2
2
|
export declare const distributionRoot: string;
|
3
|
-
|
4
|
-
|
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;
|
@@ -1,37 +1,38 @@
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
3
|
exports.getBuildDirectory = exports.getSourceDirectory = exports.distributionRoot = exports.sourceRoot = void 0;
|
27
|
-
const
|
28
|
-
|
29
|
-
exports.
|
30
|
-
|
31
|
-
|
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);
|
32
18
|
}
|
33
19
|
exports.getSourceDirectory = getSourceDirectory;
|
34
|
-
|
35
|
-
|
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);
|
36
29
|
}
|
37
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,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("./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;
|
package/package.json
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@byaga/cdk-patterns",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.10.0",
|
4
4
|
"description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
|
5
|
-
"main": "lib/index.js",
|
6
|
-
"types": "lib/index.d.ts",
|
5
|
+
"main": "./lib/index.js",
|
6
|
+
"types": "./lib/index.d.ts",
|
7
7
|
"scripts": {
|
8
|
-
"
|
8
|
+
"clean": "rimraf ./lib",
|
9
|
+
"build": "npm run clean && tsc",
|
10
|
+
"lint": "eslint . --ext .ts",
|
11
|
+
"test": "jest ./src",
|
12
|
+
"preversion": "npm run lint && npm test && npm run build"
|
9
13
|
},
|
10
14
|
"keywords": [
|
11
15
|
"CDK",
|
@@ -15,14 +19,30 @@
|
|
15
19
|
"author": "VeryFineHat",
|
16
20
|
"license": "MIT",
|
17
21
|
"dependencies": {
|
18
|
-
"
|
19
|
-
"aws-cdk": "^2.
|
20
|
-
"aws-cdk-lib": "^2.103.1",
|
22
|
+
"aws-cdk": "^2.122.0",
|
23
|
+
"aws-cdk-lib": "^2.122.0",
|
21
24
|
"constructs": "^10.3.0",
|
22
|
-
"fs-extra": "^11.
|
25
|
+
"fs-extra": "^11.2.0",
|
26
|
+
"glob": "^10.3.10",
|
27
|
+
"ignore": "^5.3.0"
|
23
28
|
},
|
24
29
|
"devDependencies": {
|
25
|
-
"@types/
|
26
|
-
"
|
30
|
+
"@types/fs-extra": "^11.0.4",
|
31
|
+
"@types/glob": "^8.1.0",
|
32
|
+
"@types/jest": "^29.5.11",
|
33
|
+
"@types/node": "^20.11.5",
|
34
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
35
|
+
"@typescript-eslint/parser": "^6.19.0",
|
36
|
+
"eslint": "^8.56.0",
|
37
|
+
"jest": "^29.7.0",
|
38
|
+
"jest-html-reporters": "^3.1.7",
|
39
|
+
"jest-junit": "^16.0.0",
|
40
|
+
"ts-jest": "^29.1.1",
|
41
|
+
"ts-mockito": "^2.6.1",
|
42
|
+
"typescript": "^5.3.3"
|
43
|
+
},
|
44
|
+
"repository": {
|
45
|
+
"type": "git",
|
46
|
+
"url": "https://github.com/veryfine-hat/byaga-cdk-patterns"
|
27
47
|
}
|
28
48
|
}
|
package/tsconfig.json
CHANGED
package/lib/IDeployStack.d.ts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Stack } from 'aws-cdk-lib';
|
2
|
-
import IStackArguments from './IStackArguments';
|
3
|
-
import { IConstruct } from "constructs";
|
4
|
-
export declare class IDeployStack extends Stack {
|
5
|
-
registry: {
|
6
|
-
[t: string]: {
|
7
|
-
[n: string]: any;
|
8
|
-
};
|
9
|
-
};
|
10
|
-
stage: string;
|
11
|
-
name: string;
|
12
|
-
genName(...name: string[]): string;
|
13
|
-
genId(...name: string[]): string;
|
14
|
-
static genStackResourceName(stackName: string, resource: string, stage?: string): string;
|
15
|
-
static genStackResourceId(stackName: string, resource: string, stage?: string): string;
|
16
|
-
constructor(scope: IConstruct, props: IStackArguments);
|
17
|
-
get(type: string, name: string): any;
|
18
|
-
set(type: string, name: string, instance: any): any;
|
19
|
-
}
|
20
|
-
export default IDeployStack;
|
package/lib/IDeployStack.js
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.IDeployStack = void 0;
|
4
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
-
class IDeployStack extends aws_cdk_lib_1.Stack {
|
6
|
-
registry = {};
|
7
|
-
stage;
|
8
|
-
name;
|
9
|
-
genName(...name) {
|
10
|
-
return IDeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'));
|
11
|
-
}
|
12
|
-
genId(...name) {
|
13
|
-
return IDeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'));
|
14
|
-
}
|
15
|
-
static genStackResourceName(stackName, resource, stage = 'develop') {
|
16
|
-
let name = stackName[0].toLowerCase() + stackName.substr(1);
|
17
|
-
name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
|
18
|
-
return `${name}-${resource}-${stage}`.toLowerCase();
|
19
|
-
}
|
20
|
-
static genStackResourceId(stackName, resource, stage = 'develop') {
|
21
|
-
const constructName = `${stackName}-${resource}-${stage}`;
|
22
|
-
return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase());
|
23
|
-
}
|
24
|
-
constructor(scope, props) {
|
25
|
-
const options = (props || {});
|
26
|
-
const { stage = 'develop' } = options;
|
27
|
-
super(scope, props.stackName + '-' + stage, {
|
28
|
-
...props,
|
29
|
-
stackName: props.stackName + '-' + stage
|
30
|
-
});
|
31
|
-
const stack = this;
|
32
|
-
stack.name = props.stackName || '';
|
33
|
-
stack.stage = stage;
|
34
|
-
stack.tags.setTag('Stage', stage);
|
35
|
-
stack.tags.setTag('Stack', this.genName('ui-stack'));
|
36
|
-
}
|
37
|
-
get(type, name) {
|
38
|
-
const items = this.registry[type];
|
39
|
-
return (items && items[name]) || null;
|
40
|
-
}
|
41
|
-
set(type, name, instance) {
|
42
|
-
this.registry[type] = this.registry[type] || {};
|
43
|
-
this.registry[type][name] = instance;
|
44
|
-
return instance;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
exports.IDeployStack = IDeployStack;
|
48
|
-
exports.default = IDeployStack;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import * as fs from 'fs';
|
3
|
-
export interface IIgnoreOptions {
|
4
|
-
excluded?: (stat: fs.Dirent) => boolean;
|
5
|
-
included?: (stat: fs.Dirent) => boolean;
|
6
|
-
childrenExcluded?: (stat: fs.Dirent) => boolean;
|
7
|
-
childrenIncluded?: (stat: fs.Dirent) => boolean;
|
8
|
-
}
|
9
|
-
export declare const yes: () => boolean;
|
10
|
-
export declare const no: () => boolean;
|
11
|
-
export default function walkDirectory(directory: string, options: IIgnoreOptions, filepaths?: DirentExtended[]): DirentExtended[];
|
12
|
-
export interface DirentExtended extends fs.Dirent {
|
13
|
-
fullpath: () => string;
|
14
|
-
}
|