Skip to content

Commit 456cb90

Browse files
committed
Implement printing cdklocal version as well as cdk version
1 parent 87330ae commit 456cb90

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bin/cdklocal

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const https = require("https");
99
const crypto = require("crypto");
1010
const net = require('net');
1111

12-
const { isEnvTrue, EDGE_PORT, PROTOCOL, configureEnvironment } = require("../src");
12+
const { isEnvTrue, EDGE_PORT, PROTOCOL, configureEnvironment } = require(path.resolve(__dirname, "..", "src"));
13+
const pkg = require(path.resolve(__dirname, "..", "package.json"));
1314

1415
// constants and custom config values
1516

@@ -22,6 +23,17 @@ const AWS_ENVAR_ALLOWLIST = process.env.AWS_ENVAR_ALLOWLIST || "";
2223
// UTIL FUNCTIONS
2324
//----------------
2425

26+
function printVersion() {
27+
try {
28+
const lib = require("aws-cdk/lib");
29+
const cdkVersion = require(path.join(lib.rootDir(), 'package.json')).version.replace(/\+[0-9a-f]+$/, '');
30+
console.log(`cdklocal v${pkg.version}`);
31+
console.log(`cdk cli version v${cdkVersion}`);
32+
} catch (e) {
33+
console.log(`cdklocal v${pkg.version}`);
34+
}
35+
}
36+
2537
const getLocalEndpoint = async () => process.env.AWS_ENDPOINT_URL || `${PROTOCOL}://${await getLocalHost()}`;
2638

2739
var resolvedHostname = undefined;
@@ -484,6 +496,12 @@ const patchPost_2_14 = () => {
484496
}
485497
};
486498

499+
// handle printing version information
500+
if (process.argv[2] === "--version" || process.argv[2] === "-v") {
501+
printVersion();
502+
process.exit(0);
503+
}
504+
487505
if (isEsbuildBundle()) {
488506
// load for CDK version 2.14.0 and above
489507
// (v2.14.0+ uses a self-contained bundle, see https://github.com/aws/aws-cdk/pull/18667)

0 commit comments

Comments
 (0)