From 526f717afd1627ed5056e31b5a6d9477a7f974d0 Mon Sep 17 00:00:00 2001 From: Akash Askoolum Date: Fri, 13 Aug 2021 08:36:02 +0100 Subject: [PATCH 1/2] chore: Reduce noise when invoking CLI in DEV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove node/ts-node output when invoking the CLI locally. This makes it easier to pipe the response through `jq` and other tools. Before: ```console ➜ ./script/cli > @guardian/cdk@23.3.0 cli:dev /Users/akash_askoolum/code/cdk > ts-node src/bin/index.ts index.ts COMMAND [args] Commands: index.ts aws-cdk-version Print the version of @aws-cdk libraries being used index.ts account-readiness Perform checks on an AWS account to see if it is GuCDK ready index.ts check-package-json Check a package.json file for compatibility with GuCDK Options: --profile AWS profile [string] --region AWS region [string] [default: "eu-west-1"] --version Show version number [boolean] -h, --help Show help [boolean] ``` After: ```console ➜ ./script/cli index.ts COMMAND [args] Commands: index.ts aws-cdk-version Print the version of @aws-cdk libraries being used index.ts account-readiness Perform checks on an AWS account to see if it is GuCDK ready index.ts check-package-json Check a package.json file for compatibility with GuCDK Options: --profile AWS profile [string] --region AWS region [string] [default: "eu-west-1"] --version Show version number [boolean] -h, --help Show help [boolean] ``` --- script/cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/cli b/script/cli index d511545608..cc09ae27b8 100755 --- a/script/cli +++ b/script/cli @@ -10,4 +10,4 @@ if [[ $# -gt 0 ]] ; then fi # shellcheck disable=SC2086 -npm run cli:dev $EXTRA_ARGS +npm run --silent cli:dev $EXTRA_ARGS From 45c67564c4f655de52925d7dc36f1478e6f50036 Mon Sep 17 00:00:00 2001 From: Akash Askoolum Date: Fri, 13 Aug 2021 08:52:44 +0100 Subject: [PATCH 2/2] feat: Add the GuCDK version to the CLI JSON response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is useful to know what version of the CLI you're using when running commands. Let's say you're working on a CDK project using v22.3.0 of GuCDK. You'll be using AWS CDK libraries of v1.110.1. However if you run `npx @guardian/cdk aws-cdk-version` the CLI will suggest using v1.115.0 of the AWS CDK libraries. This is because you're invoking the latest version of the CLI, rather than version for v22.3.0. Printing the version of GuCDK in the CLI response should hopefully make this process easier. Before: ```console ➜ ./script/cli aws-cdk-version | jq . { "dependencies": { "@aws-cdk/assert": "1.115.0", "@aws-cdk/aws-apigateway": "1.115.0", "@aws-cdk/aws-autoscaling": "1.115.0", "@aws-cdk/aws-cloudwatch-actions": "1.115.0", "@aws-cdk/aws-ec2": "1.115.0", "@aws-cdk/aws-elasticloadbalancing": "1.115.0", "@aws-cdk/aws-elasticloadbalancingv2": "1.115.0", "@aws-cdk/aws-events-targets": "1.115.0", "@aws-cdk/aws-iam": "1.115.0", "@aws-cdk/aws-kinesis": "1.115.0", "@aws-cdk/aws-lambda": "1.115.0", "@aws-cdk/aws-lambda-event-sources": "1.115.0", "@aws-cdk/aws-rds": "1.115.0", "@aws-cdk/aws-s3": "1.115.0", "@aws-cdk/core": "1.115.0" }, "devDependencies": {} } ``` After: ```console ➜ ./script/cli aws-cdk-version | jq . { "@guardian/cdk": { "version": "23.3.0" }, "dependencies": { "@aws-cdk/assert": "1.115.0", "@aws-cdk/aws-apigateway": "1.115.0", "@aws-cdk/aws-autoscaling": "1.115.0", "@aws-cdk/aws-cloudwatch-actions": "1.115.0", "@aws-cdk/aws-ec2": "1.115.0", "@aws-cdk/aws-elasticloadbalancing": "1.115.0", "@aws-cdk/aws-elasticloadbalancingv2": "1.115.0", "@aws-cdk/aws-events-targets": "1.115.0", "@aws-cdk/aws-iam": "1.115.0", "@aws-cdk/aws-kinesis": "1.115.0", "@aws-cdk/aws-lambda": "1.115.0", "@aws-cdk/aws-lambda-event-sources": "1.115.0", "@aws-cdk/aws-rds": "1.115.0", "@aws-cdk/aws-s3": "1.115.0", "@aws-cdk/core": "1.115.0" }, "devDependencies": {} } ``` --- src/bin/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/index.ts b/src/bin/index.ts index 66e71fc423..52733a31f3 100755 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -66,7 +66,8 @@ parseCommandLineArguments() } else if (typeof commandResponse === "string") { console.log(commandResponse); } else { - console.log(JSON.stringify(commandResponse)); + const responseWithVersionInfo = { "@guardian/cdk": { version: LibraryInfo.VERSION }, ...commandResponse }; + console.log(JSON.stringify(responseWithVersionInfo)); } }) .catch((err) => {