@simonyea/holysheep-cli 1.7.8 → 1.7.10
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/package.json +1 -1
- package/src/commands/setup.js +26 -1
- package/src/index.js +3 -2
- package/src/utils/shell.js +48 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simonyea/holysheep-cli",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.10",
|
|
4
4
|
"description": "Claude Code/Cursor/Cline API relay for China — ¥1=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openai-china",
|
package/src/commands/setup.js
CHANGED
|
@@ -7,7 +7,11 @@ const ora = require('ora')
|
|
|
7
7
|
const { execSync, spawnSync } = require('child_process')
|
|
8
8
|
const pkg = require('../../package.json')
|
|
9
9
|
const { saveConfig, getApiKey, BASE_URL_ANTHROPIC, BASE_URL_OPENAI, SHOP_URL } = require('../utils/config')
|
|
10
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
writeEnvToShell,
|
|
12
|
+
ensureWindowsUserPathHasNpmBin,
|
|
13
|
+
installWindowsCliShims,
|
|
14
|
+
} = require('../utils/shell')
|
|
11
15
|
const { commandExists } = require('../utils/which')
|
|
12
16
|
const TOOLS = require('../tools')
|
|
13
17
|
|
|
@@ -29,6 +33,10 @@ const AUTO_INSTALL = {
|
|
|
29
33
|
function getWindowsImmediateLaunchCmd(tool) {
|
|
30
34
|
if (process.platform !== 'win32' || !tool?.launchCmd) return null
|
|
31
35
|
|
|
36
|
+
if (/^npx\b/i.test(tool.launchCmd)) {
|
|
37
|
+
return tool.launchCmd
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
const [cmdBin, ...cmdArgs] = tool.launchCmd.split(' ')
|
|
33
41
|
|
|
34
42
|
try {
|
|
@@ -48,6 +56,10 @@ function getWindowsImmediateLaunchCmd(tool) {
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
function getPreferredCliPrefix() {
|
|
59
|
+
if (process.platform === 'win32') {
|
|
60
|
+
return 'npx @simonyea/holysheep-cli@latest'
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
const mainEntry = String(require.main?.filename || '')
|
|
52
64
|
const runningFromNpxCache =
|
|
53
65
|
/[\\/]_npx[\\/]/i.test(mainEntry) ||
|
|
@@ -114,6 +126,14 @@ async function tryAutoInstall(tool) {
|
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
async function setup(options) {
|
|
129
|
+
let windowsCliArtifacts = []
|
|
130
|
+
if (process.platform === 'win32') {
|
|
131
|
+
windowsCliArtifacts = [
|
|
132
|
+
...installWindowsCliShims(),
|
|
133
|
+
...ensureWindowsUserPathHasNpmBin(),
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
|
|
117
137
|
console.log()
|
|
118
138
|
console.log(chalk.bold('🐑 HolySheep CLI — 一键配置 AI 工具'))
|
|
119
139
|
console.log(chalk.gray('━'.repeat(50)))
|
|
@@ -314,6 +334,11 @@ async function setup(options) {
|
|
|
314
334
|
}
|
|
315
335
|
}
|
|
316
336
|
|
|
337
|
+
if (process.platform === 'win32' && windowsCliArtifacts.length > 0) {
|
|
338
|
+
console.log(chalk.gray(`Windows 启动器已就绪: ${windowsCliArtifacts.map(item => chalk.cyan(item)).join(', ')}`))
|
|
339
|
+
console.log()
|
|
340
|
+
}
|
|
341
|
+
|
|
317
342
|
// Step 6: 保存 API Key
|
|
318
343
|
saveConfig({ apiKey })
|
|
319
344
|
|
package/src/index.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
const { program } = require('commander')
|
|
5
5
|
const chalk = require('chalk')
|
|
6
6
|
const pkg = require('../package.json')
|
|
7
|
+
const { installWindowsCliShims, ensureWindowsUserPathHasNpmBin } = require('./utils/shell')
|
|
7
8
|
|
|
8
9
|
// Windows 用户:检测 npm bin 路径是否在 PATH 中
|
|
9
10
|
if (process.platform === 'win32') {
|
|
10
|
-
const { execSync } = require('child_process')
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
installWindowsCliShims()
|
|
13
|
+
ensureWindowsUserPathHasNpmBin()
|
|
13
14
|
} catch {}
|
|
14
15
|
}
|
|
15
16
|
|
package/src/utils/shell.js
CHANGED
|
@@ -109,6 +109,46 @@ function ensureWindowsUserPathHasNpmBin() {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
function installWindowsCliShims() {
|
|
113
|
+
if (process.platform !== 'win32') return []
|
|
114
|
+
|
|
115
|
+
const appData = process.env.APPDATA
|
|
116
|
+
if (!appData) return []
|
|
117
|
+
|
|
118
|
+
const npmBin = path.join(appData, 'npm')
|
|
119
|
+
fs.mkdirSync(npmBin, { recursive: true })
|
|
120
|
+
|
|
121
|
+
const cmdContent = [
|
|
122
|
+
'@echo off',
|
|
123
|
+
'setlocal',
|
|
124
|
+
'if exist "%~dp0npx.cmd" (',
|
|
125
|
+
' call "%~dp0npx.cmd" @simonyea/holysheep-cli@latest %*',
|
|
126
|
+
') else (',
|
|
127
|
+
' call npx @simonyea/holysheep-cli@latest %*',
|
|
128
|
+
')',
|
|
129
|
+
''
|
|
130
|
+
].join('\r\n')
|
|
131
|
+
|
|
132
|
+
const ps1Content = [
|
|
133
|
+
'$npxCmd = Join-Path $PSScriptRoot "npx.cmd"',
|
|
134
|
+
'if (Test-Path $npxCmd) {',
|
|
135
|
+
' & $npxCmd "@simonyea/holysheep-cli@latest" @args',
|
|
136
|
+
'} else {',
|
|
137
|
+
' & npx "@simonyea/holysheep-cli@latest" @args',
|
|
138
|
+
'}',
|
|
139
|
+
''
|
|
140
|
+
].join('\r\n')
|
|
141
|
+
|
|
142
|
+
const written = []
|
|
143
|
+
for (const name of ['hs', 'holysheep']) {
|
|
144
|
+
fs.writeFileSync(path.join(npmBin, `${name}.cmd`), cmdContent, 'utf8')
|
|
145
|
+
fs.writeFileSync(path.join(npmBin, `${name}.ps1`), ps1Content, 'utf8')
|
|
146
|
+
written.push(`[启动器] %APPDATA%\\npm\\${name}.cmd`)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return written
|
|
150
|
+
}
|
|
151
|
+
|
|
112
152
|
function writeEnvToShell(envVars) {
|
|
113
153
|
// Windows: 用 setx 写入用户级环境变量(需重启终端生效)
|
|
114
154
|
if (process.platform === 'win32') {
|
|
@@ -119,6 +159,7 @@ function writeEnvToShell(envVars) {
|
|
|
119
159
|
written.push(`[系统环境变量] ${k}`)
|
|
120
160
|
} catch {}
|
|
121
161
|
}
|
|
162
|
+
written.push(...installWindowsCliShims())
|
|
122
163
|
written.push(...ensureWindowsUserPathHasNpmBin())
|
|
123
164
|
if (written.length > 0) {
|
|
124
165
|
const chalk = require('chalk')
|
|
@@ -174,4 +215,10 @@ function escapeRegex(s) {
|
|
|
174
215
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
175
216
|
}
|
|
176
217
|
|
|
177
|
-
module.exports = {
|
|
218
|
+
module.exports = {
|
|
219
|
+
getShellRcFiles,
|
|
220
|
+
writeEnvToShell,
|
|
221
|
+
removeEnvFromShell,
|
|
222
|
+
ensureWindowsUserPathHasNpmBin,
|
|
223
|
+
installWindowsCliShims
|
|
224
|
+
}
|