@notenkidev/claude-token-dashboard 0.1.4 → 0.1.6
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.js +31 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* npx インストールパスの構造:
|
|
5
|
+
* ~/.npm/_npx/<hash>/node_modules/@notenkidev/claude-token-dashboard/ ← root (__dirname/..)
|
|
6
|
+
* ~/.npm/_npx/<hash>/node_modules/.bin/next ← flat install (2 levels up)
|
|
7
|
+
*
|
|
8
|
+
* ローカル開発 / npm install の場合:
|
|
9
|
+
* <project>/node_modules/.bin/next ← nested install
|
|
10
|
+
*/
|
|
11
|
+
|
|
3
12
|
const { execSync, spawn } = require('child_process')
|
|
4
13
|
const { existsSync } = require('fs')
|
|
5
14
|
const { join } = require('path')
|
|
@@ -7,15 +16,32 @@ const { join } = require('path')
|
|
|
7
16
|
const root = join(__dirname, '..')
|
|
8
17
|
const args = process.argv.slice(2)
|
|
9
18
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
function findNext () {
|
|
20
|
+
return [
|
|
21
|
+
// npx flat install (scoped packages live 2 dirs deep inside node_modules)
|
|
22
|
+
join(root, '..', '..', '.bin', 'next'),
|
|
23
|
+
// local nested install (git clone → npm install)
|
|
24
|
+
join(root, 'node_modules', '.bin', 'next'),
|
|
25
|
+
].find(existsSync) ?? null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let nextBin = findNext()
|
|
29
|
+
|
|
30
|
+
// Fallback: run npm install locally (e.g. running directly from a git clone
|
|
31
|
+
// without having done npm install first)
|
|
32
|
+
if (!nextBin) {
|
|
33
|
+
console.log('📦 Installing dependencies (~30s)...')
|
|
34
|
+
execSync('npm install --prefer-offline', { cwd: root, stdio: 'inherit' })
|
|
35
|
+
nextBin = findNext()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!nextBin) {
|
|
39
|
+
console.error('❌ Could not locate the next binary. Run `npm install` in the project directory.')
|
|
40
|
+
process.exit(1)
|
|
14
41
|
}
|
|
15
42
|
|
|
16
43
|
console.log('🚀 Starting Claude Token Dashboard → http://localhost:3000\n')
|
|
17
44
|
|
|
18
|
-
const nextBin = join(root, 'node_modules', '.bin', 'next')
|
|
19
45
|
const child = spawn(process.execPath, [nextBin, 'dev', ...args], {
|
|
20
46
|
cwd: root,
|
|
21
47
|
stdio: 'inherit',
|