dsh-pick 0.5.1 → 0.5.3
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 +14 -1
- package/data/catalog.json +1 -1
- package/lib/boards.js +24 -5
- package/lib/engine.js +169 -8
- package/lib/github.js +2 -2
- package/lib/market-index.js +131 -0
- package/lib/market-source.js +68 -0
- package/lib/remote.js +1 -1
- package/package.json +6 -2
- package/plugin/client.js +37 -3
- package/plugin/index.js +72 -2
- package/web/panel.html +20 -17
- package/web/panel.js +28 -39
package/plugin/index.js
CHANGED
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
// GET /api-dsh-pick/catalog.json 目录(含排名、链接、去噪指标)
|
|
12
12
|
// GET /api-dsh-pick/meta 目录概要(更新时间、包数、来源)
|
|
13
13
|
// GET /api-dsh-pick/update 本插件版本 + npm 上的最新版本
|
|
14
|
-
// POST /api-dsh-pick/update 更新到 npm 最新版(交给 DSH
|
|
14
|
+
// POST /api-dsh-pick/update 更新到 npm 最新版(交给 DSH 的插件管理器,优先用 updateBundle)
|
|
15
15
|
// POST /api-dsh-pick/uninstall 从 DSH 卸载本插件
|
|
16
16
|
// GET /api-dsh-pick/installed DSH 里已装的插件名(面板的「已安装」标记)
|
|
17
17
|
// GET /api-dsh-pick/live?names=a,b 实时查 npm(「我的监控」的刷新,最多 30 个)
|
|
18
|
+
// GET /api-dsh-pick/market dsh-pick 的插件索引在不在 DSH「插件 → 发现」的索引源里
|
|
19
|
+
// POST /api-dsh-pick/market 把它加进去(设置页的按钮)
|
|
20
|
+
//
|
|
21
|
+
// 启动时还会自动把插件索引加进「发现」一次(lib/market-source.js),用户删掉后不再自动加。
|
|
18
22
|
// POST /api-dsh-pick/install 安装目录里的某个插件 { name }
|
|
19
23
|
//
|
|
20
24
|
// 另外注册 4 个 AI 工具(plugin/tools.js):对话里的 AI 能自己查目录、比较插件。
|
|
@@ -27,6 +31,7 @@ import { join } from 'node:path'
|
|
|
27
31
|
import { registerTools } from './tools.js'
|
|
28
32
|
import { loadCatalog, liveStats, parseWatchNames } from '../lib/engine.js'
|
|
29
33
|
import { refreshCatalog, remoteState, CHECK_EVERY_MS } from '../lib/remote.js'
|
|
34
|
+
import { ensureMarketSource, marketStatus } from '../lib/market-source.js'
|
|
30
35
|
|
|
31
36
|
/** 本包根目录:插件就是完整的 dsh-pick 包 */
|
|
32
37
|
const PKG_ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
@@ -126,6 +131,38 @@ function managerError(result) {
|
|
|
126
131
|
return detail ? `${code}:${detail}` : code
|
|
127
132
|
}
|
|
128
133
|
|
|
134
|
+
/** 这个 DSH 能不能在运行中更新插件:新版有 updateBundle,老版只有 installBundle(还不一定成,见上) */
|
|
135
|
+
function canUpdateHere(pluginManager) {
|
|
136
|
+
return Boolean(pluginManager && (typeof pluginManager.updateBundle === 'function' || typeof pluginManager.installBundle === 'function'))
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 新版 DSH 的 updateBundle 答复 → 给面板的答复。答复的结构见官方仓库 packages/boot/plugin-manager:
|
|
141
|
+
* { from, to, step: 'check' | 'remove' | 'install', result: ChangeResult, restore?: ChangeResult }
|
|
142
|
+
* result 是最后跑的那一步;restore 只在「旧版已卸、新版没装成」时才有,是把旧版装回去的结果。
|
|
143
|
+
*/
|
|
144
|
+
function updateReply(update, latest, command) {
|
|
145
|
+
const change = update && update.result
|
|
146
|
+
if (!change) return { ok: false, message: '更新失败(DSH 没有给出结果)', command }
|
|
147
|
+
const err = managerError(change)
|
|
148
|
+
if (!err) {
|
|
149
|
+
// pnpm 的 minimumReleaseAge 可能让实际装上的比 npm 最新版旧,以 DSH 报的版本为准
|
|
150
|
+
return { ok: true, version: change.version || latest, restart: change.application === 'restart-required' }
|
|
151
|
+
}
|
|
152
|
+
const retry = '也可以完全退出 DSH,在终端执行下面的命令'
|
|
153
|
+
if (update.step === 'check') {
|
|
154
|
+
// 这个新版要求更高版本的 DSH,命令行也装不上,就不给命令了
|
|
155
|
+
if (managerCode(change) === 'incompatible-version') return { ok: false, message: `v${latest} 和这个版本的 DSH 不兼容,先升级 DSH 再更新` }
|
|
156
|
+
return { ok: false, message: `更新被拒绝,什么都没改(${err})。${retry}`, command }
|
|
157
|
+
}
|
|
158
|
+
if (update.step === 'remove') return { ok: false, message: `卸载旧版 v${update.from} 失败,没有更新(${err})。${retry}`, command }
|
|
159
|
+
if (!update.restore) return { ok: false, message: `更新失败,还是 v${update.from}(${err})。${retry}`, command }
|
|
160
|
+
if (managerError(update.restore)) {
|
|
161
|
+
return { ok: false, message: `更新失败(${err}),旧版 v${update.from} 也没能装回去,dsh-pick 现在已经不在了。请完全退出 DSH,在终端执行下面的命令重新安装`, command }
|
|
162
|
+
}
|
|
163
|
+
return { ok: false, message: `更新失败,已经装回旧版 v${update.from}(${err})。${retry}`, command }
|
|
164
|
+
}
|
|
165
|
+
|
|
129
166
|
/** 读请求体里的 JSON(最多 16 KB,这里只收很小的参数) */
|
|
130
167
|
function readJsonBody(req) {
|
|
131
168
|
return new Promise((resolve) => {
|
|
@@ -222,6 +259,15 @@ export function apply(ctx) {
|
|
|
222
259
|
profile = ctx.get && ctx.get('profileContext') && ctx.get('profileContext').name
|
|
223
260
|
} catch { profile = undefined }
|
|
224
261
|
|
|
262
|
+
// DSH「插件 → 发现」的索引源(实验功能「自定义插件索引」打开时才有这个服务):自动加一次 dsh-pick 的插件索引
|
|
263
|
+
let pluginMarket
|
|
264
|
+
ctx.inject(['pluginMarket'], (mCtx) => {
|
|
265
|
+
pluginMarket = mCtx.pluginMarket || (mCtx.get && mCtx.get('pluginMarket'))
|
|
266
|
+
ensureMarketSource(pluginMarket)
|
|
267
|
+
.then(r => { if (r.status === 'added') console.info('[dsh-pick] 已把插件索引加进「插件 → 发现」') })
|
|
268
|
+
.catch(() => {})
|
|
269
|
+
})
|
|
270
|
+
|
|
225
271
|
// 每日更新的目录:启动时查一次,之后每 6 小时查一次(查不到就继续用手上的)
|
|
226
272
|
const refresh = () => refreshCatalog().catch(() => {})
|
|
227
273
|
const startTimer = setTimeout(refresh, 5000) // 别和 DSH 启动抢网络
|
|
@@ -305,7 +351,7 @@ export function apply(ctx) {
|
|
|
305
351
|
restartPending: installed && running && compareVersions(installed, running) > 0 ? installed : '',
|
|
306
352
|
latest,
|
|
307
353
|
available: Boolean(latest) && compareVersions(latest, current) > 0,
|
|
308
|
-
canInstall:
|
|
354
|
+
canInstall: canUpdateHere(pluginManager),
|
|
309
355
|
command: pluginCommand(`add ${PACKAGE}@${latest || 'latest'}`, profile),
|
|
310
356
|
})
|
|
311
357
|
}
|
|
@@ -314,6 +360,14 @@ export function apply(ctx) {
|
|
|
314
360
|
const command = pluginCommand(`add ${PACKAGE}@${latest || 'latest'}`, profile)
|
|
315
361
|
if (!latest) return sendJson(res, 200, { ok: false, message: '查不到 npm 上的最新版本,检查网络后再试', command })
|
|
316
362
|
if (compareVersions(latest, running) <= 0) return sendJson(res, 200, { ok: false, message: `已经是最新版 v${running}` })
|
|
363
|
+
// 新版 DSH 有专门的 updateBundle,能在运行中直接更新
|
|
364
|
+
if (pluginManager && typeof pluginManager.updateBundle === 'function') {
|
|
365
|
+
try {
|
|
366
|
+
return sendJson(res, 200, updateReply(await pluginManager.updateBundle(PACKAGE, latest), latest, command))
|
|
367
|
+
} catch (e) {
|
|
368
|
+
return sendJson(res, 200, { ok: false, message: `更新失败:${e.message}`, command })
|
|
369
|
+
}
|
|
370
|
+
}
|
|
317
371
|
if (!pluginManager || typeof pluginManager.installBundle !== 'function') {
|
|
318
372
|
return sendJson(res, 200, { ok: false, message: '这个版本的 DSH 不能在这里装插件,请在终端执行命令', command })
|
|
319
373
|
}
|
|
@@ -366,6 +420,22 @@ export function apply(ctx) {
|
|
|
366
420
|
},
|
|
367
421
|
}))
|
|
368
422
|
|
|
423
|
+
// 「发现」的索引源:查状态 / 用户点按钮加进去
|
|
424
|
+
track(ws.register({
|
|
425
|
+
kind: 'exact',
|
|
426
|
+
path: '/api-dsh-pick/market',
|
|
427
|
+
handler: async (req, res) => {
|
|
428
|
+
if (req.method === 'GET') return sendJson(res, 200, await marketStatus(pluginMarket))
|
|
429
|
+
if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
|
|
430
|
+
const r = await ensureMarketSource(pluginMarket, { force: true })
|
|
431
|
+
if (r.status === 'added' || r.status === 'present') return sendJson(res, 200, { ok: true, status: r.status })
|
|
432
|
+
if (r.status === 'unavailable') {
|
|
433
|
+
return sendJson(res, 200, { ok: false, message: '先在 DSH 的「插件」页打开实验功能「自定义插件索引」,「发现」页出来后再点' })
|
|
434
|
+
}
|
|
435
|
+
return sendJson(res, 200, { ok: false, message: `没加上:${r.message || r.status}` })
|
|
436
|
+
},
|
|
437
|
+
}))
|
|
438
|
+
|
|
369
439
|
// 已装的插件(面板卡片上的「已安装」)
|
|
370
440
|
track(ws.register({
|
|
371
441
|
kind: 'exact',
|
package/web/panel.html
CHANGED
|
@@ -118,9 +118,8 @@ table.rank td .arch{font-size:10.5px;color:var(--t3);background:var(--soft);bord
|
|
|
118
118
|
.section h2 .h2-acts{margin-left:auto;display:inline-flex;gap:8px;align-items:center}
|
|
119
119
|
.section h2 .h2-acts .ai{margin-left:0}
|
|
120
120
|
.btn.sm{font-size:11.5px;padding:0 10px;height:24px;border-radius:7px}
|
|
121
|
-
.
|
|
122
|
-
.
|
|
123
|
-
.mon .delta.up{color:var(--ok)}.mon .delta.down{color:var(--bad)}
|
|
121
|
+
.mrow .delta{font-size:10.5px;margin-left:3px}
|
|
122
|
+
.mrow .delta.up{color:var(--ok)}.mrow .delta.down{color:var(--bad)}
|
|
124
123
|
#watchAsOf b{color:var(--t2);font-weight:600}
|
|
125
124
|
.inst{appearance:none;font-family:inherit;font-size:10.5px;font-weight:600;border-radius:6px;padding:2px 9px;cursor:pointer;
|
|
126
125
|
border:1px solid var(--accent);background:var(--panel);color:var(--accent);white-space:nowrap}
|
|
@@ -228,20 +227,24 @@ td.down{color:var(--bad);font-weight:600}
|
|
|
228
227
|
.catpill{font-size:10.5px;background:var(--soft);color:var(--t2);border-radius:20px;padding:2px 8px;white-space:nowrap}
|
|
229
228
|
|
|
230
229
|
/* ---------- 监控 ---------- */
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.
|
|
235
|
-
.
|
|
236
|
-
.
|
|
237
|
-
.
|
|
238
|
-
.
|
|
239
|
-
.
|
|
240
|
-
.
|
|
241
|
-
.
|
|
242
|
-
.
|
|
243
|
-
.
|
|
244
|
-
.
|
|
230
|
+
/* 我的监控:和排行榜一样一行一个插件,上面是列名。名字和最后的图标宽度固定,
|
|
231
|
+
中间各列用 minmax(0, 1fr) 平分剩下的宽度,栏变窄时一起压缩,放不下的用省略号 */
|
|
232
|
+
/* 数字列留够短写数字(312k、#3088)的最小宽度,不会被截断;压缩主要由「分类」承担 */
|
|
233
|
+
#watchList{--mcols:minmax(84px,3.4fr) minmax(36px,.7fr) minmax(0,1.2fr) minmax(40px,.9fr) minmax(32px,.8fr) minmax(30px,.7fr) minmax(36px,.8fr) auto}
|
|
234
|
+
.mrow{display:grid;grid-template-columns:var(--mcols);align-items:center;column-gap:6px;padding:8px 0;border-bottom:1px solid var(--soft);font-size:12px;color:var(--t2)}
|
|
235
|
+
.mrow:last-child{border-bottom:none}
|
|
236
|
+
.mrow.mhead{font-size:11px;color:var(--t3);font-weight:600;padding:0 0 7px;border-bottom:1px solid var(--line)}
|
|
237
|
+
.mrow .mc{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}
|
|
238
|
+
.mrow .mc.r{text-align:right}
|
|
239
|
+
.mrow .mc.span{grid-column:2 / -2;color:var(--t3)}
|
|
240
|
+
.mrow .mc b{color:var(--text);font-weight:650}
|
|
241
|
+
.mrow .nm{font-size:13px;font-weight:650;color:var(--text)}
|
|
242
|
+
.mrow.mhead .nm{font-size:11px;font-weight:600;color:var(--t3)}
|
|
243
|
+
.mrow .ver{color:var(--t3);font-weight:400;font-size:11px}
|
|
244
|
+
.mrow .acts{display:flex;align-items:center;justify-content:flex-end;overflow:visible}
|
|
245
|
+
.mrow .livedot{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--ok);margin-right:5px;vertical-align:middle}
|
|
246
|
+
.mrow .x{appearance:none;border:none;background:none;color:var(--t3);cursor:pointer;font-size:16px;line-height:1;padding:0 2px 0 4px;flex:none}
|
|
247
|
+
.mrow .x:hover{color:var(--bad)}
|
|
245
248
|
|
|
246
249
|
.foot{font-size:11.5px;color:var(--t3);line-height:1.9;margin-top:6px}
|
|
247
250
|
.foot b{color:var(--t2);font-weight:650}
|
package/web/panel.js
CHANGED
|
@@ -850,9 +850,6 @@ async function refreshWatch() {
|
|
|
850
850
|
renderWatch()
|
|
851
851
|
}
|
|
852
852
|
|
|
853
|
-
/** 我的监控里展开着的插件(只在这次打开期间记住) */
|
|
854
|
-
const watchOpen = new Set()
|
|
855
|
-
|
|
856
853
|
function renderWatch() {
|
|
857
854
|
const list = watch()
|
|
858
855
|
$('#watchCount').textContent = list.length ? ` (${list.length})` : ''
|
|
@@ -867,50 +864,42 @@ function renderWatch() {
|
|
|
867
864
|
return
|
|
868
865
|
}
|
|
869
866
|
|
|
870
|
-
|
|
867
|
+
// 像排行榜一样:上面一行是列名,每个插件一行。名字在最前、图标和移除在最后,
|
|
868
|
+
// 中间各列始终都在,右侧栏变窄时一起按比例压缩(放不下的用省略号,悬停看全文)
|
|
869
|
+
const cell = (text, title, cls = '') => `<span class="mc${cls ? ' ' + cls : ''}" title="${esc(title)}">${text}</span>`
|
|
870
|
+
const head = '<div class="mrow mhead">' +
|
|
871
|
+
'<span class="mc nm">插件</span>' +
|
|
872
|
+
[['总榜', 'r', '总榜排名'], ['分类', '', '分类'], ['周下载', 'r', '周下载'], ['基线', 'r', '日常基线'], ['★', 'r', 'GitHub 星标'], ['发版', 'r', '最近一次发版']]
|
|
873
|
+
.map(([t, cls, title]) => `<span class="mc${cls ? ' ' + cls : ''}" title="${title}">${t}</span>`).join('') +
|
|
874
|
+
'<span class="mc acts"></span></div>'
|
|
875
|
+
host.innerHTML = head + list.map(n => {
|
|
871
876
|
const r = watchRec(n)
|
|
872
877
|
const name = r ? esc(r.label || n) : esc(n)
|
|
873
878
|
const ver = r && r.v ? ` <span class="ver">v${esc(r.v)}</span>` : ''
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
detail = (r.live ? '<span class="live" title="刚从 npm / GitHub 查的">实时</span>' : '') +
|
|
885
|
-
`<span class="mrank">${rankText(r)}</span>` +
|
|
886
|
-
`<span>${esc(r.cat)}</span>` +
|
|
887
|
-
(r.w != null ? `<span><b>${num(r.w)}</b>/周${delta}</span>` : '') +
|
|
888
|
-
(r.w != null ? `<span>基线 ${d ? num(d.base) : '—'}</span>` : '') +
|
|
889
|
-
(r.gh ? `<span title="GitHub · 最近提交 ${esc(r.gh.p || '—')}">★ ${short(r.gh.s)}${r.gh.a ? ' · 已归档' : ''}</span>` : '') +
|
|
890
|
-
(d ? `<span>${ageText(d.age)}发版</span>` : '')
|
|
879
|
+
const live = r && r.live ? '<i class="livedot" title="实时数据:刚从 npm / GitHub 查的"></i>' : ''
|
|
880
|
+
const nameCell = `<span class="mc nm" title="${name}${r && r.v ? ' v' + esc(r.v) : ''}">${live}${name}${ver}</span>`
|
|
881
|
+
const acts = `<span class="mc acts">${r ? linkBtns(r, { icon: true }) : ''}<button class="x" data-rm="${esc(n)}" title="从我的监控移除" aria-label="移除 ${name}">×</button></span>`
|
|
882
|
+
if (!r) return `<div class="mrow">${nameCell}<span class="mc span">不在目录中,点「刷新」去 npm 查</span>${acts}</div>`
|
|
883
|
+
const d = r.deep
|
|
884
|
+
// 和目录数据比,周下载涨了还是跌了(只在刷新过、差得明显时标)
|
|
885
|
+
let delta = ''
|
|
886
|
+
if (r.live && r.catalogW) {
|
|
887
|
+
const ch = (r.w - r.catalogW) / Math.max(r.catalogW, 1)
|
|
888
|
+
if (Math.abs(ch) >= 0.05) delta = `<span class="delta ${ch > 0 ? 'up' : 'down'}">${ch > 0 ? '↑' : '↓'}${Math.round(Math.abs(ch) * 100)}%</span>`
|
|
891
889
|
}
|
|
892
|
-
|
|
893
|
-
return
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
`</div>`
|
|
890
|
+
const rankFull = r.rank ? `总榜 #${num(r.rank)}${r.crank ? ` · ${r.cat} #${num(r.crank)}` : ''}` : ''
|
|
891
|
+
return '<div class="mrow">' + nameCell +
|
|
892
|
+
cell(r.rank ? `#${r.rank < 1000 ? r.rank : short(r.rank)}` : '—', rankFull || '不在总榜里', 'r') +
|
|
893
|
+
cell(esc(r.cat || '—'), r.cat || '') +
|
|
894
|
+
cell(r.w != null ? `<b>${short(r.w)}</b>${delta}` : '—', r.w != null ? `周下载 ${num(r.w)}${delta ? `(和目录数据相比 ${delta.replace(/<[^>]+>/g, '')})` : ''}` : '只在 GitHub,没有 npm 数据', 'r') +
|
|
895
|
+
cell(d ? short(d.base) : '—', d ? `日常基线 ${num(d.base)} 次/天` : '没有去噪指标', 'r') +
|
|
896
|
+
cell(r.gh ? `${short(r.gh.s)}${r.gh.a ? ' · 已归档' : ''}` : '—', r.gh ? `GitHub ★ ${num(r.gh.s)}${r.gh.p ? ` · 最近提交 ${r.gh.p}` : ''}${r.gh.a ? ' · 已归档' : ''}` : '没有 GitHub 数据', 'r') +
|
|
897
|
+
cell(d ? ageText(d.age) : '—', d && d.lastRelease ? `最近发版 ${d.lastRelease}` : '', 'r') +
|
|
898
|
+
acts + '</div>'
|
|
902
899
|
}).join('')
|
|
903
900
|
|
|
904
901
|
host.querySelectorAll('[data-rm]').forEach(b =>
|
|
905
902
|
b.addEventListener('click', () => saveWatch(watch().filter(x => x !== b.dataset.rm)) || renderWatch()))
|
|
906
|
-
host.querySelectorAll('[data-toggle]').forEach(row =>
|
|
907
|
-
row.addEventListener('click', e => {
|
|
908
|
-
if (e.target.closest('a, [data-rm]')) return
|
|
909
|
-
const n = row.dataset.toggle
|
|
910
|
-
if (watchOpen.has(n)) watchOpen.delete(n)
|
|
911
|
-
else watchOpen.add(n)
|
|
912
|
-
renderWatch()
|
|
913
|
-
}))
|
|
914
903
|
|
|
915
904
|
// 对数刻度横条图
|
|
916
905
|
const rows = list.map(watchRec).filter(r => r && r.w != null)
|