@hncode/hncode 0.1.3 → 0.1.5
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/LICENSE +219 -219
- package/README.md +198 -197
- package/README_CN.md +187 -186
- package/bin/install.js +95 -95
- package/bin/preinstall.js +41 -41
- package/package.json +35 -35
- package/src/colors.js +53 -4
- package/src/tui.js +38 -9
package/README_CN.md
CHANGED
|
@@ -1,186 +1,187 @@
|
|
|
1
|
-
# hncode — AI 编程助手命令行工具
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
|
77
|
-
|
|
78
|
-
| `/
|
|
79
|
-
| `/
|
|
80
|
-
| `/
|
|
81
|
-
| `/
|
|
82
|
-
| `/
|
|
83
|
-
| `/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- `
|
|
140
|
-
- `
|
|
141
|
-
- `
|
|
142
|
-
- `
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
**
|
|
1
|
+
# hncode — AI 编程助手命令行工具
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
> **这是我 Vibe Coding 的产物,可能不是特别好,但是如果有什么建议的话也欢迎提 issue**
|
|
6
|
+
|
|
7
|
+
一个基于命令行终端的 AI 编程助手,灵感源自 [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code)。它提供青色蓝调 (Cyan-blue) 的 TUI 界面,支持 OpenAI 和 Anthropic 双协议,配备 MCP 风格的工具集和智能上下文管理。
|
|
8
|
+
|
|
9
|
+
## 🌟 核心特性
|
|
10
|
+
|
|
11
|
+
- **原生 TUI 渲染**: 使用原始终端序列号渲染,完美兼容 Windows Terminal,解决 blessed 等库在 Windows 上的兼容性问题
|
|
12
|
+
- **双协议支持**: 同时支持 OpenAI-compatible API 和 Anthropic API
|
|
13
|
+
- **智能上下文管理**:
|
|
14
|
+
- 85% 使用率时自动触发压缩
|
|
15
|
+
- AI 摘要保留的历史对话,而非简单丢弃
|
|
16
|
+
- 手动 `/compact` 命令支持自定义压缩比例
|
|
17
|
+
- **MCP 风格工具集**: Read, Write, Edit, Bash, Glob, Grep, TodoList, WebSearch, FetchURL 等
|
|
18
|
+
- **插件系统**: 可扩展的工具、命令和生命周期钩子
|
|
19
|
+
- **会话持久化**: 跨会话恢复对话
|
|
20
|
+
- **权限模式**: Ask, YOLO, Auto 三种工作流模式
|
|
21
|
+
|
|
22
|
+
## 🚀 安装
|
|
23
|
+
|
|
24
|
+
### 全局安装(推荐)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @hncode/hncode
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
然后运行:
|
|
31
|
+
```bash
|
|
32
|
+
hncode
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 使用 npx(无需安装)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx @hncode/hncode
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
这将下载并运行最新版本,而无需全局安装。
|
|
42
|
+
|
|
43
|
+
### 本地开发安装
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install @hncode/hncode
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## ⚙️ 配置
|
|
50
|
+
|
|
51
|
+
创建 `~/.hncode/config.toml`:
|
|
52
|
+
|
|
53
|
+
```toml
|
|
54
|
+
default_model = "gpt-4o-mini"
|
|
55
|
+
|
|
56
|
+
[providers.openai]
|
|
57
|
+
base_url = "https://api.openai.com/v1"
|
|
58
|
+
api_key = "your-api-key-here"
|
|
59
|
+
|
|
60
|
+
[models.gpt-4o-mini]
|
|
61
|
+
provider = "openai"
|
|
62
|
+
model = "gpt-4o-mini"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
或使用环境变量:
|
|
66
|
+
```bash
|
|
67
|
+
export HNCODE_API_KEY="your-key"
|
|
68
|
+
export HNCODE_PROVIDER="openai"
|
|
69
|
+
export HNCODE_MODEL="gpt-4o-mini"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 📖 使用
|
|
73
|
+
|
|
74
|
+
### 基本命令
|
|
75
|
+
|
|
76
|
+
| 命令 | 描述 |
|
|
77
|
+
|------|------|
|
|
78
|
+
| `/compact [ratio]` | 压缩对话(AI 摘要 + 保留最近 20%) |
|
|
79
|
+
| `/model <name>` | 切换 LLM 模型 |
|
|
80
|
+
| `/sessions` | 浏览和恢复过往对话 |
|
|
81
|
+
| `/move <path>` | 将当前会话迁移到另一个目录 |
|
|
82
|
+
| `/auto` / `/ask` / `/yolo` | 切换权限模式 |
|
|
83
|
+
| `/plan` / `/focus` | 切换仅研究或完整编辑模式 |
|
|
84
|
+
| `/calm-mode` | 简洁回复(跳过叙述) |
|
|
85
|
+
| `/help` | 显示所有命令 |
|
|
86
|
+
|
|
87
|
+
### Tab 补全
|
|
88
|
+
|
|
89
|
+
- 输入 `/` → 命令菜单
|
|
90
|
+
- 输入 `@` → 文件/文件夹补全
|
|
91
|
+
- 使用 Tab 导航,Enter 选择
|
|
92
|
+
|
|
93
|
+
### 自动压缩
|
|
94
|
+
|
|
95
|
+
- 当上下文使用率达到 85% 时自动触发
|
|
96
|
+
- AI 会摘要被丢弃的消息,而不是简单删除
|
|
97
|
+
- 保留最近的 20% 对话以保持上下文连贯性
|
|
98
|
+
|
|
99
|
+
## 🔧 插件系统
|
|
100
|
+
|
|
101
|
+
### 创建插件
|
|
102
|
+
|
|
103
|
+
在 `~/.hncode/plugins/` 目录下创建 `.js` 或 `.mjs` 文件:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
// my-plugin.mjs
|
|
107
|
+
export function install(api) {
|
|
108
|
+
// 注册新工具
|
|
109
|
+
api.registerTool({
|
|
110
|
+
name: 'MyTool',
|
|
111
|
+
description: '...',
|
|
112
|
+
parameters: { /* schema */ },
|
|
113
|
+
async execute(args, ctx) { return result; }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// 注册命令
|
|
117
|
+
api.registerCommand({
|
|
118
|
+
name: 'mycmd',
|
|
119
|
+
description: '...',
|
|
120
|
+
run: (arg, ctx) => { /* ... */ }
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// 注册钩子
|
|
124
|
+
api.registerHook('onTurnEnd', (turnInfo) => { /* ... */ });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default { name: 'my-plugin', version: '1.0.0' };
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 查看已加载插件
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
hncode /plugins
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 🛠 工具集
|
|
137
|
+
|
|
138
|
+
内置工具包括:
|
|
139
|
+
- `Read`, `Write`, `Edit` - 文件操作
|
|
140
|
+
- `Bash` - 执行 Shell 命令
|
|
141
|
+
- `Glob`, `Grep` - 搜索文件
|
|
142
|
+
- `TodoList`, `TaskOutput` - 任务管理
|
|
143
|
+
- `FetchURL`, `WebSearch` - 网络访问
|
|
144
|
+
- `ReadMediaFile`, `FileLines` - 媒体处理
|
|
145
|
+
|
|
146
|
+
## 🎨 主题
|
|
147
|
+
|
|
148
|
+
支持的 theme: `auto`, `dark`, `light`, 或自定义 RGB 颜色。
|
|
149
|
+
|
|
150
|
+
通过配置设置:
|
|
151
|
+
```toml
|
|
152
|
+
theme = "dark"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
或在 TUI 中使用 `/theme <name>`。
|
|
156
|
+
|
|
157
|
+
## 🤝 贡献
|
|
158
|
+
|
|
159
|
+
这个项目是通过 Vibe Coding 创建的。虽然它可能不够完美,但我欢迎您的反馈!
|
|
160
|
+
|
|
161
|
+
**欢迎:**
|
|
162
|
+
- 提交问题报告 bug 或提出建议
|
|
163
|
+
- Fork 并创建拉取请求
|
|
164
|
+
- 分享您使用 hncode 的体验
|
|
165
|
+
|
|
166
|
+
## 🙏 致谢
|
|
167
|
+
|
|
168
|
+
hncode 从以下几个优秀项目中汲取了灵感:
|
|
169
|
+
|
|
170
|
+
- **[Kimi Code CLI](https://github.com/MoonshotAI/kimi-code)** - 原始的青色蓝调终端界面 AI 编程助手,启发了本项目的设计和理念
|
|
171
|
+
- **[Claude Code](https://github.com/anthropics/claude-code)** - 对话流程和工具交互模式
|
|
172
|
+
|
|
173
|
+
特别感谢这些项目背后的社区,它们推动了 AI 辅助编程的边界。
|
|
174
|
+
|
|
175
|
+
## 📄 许可证
|
|
176
|
+
|
|
177
|
+
本项目的许可受 [GNU General Public License v3.0](LICENSE) 保护。
|
|
178
|
+
|
|
179
|
+
**简单来说:**
|
|
180
|
+
1. ✅ 你可以自由使用、修改和分享此代码
|
|
181
|
+
2. ✅ 必须保留原作者署名(NiceHello666)并链接回此仓库
|
|
182
|
+
3. ❌ 不得用于商业目的(例如出售、作为付费产品的一部分)
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
**NPM 包**: [@hncode/hncode](https://www.npmjs.com/package/@hncode/hncode)
|
|
187
|
+
**GitHub**: [NiceHello666/hncode](https://github.com/NiceHello666/hncode)
|
package/bin/install.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* hncode auto-install script
|
|
4
|
-
* Creates default configuration and sets up the environment
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const os = require('os');
|
|
10
|
-
|
|
11
|
-
// Get user home directory (cross-platform)
|
|
12
|
-
const homeDir = os.homedir();
|
|
13
|
-
const configDir = path.join(homeDir, '.hncode');
|
|
14
|
-
const configFile = path.join(configDir, 'config.toml');
|
|
15
|
-
const sessionsDir = path.join(configDir, 'sessions');
|
|
16
|
-
const pluginsDir = path.join(configDir, 'plugins');
|
|
17
|
-
|
|
18
|
-
console.log('🚀 Setting up hncode...\n');
|
|
19
|
-
|
|
20
|
-
// Create directories if they don't exist
|
|
21
|
-
const dirs = [configDir, sessionsDir, pluginsDir];
|
|
22
|
-
for (const dir of dirs) {
|
|
23
|
-
if (!fs.existsSync(dir)) {
|
|
24
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
25
|
-
console.log(`✓ Created directory: ${dir}`);
|
|
26
|
-
} else {
|
|
27
|
-
console.log(`✓ Directory exists: ${dir}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Check if config file exists
|
|
32
|
-
if (!fs.existsSync(configFile)) {
|
|
33
|
-
const defaultConfig = `# hncode Configuration
|
|
34
|
-
# Generated by hncode install script
|
|
35
|
-
|
|
36
|
-
# Default model (change this to your preferred model)
|
|
37
|
-
default_model = "gpt-4o-mini"
|
|
38
|
-
|
|
39
|
-
# Optional: Add providers directly here
|
|
40
|
-
# Uncomment and configure as needed:
|
|
41
|
-
#
|
|
42
|
-
# [providers.openai]
|
|
43
|
-
# base_url = "https://api.openai.com/v1"
|
|
44
|
-
# api_key = "your-api-key-here"
|
|
45
|
-
# protocol = "openai"
|
|
46
|
-
|
|
47
|
-
# Or use environment variables:
|
|
48
|
-
# HNCODE_API_KEY="your-key"
|
|
49
|
-
# HNCODE_PROVIDER="openai"
|
|
50
|
-
# HNCODE_MODEL="gpt-4o-mini"
|
|
51
|
-
|
|
52
|
-
`;
|
|
53
|
-
|
|
54
|
-
fs.writeFileSync(configFile, defaultConfig);
|
|
55
|
-
console.log(`\n✅ Created default configuration at: ${configFile}`);
|
|
56
|
-
console.log('\n💡 Next steps:');
|
|
57
|
-
console.log(' 1. Edit ~/.hncode/config.toml with your API key');
|
|
58
|
-
console.log(' 2. Or set environment variables:');
|
|
59
|
-
console.log(' export HNCODE_API_KEY="your-key"');
|
|
60
|
-
console.log(' export HNCODE_PROVIDER="openai"');
|
|
61
|
-
console.log(' 3. Run "hncode" to start!');
|
|
62
|
-
} else {
|
|
63
|
-
console.log(`\nℹ️ Configuration already exists at: ${configFile}`);
|
|
64
|
-
console.log(' Run "hncode init" to regenerate or edit manually.');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
console.log('\n✨ hncode is ready to use!');
|
|
68
|
-
|
|
69
|
-
// Try to refresh environment automatically
|
|
70
|
-
try {
|
|
71
|
-
const platform = os.platform();
|
|
72
|
-
|
|
73
|
-
if (platform === 'win32') {
|
|
74
|
-
// Windows: Use PowerShell to refresh environment
|
|
75
|
-
const { execSync } = require('child_process');
|
|
76
|
-
try {
|
|
77
|
-
execSync('Refresh-Environment', { stdio: 'pipe' });
|
|
78
|
-
console.log('✓ Environment refreshed automatically (PowerShell)');
|
|
79
|
-
} catch (e) {
|
|
80
|
-
console.log('ℹ️ To refresh environment in PowerShell:');
|
|
81
|
-
console.log(' . "$env:LOCALAPPDATA\\npm\\npm.cmd"');
|
|
82
|
-
console.log(' Or simply close and reopen your terminal');
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
// Unix-like systems
|
|
86
|
-
console.log('ℹ️ Please run one of these to refresh environment:');
|
|
87
|
-
console.log(' source ~/.zshrc # For Zsh');
|
|
88
|
-
console.log(' source ~/.bashrc # For Bash');
|
|
89
|
-
console.log(' Or simply close and reopen your terminal');
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
console.log('ℹ️ Note: You may need to restart your terminal');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
console.log('');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* hncode auto-install script
|
|
4
|
+
* Creates default configuration and sets up the environment
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
|
|
11
|
+
// Get user home directory (cross-platform)
|
|
12
|
+
const homeDir = os.homedir();
|
|
13
|
+
const configDir = path.join(homeDir, '.hncode');
|
|
14
|
+
const configFile = path.join(configDir, 'config.toml');
|
|
15
|
+
const sessionsDir = path.join(configDir, 'sessions');
|
|
16
|
+
const pluginsDir = path.join(configDir, 'plugins');
|
|
17
|
+
|
|
18
|
+
console.log('🚀 Setting up hncode...\n');
|
|
19
|
+
|
|
20
|
+
// Create directories if they don't exist
|
|
21
|
+
const dirs = [configDir, sessionsDir, pluginsDir];
|
|
22
|
+
for (const dir of dirs) {
|
|
23
|
+
if (!fs.existsSync(dir)) {
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
25
|
+
console.log(`✓ Created directory: ${dir}`);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(`✓ Directory exists: ${dir}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check if config file exists
|
|
32
|
+
if (!fs.existsSync(configFile)) {
|
|
33
|
+
const defaultConfig = `# hncode Configuration
|
|
34
|
+
# Generated by hncode install script
|
|
35
|
+
|
|
36
|
+
# Default model (change this to your preferred model)
|
|
37
|
+
default_model = "gpt-4o-mini"
|
|
38
|
+
|
|
39
|
+
# Optional: Add providers directly here
|
|
40
|
+
# Uncomment and configure as needed:
|
|
41
|
+
#
|
|
42
|
+
# [providers.openai]
|
|
43
|
+
# base_url = "https://api.openai.com/v1"
|
|
44
|
+
# api_key = "your-api-key-here"
|
|
45
|
+
# protocol = "openai"
|
|
46
|
+
|
|
47
|
+
# Or use environment variables:
|
|
48
|
+
# HNCODE_API_KEY="your-key"
|
|
49
|
+
# HNCODE_PROVIDER="openai"
|
|
50
|
+
# HNCODE_MODEL="gpt-4o-mini"
|
|
51
|
+
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
fs.writeFileSync(configFile, defaultConfig);
|
|
55
|
+
console.log(`\n✅ Created default configuration at: ${configFile}`);
|
|
56
|
+
console.log('\n💡 Next steps:');
|
|
57
|
+
console.log(' 1. Edit ~/.hncode/config.toml with your API key');
|
|
58
|
+
console.log(' 2. Or set environment variables:');
|
|
59
|
+
console.log(' export HNCODE_API_KEY="your-key"');
|
|
60
|
+
console.log(' export HNCODE_PROVIDER="openai"');
|
|
61
|
+
console.log(' 3. Run "hncode" to start!');
|
|
62
|
+
} else {
|
|
63
|
+
console.log(`\nℹ️ Configuration already exists at: ${configFile}`);
|
|
64
|
+
console.log(' Run "hncode init" to regenerate or edit manually.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log('\n✨ hncode is ready to use!');
|
|
68
|
+
|
|
69
|
+
// Try to refresh environment automatically
|
|
70
|
+
try {
|
|
71
|
+
const platform = os.platform();
|
|
72
|
+
|
|
73
|
+
if (platform === 'win32') {
|
|
74
|
+
// Windows: Use PowerShell to refresh environment
|
|
75
|
+
const { execSync } = require('child_process');
|
|
76
|
+
try {
|
|
77
|
+
execSync('Refresh-Environment', { stdio: 'pipe' });
|
|
78
|
+
console.log('✓ Environment refreshed automatically (PowerShell)');
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.log('ℹ️ To refresh environment in PowerShell:');
|
|
81
|
+
console.log(' . "$env:LOCALAPPDATA\\npm\\npm.cmd"');
|
|
82
|
+
console.log(' Or simply close and reopen your terminal');
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
// Unix-like systems
|
|
86
|
+
console.log('ℹ️ Please run one of these to refresh environment:');
|
|
87
|
+
console.log(' source ~/.zshrc # For Zsh');
|
|
88
|
+
console.log(' source ~/.bashrc # For Bash');
|
|
89
|
+
console.log(' Or simply close and reopen your terminal');
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.log('ℹ️ Note: You may need to restart your terminal');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log('');
|
|
96
96
|
console.log(' Type "hncode --help" for available commands.\n');
|
package/bin/preinstall.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* hncode pre-install script
|
|
4
|
-
* Checks environment requirements before installation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const os = require('os');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
console.log('🔍 Checking environment...\n');
|
|
11
|
-
|
|
12
|
-
// Check Node.js version
|
|
13
|
-
const nodeVersion = process.version.replace('v', '');
|
|
14
|
-
const [major] = nodeVersion.split('.').map(Number);
|
|
15
|
-
|
|
16
|
-
if (major < 20) {
|
|
17
|
-
console.warn(`⚠️ Warning: Node.js v${nodeVersion} detected.`);
|
|
18
|
-
console.warn(' hncode requires Node.js >= 20. Please upgrade.');
|
|
19
|
-
process.exit(1);
|
|
20
|
-
} else {
|
|
21
|
-
console.log(`✓ Node.js v${nodeVersion} ✓`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Check platform
|
|
25
|
-
const platform = os.platform();
|
|
26
|
-
console.log(`✓ Platform: ${platform}`);
|
|
27
|
-
|
|
28
|
-
// Check if already installed globally
|
|
29
|
-
try {
|
|
30
|
-
const { execSync } = require('child_process');
|
|
31
|
-
const npm = execSync('npm list -g hncode 2>&1').toString();
|
|
32
|
-
if (npm.includes('hncode')) {
|
|
33
|
-
console.log('ℹ️ hncode is already installed globally');
|
|
34
|
-
console.log(' Run "npm uninstall -g hncode" to reinstall.\n');
|
|
35
|
-
} else {
|
|
36
|
-
console.log('✓ Not installed globally yet\n');
|
|
37
|
-
}
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.log('✓ Not installed globally yet\n');
|
|
40
|
-
}
|
|
41
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* hncode pre-install script
|
|
4
|
+
* Checks environment requirements before installation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
console.log('🔍 Checking environment...\n');
|
|
11
|
+
|
|
12
|
+
// Check Node.js version
|
|
13
|
+
const nodeVersion = process.version.replace('v', '');
|
|
14
|
+
const [major] = nodeVersion.split('.').map(Number);
|
|
15
|
+
|
|
16
|
+
if (major < 20) {
|
|
17
|
+
console.warn(`⚠️ Warning: Node.js v${nodeVersion} detected.`);
|
|
18
|
+
console.warn(' hncode requires Node.js >= 20. Please upgrade.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
} else {
|
|
21
|
+
console.log(`✓ Node.js v${nodeVersion} ✓`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Check platform
|
|
25
|
+
const platform = os.platform();
|
|
26
|
+
console.log(`✓ Platform: ${platform}`);
|
|
27
|
+
|
|
28
|
+
// Check if already installed globally
|
|
29
|
+
try {
|
|
30
|
+
const { execSync } = require('child_process');
|
|
31
|
+
const npm = execSync('npm list -g hncode 2>&1').toString();
|
|
32
|
+
if (npm.includes('hncode')) {
|
|
33
|
+
console.log('ℹ️ hncode is already installed globally');
|
|
34
|
+
console.log(' Run "npm uninstall -g hncode" to reinstall.\n');
|
|
35
|
+
} else {
|
|
36
|
+
console.log('✓ Not installed globally yet\n');
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.log('✓ Not installed globally yet\n');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
42
|
console.log('✅ Environment check passed!\n');
|