clash-kit 1.0.2 → 1.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.
- package/.gitignore +20 -0
- package/LICENSE.md +9 -0
- package/README.md +4 -15
- package/index.js +12 -6
- package/lib/commands/init.js +1 -1
- package/lib/commands/stop.js +2 -2
- package/lib/kernel.js +1 -1
- package/lib/tun.js +1 -1
- package/package.json +5 -3
package/.gitignore
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present, 荣顶 and wechat-bot contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -99,20 +99,9 @@ sudo ck tun on
|
|
|
99
99
|
|
|
100
100
|
<img width="2742" height="1994" alt="image" src="https://github.com/user-attachments/assets/1183f778-62b0-4ac7-ab55-b821b66161f0" />
|
|
101
101
|
|
|
102
|
-
## 目录结构
|
|
103
|
-
|
|
104
|
-
- `bin/`: CLI 入口文件
|
|
105
|
-
- `lib/`: 核心逻辑库
|
|
106
|
-
- `profiles/`: 存放下载的订阅配置文件
|
|
107
|
-
- `clash-meta`: Clash 核心二进制文件
|
|
108
|
-
- `config.yaml`: 当前生效的配置文件
|
|
109
|
-
|
|
110
|
-
## 注意事项
|
|
111
|
-
|
|
112
|
-
- 本工具依赖 `clash-meta` 二进制文件,请确保其与本工具在同一目录下(安装包已包含)。
|
|
113
|
-
- 测速功能依赖 Clash API,请确保 `clash start` 正在运行。
|
|
114
|
-
- 默认 API 地址为 `http://127.0.0.1:9090`。
|
|
115
|
-
|
|
116
102
|
## License
|
|
117
103
|
|
|
118
|
-
|
|
104
|
+
[MIT](./LICENSE).
|
|
105
|
+
|
|
106
|
+
开源不易,点赞鼓励!
|
|
107
|
+
点一个 Star⭐️ 支持我们~ 🌸Let's enjoy it!
|
package/index.js
CHANGED
|
@@ -11,14 +11,14 @@ const __filename = fileURLToPath(import.meta.url)
|
|
|
11
11
|
const __dirname = path.dirname(__filename)
|
|
12
12
|
|
|
13
13
|
// ---------------- 1. 配置项 ----------------
|
|
14
|
-
const CLASH_BIN_PATH = path.join(__dirname, 'clash-
|
|
14
|
+
const CLASH_BIN_PATH = path.join(__dirname, 'clash-kit') // 解压后的二进制文件路径
|
|
15
15
|
const CLASH_CONFIG_PATH = path.join(__dirname, 'config.yaml') // 配置文件路径
|
|
16
16
|
|
|
17
17
|
// ---------------- 2. 启动 Clash.Meta 进程 ----------------
|
|
18
18
|
function startClash() {
|
|
19
19
|
// 尝试停止已存在的进程
|
|
20
20
|
try {
|
|
21
|
-
execSync('pkill -f clash-
|
|
21
|
+
execSync('pkill -f clash-kit')
|
|
22
22
|
} catch (e) {
|
|
23
23
|
// 忽略错误,说明没有运行中的进程
|
|
24
24
|
}
|
|
@@ -65,7 +65,7 @@ async function cleanup() {
|
|
|
65
65
|
|
|
66
66
|
// 停止 Clash 进程
|
|
67
67
|
try {
|
|
68
|
-
execSync('pkill -f clash-
|
|
68
|
+
execSync('pkill -f clash-kit')
|
|
69
69
|
console.log('Clash 服务已停止')
|
|
70
70
|
} catch (e) {
|
|
71
71
|
// 进程可能已经停止
|
|
@@ -101,7 +101,7 @@ function setupExitHandlers() {
|
|
|
101
101
|
|
|
102
102
|
// ---------------- 5. 执行流程 ----------------
|
|
103
103
|
export function main() {
|
|
104
|
-
// 检查 clash-
|
|
104
|
+
// 检查 clash-kit 二进制文件是否存在
|
|
105
105
|
if (!fs.existsSync(CLASH_BIN_PATH)) {
|
|
106
106
|
return console.error(chalk.red('\n找不到 Clash.Meta 内核文件,请先运行 clash init 命令初始化内核!\n'))
|
|
107
107
|
}
|
|
@@ -118,7 +118,7 @@ export function main() {
|
|
|
118
118
|
|
|
119
119
|
console.log(chalk.green('\n代理服务已在后台启动✅'))
|
|
120
120
|
if (clashProcess.pid) {
|
|
121
|
-
console.log(
|
|
121
|
+
console.log(`进程名称:${chalk.yellow('clash-kit')} PID: ${chalk.yellow(clashProcess.pid)}`)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
console.log(``)
|
|
@@ -126,7 +126,13 @@ export function main() {
|
|
|
126
126
|
console.log(`SOCKS5 Proxy: ${chalk.cyan(`127.0.0.1:${socks}`)}`)
|
|
127
127
|
console.log(`API: ${chalk.cyan.underline(getApiBase())}`)
|
|
128
128
|
console.log(``)
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
console.log(chalk.gray('运行日志文件: ' + path.join(__dirname, 'clash.log')))
|
|
131
|
+
console.log(chalk.blue('提示:如需查看运行状态可使用 clash status 命令'))
|
|
132
|
+
console.log(chalk.blue('如需停止代理可使用 clash stop 命令'))
|
|
133
|
+
console.log(chalk.gray('----------------------------------------'))
|
|
134
|
+
console.log(chalk.gray('如需切换系统代理模式可使用 clash sysproxy on/off 命令'))
|
|
135
|
+
console.log(chalk.gray('如需切换 TUN 模式可使用 clash tun on/off 命令'))
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
// 运行脚本
|
package/lib/commands/init.js
CHANGED
|
@@ -56,7 +56,7 @@ async function downloadResource(resource, targetDir) {
|
|
|
56
56
|
|
|
57
57
|
export async function init(options) {
|
|
58
58
|
const rootDir = path.join(__dirname, '../..')
|
|
59
|
-
const binName = process.platform === 'win32' ? 'clash-
|
|
59
|
+
const binName = process.platform === 'win32' ? 'clash-kit.exe' : 'clash-kit'
|
|
60
60
|
const binPath = path.join(rootDir, binName)
|
|
61
61
|
const configPath = path.join(rootDir, 'config.yaml')
|
|
62
62
|
|
package/lib/commands/stop.js
CHANGED
|
@@ -17,9 +17,9 @@ export async function stop() {
|
|
|
17
17
|
console.log('TUN 模式已关闭')
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// 使用 pkill 匹配进程名包含 clash-
|
|
20
|
+
// 使用 pkill 匹配进程名包含 clash-kit 的进程
|
|
21
21
|
spinner.text = '正在停止 Clash 服务...'
|
|
22
|
-
execSync('pkill -f clash-
|
|
22
|
+
execSync('pkill -f clash-kit')
|
|
23
23
|
spinner.succeed('Clash 服务已停止')
|
|
24
24
|
} catch (err) {
|
|
25
25
|
// pkill 如果没找到进程会抛出错误,这里捕获并提示
|
package/lib/kernel.js
CHANGED
|
@@ -52,7 +52,7 @@ export async function downloadClash(targetDir) {
|
|
|
52
52
|
const downloadUrl = `https://github.com/MetaCubeX/mihomo/releases/download/${version}/${name}-${version}.${urlExt}`
|
|
53
53
|
const tempFileName = `mihomo-temp.${urlExt}`
|
|
54
54
|
const tempPath = path.join(targetDir, tempFileName)
|
|
55
|
-
const targetBinName = `clash-
|
|
55
|
+
const targetBinName = `clash-kit${isWin ? '.exe' : ''}`
|
|
56
56
|
const targetBinPath = path.join(targetDir, targetBinName)
|
|
57
57
|
|
|
58
58
|
// 3. 下载文件
|
package/lib/tun.js
CHANGED
|
@@ -8,7 +8,7 @@ import { reloadConfig } from './api.js'
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
9
|
const __dirname = path.dirname(__filename)
|
|
10
10
|
const CONFIG_PATH = path.join(__dirname, '../config.yaml')
|
|
11
|
-
const BIN_PATH = path.join(__dirname, '../clash-
|
|
11
|
+
const BIN_PATH = path.join(__dirname, '../clash-kit')
|
|
12
12
|
|
|
13
13
|
export function checkTunPermissions() {
|
|
14
14
|
if (process.platform === 'win32') return true // Windows 需要管理员权限终端,难以通过文件属性判断
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clash-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A command-line interface for managing Clash configurations, subscriptions, and proxies.",
|
|
6
6
|
"bin": {
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"bin",
|
|
12
12
|
"lib",
|
|
13
|
-
"
|
|
14
|
-
"country.mmdb",
|
|
13
|
+
".gitignore",
|
|
15
14
|
"default.yaml",
|
|
15
|
+
"country.mmdb",
|
|
16
|
+
"index.js",
|
|
17
|
+
"LICENSE.md",
|
|
16
18
|
"package.json",
|
|
17
19
|
"README.md"
|
|
18
20
|
],
|