Skip to content

Commit 4efbaaf

Browse files
feat: adding a --version command
1 parent 5372e3a commit 4efbaaf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Please provide a complete state machine definition:
2727
A clear and concise description of what you expected to happen.
2828

2929
**Version:**
30+
Can be found by running `asl-validator --version`.
3031

3132
**Additional context**
3233
Add any other context about the problem here.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Usage: asl-validator [options]
2727
Amazon States Language validator
2828

2929
Options:
30+
-V, --version output the version number
3031
--json-definition <jsonDefinition> JSON definition (default: [])
3132
--json-path <jsonPath> JSON path (default: [])
3233
--yaml-definition <yamlDefinition> YAML definition (default: [])

bin/asl-validator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import fs from "fs";
4+
import path from "path";
45
import { program } from "commander";
56
import YAML from "yaml";
67

@@ -21,8 +22,26 @@ function collect(value: string, previous: string[]) {
2122
return previous.concat([value]);
2223
}
2324

25+
function getVersion(packageJsonPath: string): string | null {
26+
if (!fs.existsSync(packageJsonPath)) {
27+
return null;
28+
}
29+
const { version } = JSON.parse(
30+
fs.readFileSync(packageJsonPath).toString()
31+
) as {
32+
version: string;
33+
};
34+
return version;
35+
}
36+
2437
program
2538
.description("Amazon States Language validator")
39+
// make it work wether it is compiled or not
40+
.version(
41+
getVersion(path.join(__dirname, "../package.json")) ??
42+
getVersion(path.join(__dirname, "../../package.json")) ??
43+
""
44+
)
2645
.option("--json-definition <jsonDefinition>", "JSON definition", collect, [])
2746
.option("--json-path <jsonPath>", "JSON path", collect, [])
2847
.option("--yaml-definition <yamlDefinition>", "YAML definition", collect, [])

0 commit comments

Comments
 (0)