From 4efbaaffdc340706fb0f2320748b7ba4c9d8db4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Boug=C3=A8re?= Date: Tue, 6 Jun 2023 19:55:06 +0200 Subject: [PATCH] feat: adding a --version command --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + README.md | 1 + bin/asl-validator.ts | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 3b6ba93..9637486 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -27,6 +27,7 @@ Please provide a complete state machine definition: A clear and concise description of what you expected to happen. **Version:** +Can be found by running `asl-validator --version`. **Additional context** Add any other context about the problem here. diff --git a/README.md b/README.md index 6b9eba2..3ac56ec 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Usage: asl-validator [options] Amazon States Language validator Options: + -V, --version output the version number --json-definition JSON definition (default: []) --json-path JSON path (default: []) --yaml-definition YAML definition (default: []) diff --git a/bin/asl-validator.ts b/bin/asl-validator.ts index 8224fca..501bbde 100755 --- a/bin/asl-validator.ts +++ b/bin/asl-validator.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import fs from "fs"; +import path from "path"; import { program } from "commander"; import YAML from "yaml"; @@ -21,8 +22,26 @@ function collect(value: string, previous: string[]) { return previous.concat([value]); } +function getVersion(packageJsonPath: string): string | null { + if (!fs.existsSync(packageJsonPath)) { + return null; + } + const { version } = JSON.parse( + fs.readFileSync(packageJsonPath).toString() + ) as { + version: string; + }; + return version; +} + program .description("Amazon States Language validator") + // make it work wether it is compiled or not + .version( + getVersion(path.join(__dirname, "../package.json")) ?? + getVersion(path.join(__dirname, "../../package.json")) ?? + "" + ) .option("--json-definition ", "JSON definition", collect, []) .option("--json-path ", "JSON path", collect, []) .option("--yaml-definition ", "YAML definition", collect, [])