Skip to content

Commit 9bb1718

Browse files
authored
Print cdklocal version and cdk version if possible (#112)
1 parent 87330ae commit 9bb1718

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ $ awslocal sns list-topics
8888

8989
## Change Log
9090

91+
* 3.0.1: Using the `-v`/`--version` flag prints the cdklocal version and the version of the underlying `aws-cdk` package (if possible)
9192
* 3.0.0: Sanitise environment of configuration environment variables before deployment
9293
* 2.19.2: Fix SDK compatibility with aws-cdk versions >= 2.177.0
9394
* 2.19.1: Fix SDK compatibility with older CDK versions; Fix patched bucket location in TemplateURL

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)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aws-cdk-local",
33
"description": "CDK Toolkit for use with LocalStack",
4-
"version": "3.0.0",
4+
"version": "3.0.1",
55
"main": "src/index.js",
66
"bin": {
77
"cdklocal": "bin/cdklocal"

0 commit comments

Comments
 (0)