dsh-pick 0.3.1 → 0.4.1
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 +29 -23
- package/data/catalog.json +1 -1
- package/lib/engine.js +66 -6
- package/lib/remote.js +93 -0
- package/package.json +5 -1
- package/plugin/client.js +5 -0
- package/plugin/index.js +50 -21
- package/plugin/tools.js +40 -17
- package/web/panel.html +15 -2
- package/web/panel.js +106 -11
package/web/panel.js
CHANGED
|
@@ -131,11 +131,78 @@ async function loadInstalled() {
|
|
|
131
131
|
} catch { /* 拿不到就不显示安装 */ }
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
// 和当前 DSH 兼不兼容:问插件市场(dshmarket)的接口——它按插件声明的 DSH 版本要求算好了,
|
|
135
|
+
// 规则和它的安装检查一致。没装插件市场就不显示这一项(接口 404),只用目录里的安装信息
|
|
136
|
+
const COMPAT = new Map() // 包名 → { status: 'compatible'|'incompatible'|'unknown', requirement }
|
|
137
|
+
let HOST_VERSION = null
|
|
138
|
+
let marketCompat = true
|
|
139
|
+
async function loadCompat(names) {
|
|
140
|
+
if (!IN_DSH || !marketCompat) return
|
|
141
|
+
const want = names.filter(n => !COMPAT.has(n)).slice(0, 64)
|
|
142
|
+
if (!want.length) return
|
|
143
|
+
want.forEach(n => COMPAT.set(n, null)) // 先占位:查不到也不反复查
|
|
144
|
+
try {
|
|
145
|
+
const r = await fetch('/dsh-market/discovery-compatibility', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: { 'content-type': 'application/json' },
|
|
148
|
+
body: JSON.stringify({ packages: want }),
|
|
149
|
+
})
|
|
150
|
+
if (r.status === 404) { marketCompat = false; return }
|
|
151
|
+
if (!r.ok) return
|
|
152
|
+
const j = await r.json()
|
|
153
|
+
HOST_VERSION = j.hostVersion || HOST_VERSION
|
|
154
|
+
for (const [n, v] of Object.entries(j.plugins || {})) COMPAT.set(n, v || null)
|
|
155
|
+
renderCands($('#need').value.trim(), { keepCompat: true })
|
|
156
|
+
} catch { /* 查不到就不显示 */ }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 已装插件里和它同类的(「其他」类不算,太杂) */
|
|
160
|
+
function sameKindInstalled(r) {
|
|
161
|
+
if (!r.cat || r.cat === '其他' || INSTALLED.has(r.n)) return []
|
|
162
|
+
return [...INSTALLED].filter(n => n !== r.n && n !== 'dsh-pick' && CAT.packages[n] && CAT.packages[n].cat === r.cat)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 能不能装、为什么不能:目录里的安装信息(dsh.bundle、客户端平台)+ 插件市场给的兼容结论
|
|
167
|
+
* @returns {{ok: boolean, warn: string[], good: string[]}}
|
|
168
|
+
*/
|
|
169
|
+
function installCheck(r) {
|
|
170
|
+
const warn = []
|
|
171
|
+
const good = []
|
|
172
|
+
let ok = true
|
|
173
|
+
const inst = r.inst
|
|
174
|
+
if (inst && !inst.b) { ok = false; warn.push('没声明 dsh.bundle,DSH 装不了') }
|
|
175
|
+
if (inst && inst.p && inst.p !== 'web') { ok = false; warn.push(`${inst.p} 客户端插件,装进这里可能让 DSH 起不来`) }
|
|
176
|
+
const c = COMPAT.get(r.n)
|
|
177
|
+
if (c && c.status === 'incompatible') {
|
|
178
|
+
ok = false
|
|
179
|
+
warn.push(`和你的 DSH${HOST_VERSION ? ' ' + HOST_VERSION : ''} 不兼容${c.requirement ? `(需要 ${c.requirement})` : ''}`)
|
|
180
|
+
} else if (c && c.status === 'compatible' && ok) {
|
|
181
|
+
// 已经装不了(没 bundle、终端版)就不说「兼容」:版本对得上不等于装得上,两句放一起让人困惑
|
|
182
|
+
good.push(`兼容你的 DSH${HOST_VERSION ? ' ' + HOST_VERSION : ''}`)
|
|
183
|
+
}
|
|
184
|
+
const same = sameKindInstalled(r)
|
|
185
|
+
if (same.length) warn.push(`你已装同类:${same.join('、')}`)
|
|
186
|
+
return { ok, warn, good }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 卡片上的提醒行 */
|
|
190
|
+
function checkRow(r) {
|
|
191
|
+
if (!IN_DSH) return ''
|
|
192
|
+
const { warn, good } = installCheck(r)
|
|
193
|
+
if (!warn.length && !good.length) return ''
|
|
194
|
+
return `<div class="chk">` +
|
|
195
|
+
good.map(t => `<span class="good">✓ ${esc(t)}</span>`).join('') +
|
|
196
|
+
warn.map(t => `<span class="warn">⚠ ${esc(t)}</span>`).join('') +
|
|
197
|
+
`</div>`
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** 卡片上的安装区:已安装 / 安装(点一下变「确认安装」,再点才装)/ 装不了 */
|
|
135
201
|
function installArea(r) {
|
|
136
202
|
if (!IN_DSH) return ''
|
|
137
203
|
if (INSTALLED.has(r.n)) return '<span class="badge-in">✓ 已安装</span>'
|
|
138
204
|
if (!CAN_INSTALL) return ''
|
|
205
|
+
if (!installCheck(r).ok) return '<span class="badge-no" title="原因见卡片上的提醒">不能安装</span>'
|
|
139
206
|
return `<button class="inst" data-install="${esc(r.n)}" title="用 DSH 的插件管理器安装">安装</button>`
|
|
140
207
|
}
|
|
141
208
|
|
|
@@ -184,15 +251,42 @@ function rankText(rec) {
|
|
|
184
251
|
}
|
|
185
252
|
|
|
186
253
|
const GH_SVG = '<svg viewBox="0 0 16 16" width="13" height="13" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.4 7.4 0 0 1 2-.27c.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A7.99 7.99 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>'
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
254
|
+
// npm 的方块标志(中间一个 n):缩到 13px 也认得出;颜色用 npm 的红
|
|
255
|
+
const NPM_SVG = '<svg viewBox="0 0 16 16" width="13" height="13"><path fill="#cb3837" d="M0 0h16v16H0z"/><path fill="#fff" d="M3 3h10v10h-2.5V5.5H8V13H3z"/></svg>'
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 外链按钮。icon = 只要图标(排行榜这种窄列):悬停看得到完整地址
|
|
259
|
+
*/
|
|
260
|
+
function linkBtns(rec, { icon = false } = {}) {
|
|
261
|
+
const npm = rec.npmUrl || ('https://www.npmjs.com/package/' + rec.n)
|
|
262
|
+
const cls = icon ? 'lk ic' : 'lk'
|
|
190
263
|
let h = ''
|
|
191
264
|
if (rec.ghUrl) {
|
|
192
|
-
h += `<a class="
|
|
265
|
+
h += `<a class="${cls}" href="${esc(rec.ghUrl)}" target="_blank" rel="noopener" title="GitHub:${esc(rec.ghUrl)}" aria-label="GitHub">${GH_SVG}${icon ? '' : 'GitHub'}</a>`
|
|
193
266
|
}
|
|
194
|
-
h += `<a class="
|
|
195
|
-
return h
|
|
267
|
+
h += `<a class="${cls}" href="${esc(npm)}" target="_blank" rel="noopener" title="npm:${esc(npm)}" aria-label="npm">${NPM_SVG}${icon ? '' : 'npm'}</a>`
|
|
268
|
+
return h
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** 最近一次发版:今天 / 昨天 / N天前 / N个月前 */
|
|
272
|
+
function ageText(age) {
|
|
273
|
+
if (age == null) return '—'
|
|
274
|
+
if (age <= 0) return '今天'
|
|
275
|
+
if (age === 1) return '昨天'
|
|
276
|
+
if (age < 60) return `${age}天前`
|
|
277
|
+
return `${Math.round(age / 30)}个月前`
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 「更新」一格:上面最近一次发版,下面小字写版本节奏。两行都不折行,
|
|
282
|
+
* 比分成两列(窄栏里每列都被挤成「8 / 天 / 前」三行)省地方也整齐。超过 90 天没发版用提醒色
|
|
283
|
+
*/
|
|
284
|
+
function maintCell(d) {
|
|
285
|
+
if (!d) return '<td class="r mt">—</td>'
|
|
286
|
+
const stale = d.age != null && d.age > 90
|
|
287
|
+
const cad = d.cadence == null ? '' : `<div class="sub">${d.cadence}天/版</div>`
|
|
288
|
+
return `<td class="r mt" title="最近一次发版 ${d.lastRelease || ''}${d.cadence == null ? '' : ` · 平均 ${d.cadence} 天发一个版本`}">` +
|
|
289
|
+
`<div${stale ? ' class="stale"' : ''}>${ageText(d.age)}</div>${cad}</td>`
|
|
196
290
|
}
|
|
197
291
|
|
|
198
292
|
/* ---------------- 搜索(与 lib/engine.js 共用同一份词典 lib/words.js) --------------- */
|
|
@@ -295,7 +389,8 @@ function doSearch() {
|
|
|
295
389
|
renderCands(need)
|
|
296
390
|
}
|
|
297
391
|
|
|
298
|
-
function renderCands(need) {
|
|
392
|
+
function renderCands(need, { keepCompat = false } = {}) {
|
|
393
|
+
if (!keepCompat) loadCompat(cands.map(r => r.n))
|
|
299
394
|
const host = $('#cands')
|
|
300
395
|
host.innerHTML = ''
|
|
301
396
|
if (!cands.length) {
|
|
@@ -323,6 +418,7 @@ function renderCands(need) {
|
|
|
323
418
|
`<span>月 <b>${num(rec.m)}</b></span>` +
|
|
324
419
|
(d ? `<span>基线 <b>${num(d.base)}</b></span><span>环比 <b>${pct(d.growth)}</b></span>` : '') +
|
|
325
420
|
`</div>` +
|
|
421
|
+
checkRow(rec) +
|
|
326
422
|
`<div class="links">${linkBtns(rec)}<span class="sp"></span>${installArea(rec)}` +
|
|
327
423
|
(IN_DSH ? `<button class="ai" data-ask title="把这个插件的数据发到对话里问 AI">+AI</button>` : '') +
|
|
328
424
|
`</div>` +
|
|
@@ -495,9 +591,8 @@ function renderRank() {
|
|
|
495
591
|
`<td class="r"><b>${num(val(r))}</b></td>` +
|
|
496
592
|
`<td class="r">${num(r.w)}</td>` +
|
|
497
593
|
`<td class="r ${g === null ? '' : (g >= 0 ? 'up' : 'down')}">${pct(g)}</td>` +
|
|
498
|
-
|
|
499
|
-
`<td class="
|
|
500
|
-
`<td style="white-space:nowrap">${linkBtns(r)}</td>` +
|
|
594
|
+
maintCell(d) +
|
|
595
|
+
`<td class="lks">${linkBtns(r, { icon: true })}</td>` +
|
|
501
596
|
`</tr>`
|
|
502
597
|
}).join('')
|
|
503
598
|
}
|