@winston.wan/burn-your-money 2.0.1 → 2.0.3

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 +155 -0
  3. package/package.json +2 -2
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,155 @@
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! It is required for the statusline script.");
46
+ log(" Please install jq manually:", colors.yellow);
47
+ log(" Windows: winget install jqlang.jq", colors.yellow);
48
+ log(" macOS: brew install jq", colors.yellow);
49
+ log(" Linux: sudo apt-get install jq", colors.yellow);
50
+ }
51
+
52
+ // Check for Claude Code (informational only)
53
+ try {
54
+ const version = execSync('claude --version', { encoding: 'utf8' }).trim();
55
+ success(`Claude Code found: ${version}`);
56
+ } catch (e) {
57
+ warning("Claude Code not found in PATH.");
58
+ }
59
+ }
60
+
61
+ function createDirectories() {
62
+ log("Creating directories...", colors.cyan);
63
+ const home = getHomeDir();
64
+ const claudeDir = path.join(home, '.claude');
65
+ const scriptsDir = path.join(claudeDir, 'scripts');
66
+ const cacheDir = path.join(claudeDir, 'cache');
67
+
68
+ [claudeDir, scriptsDir, cacheDir].forEach(dir => {
69
+ if (!fs.existsSync(dir)) {
70
+ fs.mkdirSync(dir, { recursive: true });
71
+ }
72
+ });
73
+
74
+ success("Directories created");
75
+ }
76
+
77
+ function installScripts() {
78
+ log("Installing scripts...", colors.cyan);
79
+ const home = getHomeDir();
80
+ const srcDir = path.join(__dirname, 'src');
81
+
82
+ const files = [
83
+ { src: 'statusline.sh', dest: path.join(home, '.claude', 'statusline.sh') },
84
+ { src: 'token-history.sh', dest: path.join(home, '.claude', 'scripts', 'token-history.sh') }
85
+ ];
86
+
87
+ files.forEach(file => {
88
+ const srcPath = path.join(srcDir, file.src);
89
+ const destPath = file.dest;
90
+
91
+ try {
92
+ fs.copyFileSync(srcPath, destPath);
93
+ // Make executable
94
+ if (os.platform() !== 'win32') {
95
+ fs.chmodSync(destPath, '755');
96
+ }
97
+ success(`Installed ${file.src}`);
98
+ } catch (e) {
99
+ error(`Failed to install ${file.src}: ${e.message}`);
100
+ process.exit(1);
101
+ }
102
+ });
103
+ }
104
+
105
+ function configureSettings() {
106
+ log("Configuring Claude Code...", colors.cyan);
107
+ const home = getHomeDir();
108
+ const settingsFile = path.join(home, '.claude', 'settings.json');
109
+
110
+ let settings = {};
111
+ if (fs.existsSync(settingsFile)) {
112
+ try {
113
+ settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
114
+ } catch (e) {
115
+ warning("Failed to parse existing settings.json, creating new.");
116
+ }
117
+ }
118
+
119
+ // Update statusLine config
120
+ // We use forward slashes for paths in settings.json even on Windows for consistency in JSON
121
+ // accessing existing wsl path if needed? No, standard path is fine.
122
+ // The previous implementation used `~/.claude/statusline.sh`.
123
+ // Claude might process `~`? Let's stick to what the bash script did: `~/.claude/statusline.sh`
124
+
125
+ settings.statusLine = {
126
+ type: "command",
127
+ command: "~/.claude/statusline.sh"
128
+ };
129
+
130
+ try {
131
+ fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
132
+ success("settings.json updated");
133
+ } catch (e) {
134
+ error(`Failed to update settings.json: ${e.message}`);
135
+ }
136
+ }
137
+
138
+ function main() {
139
+ log("\n💸 Burn Your Money - Installer\n", colors.purple);
140
+
141
+ try {
142
+ checkDependencies();
143
+ createDirectories();
144
+ installScripts();
145
+ configureSettings();
146
+
147
+ log("\n✅ Installation complete!", colors.green);
148
+ log("Please restart Claude Code to see the status bar.\n", colors.cyan);
149
+ } catch (e) {
150
+ error(`Installation failed: ${e.message}`);
151
+ process.exit(1);
152
+ }
153
+ }
154
+
155
+ 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.3",
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": {