@simonyea/holysheep-cli 1.1.4 → 1.1.6
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/README.md +2 -2
- package/package.json +1 -1
- package/src/commands/setup.js +11 -15
- package/src/index.js +29 -0
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ npm install -g @simonyea/holysheep-cli
|
|
|
58
58
|
No npm? Try npx (no install needed):
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
npx @simonyea/holysheep-cli setup
|
|
61
|
+
npx @simonyea/holysheep-cli@latest setup
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
### Quick Start
|
|
@@ -152,7 +152,7 @@ npm install -g @simonyea/holysheep-cli
|
|
|
152
152
|
没有 npm?用 npx 免安装直接运行:
|
|
153
153
|
|
|
154
154
|
```bash
|
|
155
|
-
npx @simonyea/holysheep-cli setup
|
|
155
|
+
npx @simonyea/holysheep-cli@latest setup
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
### 快速开始
|
package/package.json
CHANGED
package/src/commands/setup.js
CHANGED
|
@@ -45,19 +45,13 @@ async function tryAutoInstall(tool) {
|
|
|
45
45
|
spinner.fail(`安装失败,请手动运行: ${chalk.cyan(info.cmd)}`)
|
|
46
46
|
return false
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// 安装后重新检测
|
|
54
|
-
if (tool.checkInstalled()) {
|
|
55
|
-
spinner.succeed(`${tool.name} 安装成功`)
|
|
56
|
-
return true
|
|
57
|
-
} else {
|
|
58
|
-
spinner.fail(`${tool.name} 安装后仍未检测到,请手动安装: ${chalk.cyan(info.cmd)}`)
|
|
59
|
-
return false
|
|
48
|
+
spinner.succeed(`${tool.name} 安装成功`)
|
|
49
|
+
// Windows PATH 在当前进程内不会刷新,但安装已成功,直接继续配置
|
|
50
|
+
// 非 Windows 再额外做一次检测
|
|
51
|
+
if (process.platform !== 'win32' && !tool.checkInstalled()) {
|
|
52
|
+
console.log(chalk.yellow(` ⚠ 安装后未检测到命令,尝试直接配置...`))
|
|
60
53
|
}
|
|
54
|
+
return true // 安装成功就视为可配置
|
|
61
55
|
} catch (e) {
|
|
62
56
|
spinner.fail(`安装失败: ${e.message}`)
|
|
63
57
|
return false
|
|
@@ -138,6 +132,7 @@ async function setup(options) {
|
|
|
138
132
|
const selectedTools = TOOLS.filter(t => toolIds.includes(t.id))
|
|
139
133
|
const needInstall = selectedTools.filter(t => !t.checkInstalled() && canAutoInstall(t.id))
|
|
140
134
|
const cantInstall = selectedTools.filter(t => !t.checkInstalled() && !canAutoInstall(t.id))
|
|
135
|
+
const justInstalled = new Set() // 记录本次刚安装成功的工具 id
|
|
141
136
|
|
|
142
137
|
// 提示不能自动安装的工具
|
|
143
138
|
if (cantInstall.length) {
|
|
@@ -157,16 +152,17 @@ async function setup(options) {
|
|
|
157
152
|
|
|
158
153
|
if (doInstall) {
|
|
159
154
|
for (const tool of needInstall) {
|
|
160
|
-
await tryAutoInstall(tool)
|
|
155
|
+
const ok = await tryAutoInstall(tool)
|
|
156
|
+
if (ok) justInstalled.add(tool.id)
|
|
161
157
|
}
|
|
162
158
|
console.log()
|
|
163
159
|
}
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
// Step 4:
|
|
162
|
+
// Step 4: 配置每个已安装的工具(包含刚刚安装成功的)
|
|
167
163
|
const envVarsToWrite = {}
|
|
168
164
|
const results = []
|
|
169
|
-
const toConfigureTools = selectedTools.filter(t => t.checkInstalled())
|
|
165
|
+
const toConfigureTools = selectedTools.filter(t => t.checkInstalled() || justInstalled.has(t.id))
|
|
170
166
|
|
|
171
167
|
if (toConfigureTools.length === 0) {
|
|
172
168
|
console.log(chalk.yellow('没有可配置的工具(请先安装),退出。'))
|
package/src/index.js
CHANGED
|
@@ -13,6 +13,34 @@ if (process.platform === 'win32') {
|
|
|
13
13
|
} catch {}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// 异步检查最新版本(不阻塞主流程)
|
|
17
|
+
function checkLatestVersion() {
|
|
18
|
+
try {
|
|
19
|
+
const https = require('https')
|
|
20
|
+
const req = https.get(
|
|
21
|
+
`https://registry.npmjs.org/@simonyea/holysheep-cli/latest`,
|
|
22
|
+
{ timeout: 3000 },
|
|
23
|
+
(res) => {
|
|
24
|
+
let data = ''
|
|
25
|
+
res.on('data', chunk => { data += chunk })
|
|
26
|
+
res.on('end', () => {
|
|
27
|
+
try {
|
|
28
|
+
const latest = JSON.parse(data).version
|
|
29
|
+
if (latest && latest !== pkg.version) {
|
|
30
|
+
console.log()
|
|
31
|
+
console.log(chalk.yellow(`⚠️ 发现新版本 v${latest}(当前 v${pkg.version})`))
|
|
32
|
+
console.log(chalk.cyan(` 建议运行: npx @simonyea/holysheep-cli@latest setup`))
|
|
33
|
+
console.log(chalk.gray(` 或更新: npm install -g @simonyea/holysheep-cli@latest`))
|
|
34
|
+
}
|
|
35
|
+
} catch {}
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
req.on('error', () => {})
|
|
40
|
+
req.setTimeout(3000, () => req.destroy())
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
|
|
16
44
|
// Banner
|
|
17
45
|
function printBanner() {
|
|
18
46
|
console.log()
|
|
@@ -66,6 +94,7 @@ program
|
|
|
66
94
|
.option('-a, --all', '配置所有已安装的工具(跳过选择)')
|
|
67
95
|
.action(async (opts) => {
|
|
68
96
|
printBanner()
|
|
97
|
+
checkLatestVersion() // 异步检查版本,不阻塞
|
|
69
98
|
await require('./commands/setup')(opts)
|
|
70
99
|
})
|
|
71
100
|
|