Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ Zero dependencies. JSON output by default. Pipeable. Works with CapCut and JianY
```bash
npm install -g capcut-cli
```
Verify the installation:

```bash
capcut --version # prints the installed CLI version
```
Or run directly:
```bash
npx capcut-cli info ./my-project/
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Usage: capcut <command> <project> [options]

Global flags:
-H, --human Human-readable table output (default: JSON)
-v, --version Print the installed CLI version
-q, --quiet No output on success, exit code only (write commands)
--jianying Use JianYing enum namespace (default: CapCut) for
transition, mask, text-anim, image-anim, add-effect, enums
Expand Down Expand Up @@ -452,6 +453,7 @@ interface Flags {
// serve
queue?: string;
failFast?: boolean;
version?: boolean;
}

// Map CLI enum flags -> enums.json category key. Order matters for HELP text.
Expand All @@ -477,6 +479,7 @@ function parseFlags(args: string[]): { positional: string[]; flags: Flags } {
for (let i = 0; i < args.length; i++) {
const a = args[i];
if (a === "-H" || a === "--human") flags.human = true;
else if (a === "-v" || a === "--version") flags.version = true;
else if (a === "-q" || a === "--quiet") flags.quiet = true;
else if (a === "--batch") flags.batch = true;
else if ((a === "--track" || a === "--type") && i + 1 < args.length) {
Expand Down Expand Up @@ -1924,6 +1927,12 @@ function cmdDoctor(flags: Flags): boolean {
return report.ok;
}

function getCliVersion(): string {
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));

return pkg.version;
}

// --- Main ---

async function main(): Promise<void> {
Expand All @@ -1934,6 +1943,11 @@ async function main(): Promise<void> {
}

const { positional, flags } = parseFlags(raw);

if (flags.version) {
console.log(getCliVersion());
process.exit(0);
}
const cmd = positional[0];
const projectPath = positional[1];

Expand Down
25 changes: 25 additions & 0 deletions test/cli-version.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { describe, it } from "node:test";
import { fileURLToPath } from "node:url";
import { spawnCli } from "./helpers/spawn-cli.mjs";

const repoRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
const pkg = JSON.parse(readFileSync(join(repoRoot, "package.json"), "utf8"));

describe("capcut --version", () => {
it("prints package version with --version", () => {
const r = spawnCli(["--version"]);

assert.equal(r.status, 0);
assert.equal(r.stdout.trim(), pkg.version);
});

it("prints package version with -v", () => {
const r = spawnCli(["-v"]);

assert.equal(r.status, 0);
assert.equal(r.stdout.trim(), pkg.version);
});
});
Loading