MCPcopy Create free account
hub / github.com/cortexkit/magic-context / getVersion

Function getVersion

packages/cli/src/index.ts:21–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19import { createRequire } from "node:module";
20
21function getVersion(): string {
22 const req = createRequire(import.meta.url);
23 // In source layout (src/index.ts) package.json is two levels up.
24 // In published layout (dist/index.js) it's one level up. Try both so
25 // `--version` works regardless of how the binary was launched.
26 for (const relPath of ["../../package.json", "../package.json"]) {
27 try {
28 const pkg = req(relPath) as { version?: unknown };
29 if (typeof pkg.version === "string" && pkg.version.length > 0) {
30 return pkg.version;
31 }
32 } catch {
33 // try next layout
34 }
35 }
36 return "0.0.0";
37}
38
39function valueAfter(args: string[], flag: string): string | null {
40 const index = args.indexOf(flag);

Callers 1

mainFunction · 0.85

Calls 1

reqFunction · 0.85

Tested by

no test coverage detected