skillfree 0.1.40 → 0.1.41
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/skillfree.js +34 -6
- package/package.json +1 -1
package/bin/skillfree.js
CHANGED
|
@@ -105,13 +105,41 @@ program
|
|
|
105
105
|
.command('update')
|
|
106
106
|
.description('更新 skillfree 到最新版本')
|
|
107
107
|
.action(async () => {
|
|
108
|
-
const { execSync } = require('child_process')
|
|
109
|
-
|
|
108
|
+
const { execSync, spawnSync } = require('child_process')
|
|
109
|
+
const currentVersion = pkg.version
|
|
110
|
+
|
|
111
|
+
// 查最新版本号
|
|
112
|
+
let latestVersion = '(unknown)'
|
|
110
113
|
try {
|
|
111
|
-
execSync('npm
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
latestVersion = execSync('npm show skillfree version 2>/dev/null', { encoding: 'utf8' }).trim()
|
|
115
|
+
} catch {}
|
|
116
|
+
|
|
117
|
+
console.log(`\n🦞 SkillFree 更新`)
|
|
118
|
+
console.log(` 当前版本:v${currentVersion}`)
|
|
119
|
+
console.log(` 最新版本:v${latestVersion}`)
|
|
120
|
+
|
|
121
|
+
if (currentVersion === latestVersion) {
|
|
122
|
+
console.log(`\n✅ 已经是最新版本,无需更新\n`)
|
|
123
|
+
process.exit(0)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(`\n🔄 正在更新 v${currentVersion} → v${latestVersion} ...\n`)
|
|
127
|
+
|
|
128
|
+
// 尝试直接安装,失败则 sudo
|
|
129
|
+
const tryInstall = (useSudo) => {
|
|
130
|
+
const cmd = useSudo
|
|
131
|
+
? ['sudo', 'npm', 'install', '-g', 'skillfree@latest']
|
|
132
|
+
: ['npm', 'install', '-g', 'skillfree@latest']
|
|
133
|
+
const result = spawnSync(cmd[0], cmd.slice(1), { stdio: 'inherit' })
|
|
134
|
+
return result.status === 0
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (tryInstall(false) || tryInstall(true)) {
|
|
138
|
+
console.log(`\n✅ 更新成功!已升级到 v${latestVersion}`)
|
|
139
|
+
console.log(` 新功能请查看:https://skillfree.tech\n`)
|
|
140
|
+
} else {
|
|
141
|
+
console.error('\n❌ 更新失败,请手动执行:')
|
|
142
|
+
console.error(' npm install -g skillfree@latest\n')
|
|
115
143
|
process.exit(1)
|
|
116
144
|
}
|
|
117
145
|
})
|