From a33f5a6875836bf51316680dc2a192f71918f944 Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Tue, 4 Jun 2024 10:16:04 -0500 Subject: [PATCH] feature: add version command to CLI (#61) * add version command * update pnpm version --- .github/workflows/tests.yaml | 6 +++--- tooling/cli/src/_main.ts | 4 +++- tooling/cli/src/commands/version.ts | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tooling/cli/src/commands/version.ts diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4c057e03..fc601496 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -19,7 +19,7 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v2 with: - version: 9.1.3 + version: 9.1.4 - name: Install Node.js uses: actions/setup-node@v3 with: @@ -50,7 +50,7 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v2 with: - version: 9.1.3 + version: 9.1.4 - name: Install Node.js uses: actions/setup-node@v3 with: @@ -81,7 +81,7 @@ jobs: - name: Setup pnpm uses: pnpm/action-setup@v2 with: - version: 9.1.3 + version: 9.1.4 - name: Install Node.js uses: actions/setup-node@v3 with: diff --git a/tooling/cli/src/_main.ts b/tooling/cli/src/_main.ts index e7573c2f..87612ab5 100644 --- a/tooling/cli/src/_main.ts +++ b/tooling/cli/src/_main.ts @@ -5,13 +5,15 @@ import build from "./commands/build"; import codegen from "./commands/codegen"; import dev from "./commands/dev"; import init from "./commands/init"; +import version from "./commands/version"; const main = defineCommand({ subCommands: { build, - dev, codegen, + dev, init, + version, }, }); diff --git a/tooling/cli/src/commands/version.ts b/tooling/cli/src/commands/version.ts new file mode 100644 index 00000000..795beee5 --- /dev/null +++ b/tooling/cli/src/commands/version.ts @@ -0,0 +1,25 @@ +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; + +import { defineCommand } from "citty"; +import path from "pathe"; + +const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file +const __dirname = path.dirname(__filename); // get the name of the directory + +const version = defineCommand({ + meta: { + name: "Version", + description: "Get the current Arri CLI version", + }, + run() { + const packageJson = JSON.parse( + readFileSync(path.resolve(__dirname, "../package.json"), { + encoding: "utf8", + }), + ); + console.info(`${packageJson.version}`); + }, +}); + +export default version;