clash-kit 1.0.5 → 1.0.7

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/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from 'commander'
4
+ import { createRequire } from 'module'
4
5
  import { init } from '../lib/commands/init.js'
5
6
  import { start } from '../lib/commands/start.js'
6
7
  import { stop } from '../lib/commands/stop.js'
@@ -11,9 +12,12 @@ import { manageSub } from '../lib/commands/sub.js'
11
12
  import { proxy } from '../lib/commands/proxy.js'
12
13
  import { test } from '../lib/commands/test.js'
13
14
 
15
+ const require = createRequire(import.meta.url)
16
+ const pkg = require('../package.json')
17
+
14
18
  const program = new Command()
15
19
 
16
- program.name('clash').alias('ck').description('Clash CLI 管理工具 (Alias: ck)').version('1.0.0')
20
+ program.name('clash').alias('ck').description('Clash CLI 管理工具 (Alias: ck)').version(pkg.version, '-v, --version')
17
21
 
18
22
  // 初始化 clash 内核
19
23
  program
@@ -73,4 +77,9 @@ program
73
77
  .description('节点测速 (别名: list, ls, test, t) ')
74
78
  .action(test)
75
79
 
80
+ // Support -V for version
81
+ if (process.argv.includes('-V')) {
82
+ process.argv[process.argv.indexOf('-V')] = '-v'
83
+ }
84
+
76
85
  program.parse(process.argv)
package/index.js CHANGED
@@ -15,8 +15,8 @@ const __filename = fileURLToPath(import.meta.url)
15
15
  const __dirname = path.dirname(__filename)
16
16
 
17
17
  // ---------------- 配置项 ----------------
18
- const CLASH_BIN_PATH = path.join(__dirname, 'clash-kit') // 解压后的二进制文件路径
19
- const CLASH_CONFIG_PATH = path.join(__dirname, 'config.yaml') // 配置文件路径
18
+ export const CLASH_BIN_PATH = path.join(__dirname, 'clash-kit') // 解压后的二进制文件路径
19
+ export const CLASH_CONFIG_PATH = path.join(__dirname, 'config.yaml') // 配置文件路径
20
20
 
21
21
  async function checkPorts() {
22
22
  try {
@@ -4,6 +4,7 @@ import fs from 'fs'
4
4
  import { fileURLToPath } from 'url'
5
5
  import chalk from 'chalk'
6
6
  import * as sub from '../subscription.js'
7
+ import { CLASH_BIN_PATH } from '../../index.js'
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url)
9
10
  const __dirname = path.dirname(__filename)
@@ -22,6 +23,11 @@ async function handleAddSubscription(url, name) {
22
23
  }
23
24
 
24
25
  export async function manageSub(options) {
26
+ // 检查 clash-kit 二进制文件是否存在
27
+ if (!fs.existsSync(CLASH_BIN_PATH)) {
28
+ return console.error(chalk.red('\n找不到 Clash.Meta 内核文件,请先运行 clash init 命令初始化内核!\n'))
29
+ }
30
+
25
31
  if (options.add) {
26
32
  if (!options.name) return console.error('错误: 添加订阅时必须指定名称 (-n)')
27
33
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clash-kit",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "A command-line interface for managing Clash configurations, subscriptions, and proxies.",
6
6
  "bin": {