flower-trellis 0.4.5-beta.0 → 0.4.5-beta.2
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
CHANGED
package/src/lib/update-check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { confirm } from "@inquirer/prompts";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
+
import { readManifest, readUpdateCheck, writeUpdateCheck } from "./manifest.js";
|
|
4
5
|
import { isRunningViaNpx } from "./runtime-env.js";
|
|
5
6
|
import { flowerVersion } from "./versions.js";
|
|
6
7
|
|
|
@@ -173,13 +174,29 @@ export function getUpdateRecommendation(current, tags) {
|
|
|
173
174
|
return null;
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
/** 尽力而为刷新目标项目 manifest 里的远端探测缓存。 */
|
|
178
|
+
function rememberRemoteTags(target, tags, status) {
|
|
179
|
+
try {
|
|
180
|
+
if (!readManifest(target)) return;
|
|
181
|
+
writeUpdateCheck(target, {
|
|
182
|
+
lastCheckedAt: new Date().toISOString(),
|
|
183
|
+
lastRemote: tags,
|
|
184
|
+
lastStatus: status,
|
|
185
|
+
lastErrorCode: null,
|
|
186
|
+
});
|
|
187
|
+
} catch {
|
|
188
|
+
// 缓存写入只是优化后续启动提示,失败不能影响 init/update 主流程。
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
176
192
|
/**
|
|
177
193
|
* 检测 flower-trellis 自身是否有新版本,并按场景提示/引导升级。在 init / update 的
|
|
178
194
|
* 品牌头部之后、主操作之前调用。
|
|
179
195
|
*
|
|
180
196
|
* 短路条件(任一命中即跳过,什么都不打印):关闭开关(`--no-update-check` 使
|
|
181
|
-
* `ctx.updateCheck===false
|
|
182
|
-
*
|
|
197
|
+
* `ctx.updateCheck===false`,目标 manifest 的 `updateCheck.enabled=false` /
|
|
198
|
+
* `policy=off`,或环境变量 `FLOWER_NO_UPDATE_CHECK` 非空)、经 npx 运行、网络探测失败、
|
|
199
|
+
* 无升级推荐。
|
|
183
200
|
*
|
|
184
201
|
* 发现新版时的行为:
|
|
185
202
|
* - 交互 TTY:打印通知 → confirm 询问是否升级 → 同意则执行推荐的 npm install 命令;
|
|
@@ -194,6 +211,8 @@ export function getUpdateRecommendation(current, tags) {
|
|
|
194
211
|
export async function checkForUpdate(ctx, commandLabel) {
|
|
195
212
|
// 1. 关闭开关:显式 flag 或环境变量
|
|
196
213
|
if (ctx.updateCheck === false || process.env.FLOWER_NO_UPDATE_CHECK) return;
|
|
214
|
+
const updateCheck = readUpdateCheck(ctx.target);
|
|
215
|
+
if (!updateCheck.enabled || updateCheck.policy === "off") return;
|
|
197
216
|
// 2. npx 本就是最新版,跳过(连通知都不打,避免误导)
|
|
198
217
|
if (isRunningViaNpx(import.meta.url)) return;
|
|
199
218
|
|
|
@@ -204,6 +223,7 @@ export async function checkForUpdate(ctx, commandLabel) {
|
|
|
204
223
|
// 4. 根据本地版本通道生成推荐;无推荐时不打扰
|
|
205
224
|
const current = flowerVersion();
|
|
206
225
|
const recommendation = getUpdateRecommendation(current, tags);
|
|
226
|
+
rememberRemoteTags(ctx.target, tags, recommendation ? "update_available" : "up_to_date");
|
|
207
227
|
if (!recommendation) return;
|
|
208
228
|
|
|
209
229
|
// 5. 打印发现新版本通知(粉色品牌色,与 banner 一致)
|