Skip to content

Commit

Permalink
chore(cli): show git commit with --version if tact comes from dev…
Browse files Browse the repository at this point in the history
… repo
  • Loading branch information
anton-trunov committed Jul 11, 2024
1 parent 99c3063 commit 3342eb0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/tact.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const pkg = require("../package.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const main = require("../dist/node.js");
const meowModule = import("meow");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execFileSync } = require("child_process");

void meowModule.then(
/** @param meow {import('meow/build/index')} */
Expand Down Expand Up @@ -36,6 +38,7 @@ void meowModule.then(
url: new URL("file://" + __dirname + __filename).toString(),
},
description: `Command-line utility for the Tact compiler:\n${pkg.description}`,
autoVersion: false,
flags: {
config: {
shortFlag: "c",
Expand Down Expand Up @@ -83,7 +86,18 @@ void meowModule.then(

// Show version regardless of other flags
if (cli.flags.version) {
cli.showVersion();
console.log(pkg.version);
// if working inside a git repository
// also print the current git commit hash
try {
const gitCommit = execFileSync("git", ["rev-parse", "HEAD"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
console.log(`git commit: ${gitCommit}`);
} finally {
process.exit(0);
}
}

// Evaluate expression regardless of other flags
Expand Down

0 comments on commit 3342eb0

Please sign in to comment.