cc-token-usage 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +38 -14
- package/package.json +7 -10
- package/bin/install.mjs +0 -53
package/bin/cli.mjs
CHANGED
|
@@ -1,35 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
4
|
+
import { existsSync, mkdirSync, accessSync, chmodSync, constants } from "fs";
|
|
5
5
|
import { join, dirname } from "path";
|
|
6
|
-
import {
|
|
7
|
-
import { tmpdir,
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { tmpdir, platform, arch, homedir } from "os";
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
10
|
|
|
11
|
-
// ───
|
|
11
|
+
// ─── Resolve platform binary (Biome bin pattern) ────────────────────────────
|
|
12
|
+
|
|
13
|
+
const PLATFORMS = {
|
|
14
|
+
"darwin-arm64": "cc-token-usage-darwin-arm64",
|
|
15
|
+
"darwin-x64": "cc-token-usage-darwin-x64",
|
|
16
|
+
"linux-x64": "cc-token-usage-linux-x64",
|
|
17
|
+
"linux-arm64": "cc-token-usage-linux-arm64",
|
|
18
|
+
};
|
|
12
19
|
|
|
13
20
|
function findBinary() {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
21
|
+
const key = `${platform()}-${arch()}`;
|
|
22
|
+
const pkg = PLATFORMS[key];
|
|
23
|
+
|
|
24
|
+
// 1. Resolve from platform-specific optionalDependency
|
|
25
|
+
if (pkg) {
|
|
26
|
+
try {
|
|
27
|
+
const pkgDir = dirname(require.resolve(`${pkg}/package.json`));
|
|
28
|
+
const bin = join(pkgDir, "bin", "cc-token-usage");
|
|
29
|
+
if (existsSync(bin)) {
|
|
30
|
+
// Self-healing: ensure binary is executable
|
|
31
|
+
try {
|
|
32
|
+
accessSync(bin, constants.X_OK);
|
|
33
|
+
} catch {
|
|
34
|
+
try { chmodSync(bin, 0o755); } catch {}
|
|
35
|
+
}
|
|
36
|
+
return bin;
|
|
37
|
+
}
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
17
40
|
|
|
18
|
-
// 2.
|
|
41
|
+
// 2. Fallback: check PATH
|
|
19
42
|
try {
|
|
20
43
|
const which = platform() === "win32" ? "where" : "which";
|
|
21
|
-
const result =
|
|
44
|
+
const result = execFileSync(which, ["cc-token-usage"], {
|
|
22
45
|
encoding: "utf-8",
|
|
23
46
|
}).trim();
|
|
24
47
|
if (result) return result;
|
|
25
48
|
} catch {}
|
|
26
49
|
|
|
27
|
-
// 3.
|
|
50
|
+
// 3. Fallback: check cargo bin
|
|
28
51
|
const cargoBin = join(homedir(), ".cargo", "bin", "cc-token-usage");
|
|
29
52
|
if (existsSync(cargoBin)) return cargoBin;
|
|
30
53
|
|
|
31
54
|
console.error("Error: cc-token-usage binary not found.");
|
|
32
|
-
console.error(
|
|
55
|
+
console.error(`Unsupported platform: ${platform()}-${arch()}`);
|
|
56
|
+
console.error("Install via cargo: cargo install cc-token-usage");
|
|
33
57
|
process.exit(1);
|
|
34
58
|
}
|
|
35
59
|
|
|
@@ -88,7 +112,7 @@ if (htmlResult.status === 0) {
|
|
|
88
112
|
: "xdg-open";
|
|
89
113
|
|
|
90
114
|
try {
|
|
91
|
-
|
|
115
|
+
execFileSync(openCmd, [htmlFile], { stdio: "ignore" });
|
|
92
116
|
} catch {
|
|
93
117
|
// Silent fail — user can open manually
|
|
94
118
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-token-usage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Analyze Claude Code session token usage, costs, and efficiency",
|
|
5
5
|
"bin": {
|
|
6
6
|
"cc-token-usage": "./bin/cli.mjs"
|
|
7
7
|
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"postinstall": "node ./bin/install.mjs"
|
|
10
|
-
},
|
|
11
8
|
"files": [
|
|
12
9
|
"bin/",
|
|
13
10
|
"README.md"
|
|
14
11
|
],
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"cc-token-usage-darwin-arm64": "1.0.4",
|
|
14
|
+
"cc-token-usage-darwin-x64": "1.0.4",
|
|
15
|
+
"cc-token-usage-linux-x64": "1.0.4",
|
|
16
|
+
"cc-token-usage-linux-arm64": "1.0.4"
|
|
17
|
+
},
|
|
15
18
|
"keywords": [
|
|
16
19
|
"claude",
|
|
17
20
|
"claude-code",
|
|
@@ -23,11 +26,5 @@
|
|
|
23
26
|
"license": "MIT",
|
|
24
27
|
"engines": {
|
|
25
28
|
"node": ">=18"
|
|
26
|
-
},
|
|
27
|
-
"optionalDependencies": {
|
|
28
|
-
"cc-token-usage-darwin-arm64": "1.0.3",
|
|
29
|
-
"cc-token-usage-darwin-x64": "1.0.3",
|
|
30
|
-
"cc-token-usage-linux-x64": "1.0.3",
|
|
31
|
-
"cc-token-usage-linux-arm64": "1.0.3"
|
|
32
29
|
}
|
|
33
30
|
}
|
package/bin/install.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Postinstall: resolve platform binary from optionalDependencies or PATH.
|
|
4
|
-
|
|
5
|
-
import { execSync } from "child_process";
|
|
6
|
-
import { existsSync, copyFileSync, chmodSync } from "fs";
|
|
7
|
-
import { join, dirname } from "path";
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
9
|
-
import { createRequire } from "module";
|
|
10
|
-
|
|
11
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const binaryDest = join(__dirname, "cc-token-usage");
|
|
13
|
-
|
|
14
|
-
// Already have it
|
|
15
|
-
if (existsSync(binaryDest)) {
|
|
16
|
-
process.exit(0);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Try to resolve from platform-specific optionalDependency
|
|
20
|
-
const platform = process.platform;
|
|
21
|
-
const arch = process.arch;
|
|
22
|
-
const pkgMap = {
|
|
23
|
-
"darwin-arm64": "cc-token-usage-darwin-arm64",
|
|
24
|
-
"darwin-x64": "cc-token-usage-darwin-x64",
|
|
25
|
-
"linux-x64": "cc-token-usage-linux-x64",
|
|
26
|
-
"linux-arm64": "cc-token-usage-linux-arm64",
|
|
27
|
-
};
|
|
28
|
-
const pkgName = pkgMap[`${platform}-${arch}`];
|
|
29
|
-
|
|
30
|
-
if (pkgName) {
|
|
31
|
-
try {
|
|
32
|
-
const require = createRequire(import.meta.url);
|
|
33
|
-
const pkgDir = dirname(require.resolve(`${pkgName}/package.json`));
|
|
34
|
-
const src = join(pkgDir, "cc-token-usage");
|
|
35
|
-
if (existsSync(src)) {
|
|
36
|
-
copyFileSync(src, binaryDest);
|
|
37
|
-
chmodSync(binaryDest, 0o755);
|
|
38
|
-
console.log(`cc-token-usage: installed binary from ${pkgName}`);
|
|
39
|
-
process.exit(0);
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
// Package not installed (wrong platform, or not published yet)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Fallback: check PATH
|
|
47
|
-
try {
|
|
48
|
-
execSync("cc-token-usage --version", { stdio: "ignore" });
|
|
49
|
-
process.exit(0);
|
|
50
|
-
} catch {
|
|
51
|
-
console.warn("cc-token-usage: no pre-built binary for your platform.");
|
|
52
|
-
console.warn("Install via cargo: cargo install cc-token-usage");
|
|
53
|
-
}
|