@winston.wan/burn-your-money 2.0.1 → 2.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.
Files changed (3) hide show
  1. package/README.md +11 -17
  2. package/install.js +212 -0
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -30,26 +30,26 @@ Claude Code 会默默地烧掉你的钱,而你甚至感觉不到...
30
30
 
31
31
  ## 🚀 快速安装
32
32
 
33
- ### Windows
33
+ ### 方法 1: NPM 安装 (推荐)
34
34
 
35
- **方法 1: PowerShell**
36
- ```powershell
37
- # PowerShell 使用分号分隔命令
38
- curl.exe -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh -o install.sh; bash install.sh
39
- ```
40
-
41
- **方法 2: Git Bash(推荐)**
42
35
  ```bash
43
- curl -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh | bash
36
+ npm install -g "@winston.wan/burn-your-money"
44
37
  ```
45
38
 
46
- ### Linux/macOS/Git Bash
39
+ ### 方法 2: 一键脚本
47
40
 
41
+ **Linux / macOS / Git Bash**
48
42
  ```bash
49
43
  curl -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh | bash
50
44
  ```
51
45
 
52
- ### 方法 2: 手动安装
46
+ **Windows PowerShell**
47
+ ```powershell
48
+ # PowerShell 使用分号分隔命令
49
+ curl.exe -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh -o install.sh; bash install.sh
50
+ ```
51
+
52
+ ### 方法 3: 手动安装
53
53
 
54
54
  ```bash
55
55
  # 克隆仓库
@@ -60,12 +60,6 @@ cd burn-your-money
60
60
  ./install.sh
61
61
  ```
62
62
 
63
- ### 方法 3: NPM 安装
64
-
65
- ```bash
66
- npm install -g @winston.wan/burn-your-money
67
- ```
68
-
69
63
  ## 📋 系统要求
70
64
 
71
65
  - ✅ Claude Code 2.1.6 或更高版本
package/install.js ADDED
@@ -0,0 +1,212 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const { execSync } = require('child_process');
5
+
6
+ // ANSI colors for console output
7
+ const colors = {
8
+ reset: "\x1b[0m",
9
+ red: "\x1b[31m",
10
+ green: "\x1b[32m",
11
+ yellow: "\x1b[33m",
12
+ blue: "\x1b[34m",
13
+ purple: "\x1b[35m",
14
+ cyan: "\x1b[36m"
15
+ };
16
+
17
+ function log(message, color = colors.reset) {
18
+ console.log(`${color}${message}${colors.reset}`);
19
+ }
20
+
21
+ function success(message) {
22
+ log(`✓ ${message}`, colors.green);
23
+ }
24
+
25
+ function warning(message) {
26
+ log(`⚠ ${message}`, colors.yellow);
27
+ }
28
+
29
+ function error(message) {
30
+ log(`✗ ${message}`, colors.red);
31
+ }
32
+
33
+ function getHomeDir() {
34
+ return os.homedir();
35
+ }
36
+
37
+ function checkDependencies() {
38
+ log("Checking dependencies...", colors.cyan);
39
+
40
+ // Check for jq
41
+ try {
42
+ execSync('jq --version', { stdio: 'ignore' });
43
+ success("jq is installed");
44
+ } catch (e) {
45
+ warning("jq not found! Attempting valid auto-installation...");
46
+
47
+ try {
48
+ if (os.platform() === 'win32') {
49
+ log("Attempting to install jq via winget...", colors.cyan);
50
+ // silent install might need admin, but let's try
51
+ execSync('winget install jqlang.jq --accept-source-agreements --accept-package-agreements', { stdio: 'inherit' });
52
+ success("jq installed successfully!");
53
+ } else if (os.platform() === 'darwin') {
54
+ log("Attempting to install jq via brew...", colors.cyan);
55
+ execSync('brew install jq', { stdio: 'inherit' });
56
+ success("jq installed successfully!");
57
+ } else {
58
+ // Linux: too many variants (apt, dnf, pacman...), just warn
59
+ throw new Error("Linux auto-install not supported");
60
+ }
61
+ } catch (installError) {
62
+ error("Auto-installation failed.");
63
+ log(" Please install jq manually:", colors.yellow);
64
+ log(" Windows: winget install jqlang.jq", colors.yellow);
65
+ log(" macOS: brew install jq", colors.yellow);
66
+ log(" Linux: sudo apt-get install jq", colors.yellow);
67
+ }
68
+ }
69
+
70
+ // Check for Claude Code (informational only)
71
+ try {
72
+ const version = execSync('claude --version', { encoding: 'utf8' }).trim();
73
+ success(`Claude Code found: ${version}`);
74
+ } catch (e) {
75
+ warning("Claude Code not found in PATH.");
76
+ }
77
+ }
78
+
79
+ function createDirectories() {
80
+ log("Creating directories...", colors.cyan);
81
+ const home = getHomeDir();
82
+ const claudeDir = path.join(home, '.claude');
83
+ const scriptsDir = path.join(claudeDir, 'scripts');
84
+ const cacheDir = path.join(claudeDir, 'cache');
85
+
86
+ [claudeDir, scriptsDir, cacheDir].forEach(dir => {
87
+ if (!fs.existsSync(dir)) {
88
+ fs.mkdirSync(dir, { recursive: true });
89
+ }
90
+ });
91
+
92
+ success("Directories created");
93
+ }
94
+
95
+ function installScripts() {
96
+ log("Installing scripts...", colors.cyan);
97
+ const home = getHomeDir();
98
+ const srcDir = path.join(__dirname, 'src');
99
+
100
+ const files = [
101
+ { src: 'statusline.sh', dest: path.join(home, '.claude', 'statusline.sh') },
102
+ { src: 'token-history.sh', dest: path.join(home, '.claude', 'scripts', 'token-history.sh') }
103
+ ];
104
+
105
+ files.forEach(file => {
106
+ const srcPath = path.join(srcDir, file.src);
107
+ const destPath = file.dest;
108
+
109
+ try {
110
+ fs.copyFileSync(srcPath, destPath);
111
+ // Make executable
112
+ if (os.platform() !== 'win32') {
113
+ fs.chmodSync(destPath, '755');
114
+ }
115
+ success(`Installed ${file.src}`);
116
+ } catch (e) {
117
+ error(`Failed to install ${file.src}: ${e.message}`);
118
+ process.exit(1);
119
+ }
120
+ });
121
+ }
122
+
123
+ function configureSettings() {
124
+ log("Configuring Claude Code...", colors.cyan);
125
+ const home = getHomeDir();
126
+ const settingsFile = path.join(home, '.claude', 'settings.json');
127
+
128
+ let settings = {};
129
+ if (fs.existsSync(settingsFile)) {
130
+ try {
131
+ settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
132
+ } catch (e) {
133
+ warning("Failed to parse existing settings.json, creating new.");
134
+ }
135
+ }
136
+
137
+ // Update statusLine config
138
+ // We use forward slashes for paths in settings.json even on Windows for consistency in JSON
139
+ // accessing existing wsl path if needed? No, standard path is fine.
140
+ // The previous implementation used `~/.claude/statusline.sh`.
141
+ // Claude might process `~`? Let's stick to what the bash script did: `~/.claude/statusline.sh`
142
+
143
+ // Configure command based on platform
144
+ let commandEnv = "~/.claude/statusline.sh";
145
+
146
+ if (os.platform() === 'win32') {
147
+ // On Windows, expand home directory and ensure forward slashes
148
+ const scriptPath = path.join(home, '.claude', 'statusline.sh').replace(/\\/g, '/');
149
+
150
+ // Robust bash detection: try Git Bash first, then fallback to 'bash'
151
+ let bashPath = 'bash';
152
+ // Common Git Bash locations
153
+ const gitBashPaths = [
154
+ 'C:/Program Files/Git/bin/bash.exe',
155
+ 'C:/Program Files/Git/cmd/bash.exe',
156
+ 'C:/Program Files (x86)/Git/bin/bash.exe',
157
+ 'C:/Program Files (x86)/Git/cmd/bash.exe'
158
+ ];
159
+
160
+ let foundBash = false;
161
+ for (const p of gitBashPaths) {
162
+ if (fs.existsSync(p)) {
163
+ bashPath = `"${p}"`;
164
+ foundBash = true;
165
+ break;
166
+ }
167
+ }
168
+
169
+ if (!foundBash) {
170
+ // Warn if we are falling back to potentially broken 'bash' (WSL default)
171
+ try {
172
+ execSync('bash --version', { stdio: 'ignore' });
173
+ } catch (e) {
174
+ warning("Warning: 'bash' command seems broken on this system.");
175
+ log(" Recommend installing Git Bash: https://git-scm.com/download/win", colors.yellow);
176
+ }
177
+ }
178
+
179
+ commandEnv = `${bashPath} "${scriptPath}"`;
180
+ }
181
+
182
+ settings.statusLine = {
183
+ type: "command",
184
+ command: commandEnv
185
+ };
186
+
187
+ try {
188
+ fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
189
+ success("settings.json updated");
190
+ } catch (e) {
191
+ error(`Failed to update settings.json: ${e.message}`);
192
+ }
193
+ }
194
+
195
+ function main() {
196
+ log("\n💸 Burn Your Money - Installer\n", colors.purple);
197
+
198
+ try {
199
+ checkDependencies();
200
+ createDirectories();
201
+ installScripts();
202
+ configureSettings();
203
+
204
+ log("\n✅ Installation complete!", colors.green);
205
+ log("Please restart Claude Code to see the status bar.\n", colors.cyan);
206
+ } catch (e) {
207
+ error(`Installation failed: ${e.message}`);
208
+ process.exit(1);
209
+ }
210
+ }
211
+
212
+ main();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@winston.wan/burn-your-money",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
4
4
  "description": "💸 Burn Your Money - 实时显示 Claude Code 的 token 消耗,看着你的钱包燃烧!",
5
5
  "main": "src/statusline.sh",
6
6
  "bin": {
7
7
  "burn-your-money": "./bin/burn-your-money"
8
8
  },
9
9
  "scripts": {
10
- "install": "bash ./install.sh",
10
+ "install": "node install.js",
11
11
  "test": "bash ./test.sh"
12
12
  },
13
13
  "repository": {
@@ -29,4 +29,4 @@
29
29
  "url": "https://github.com/winston-wwzhen/burn-your-money/issues"
30
30
  },
31
31
  "homepage": "https://github.com/winston-wwzhen/burn-your-money#readme"
32
- }
32
+ }