dsh-modpack-kit 0.2.4 → 0.3.0
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 +26 -27
- package/annotate/index.mjs +62 -0
- package/annotate/manifest.json +18 -0
- package/client.js +1650 -211
- package/community/README.md +34 -0
- package/community/index.mjs +29 -0
- package/community/manifest.json +22 -0
- package/docs/ANNOTATIONS.md +60 -0
- package/docs/CODE-MAP.md +431 -272
- package/docs/DETAIL.md +30 -166
- package/docs/MARKET.txt +2 -2
- package/index.js +422 -7
- package/lib/annotate.mjs +172 -0
- package/lib/classify.mjs +11 -0
- package/lib/community.mjs +11 -0
- package/lib/compat.mjs +11 -0
- package/lib/github.mjs +11 -0
- package/lib/groups.mjs +12 -0
- package/lib/http.mjs +10 -0
- package/lib/install.mjs +12 -0
- package/lib/manifest.mjs +12 -0
- package/lib/market-catalog.mjs +12 -0
- package/lib/modpack-catalog.mjs +11 -0
- package/lib/net.mjs +11 -0
- package/lib/pack.mjs +12 -0
- package/lib/plugin-graph.mjs +461 -0
- package/lib/plugin-manager.mjs +557 -0
- package/lib/profile.mjs +12 -0
- package/lib/registry.mjs +12 -0
- package/lib/repack.mjs +11 -0
- package/lib/scan.mjs +12 -0
- package/lib/semver.mjs +10 -0
- package/lib/store.mjs +38 -0
- package/lib/subplugins.mjs +141 -0
- package/lib/tar.mjs +10 -0
- package/lib/testmode.mjs +102 -0
- package/lib/theme.mjs +186 -0
- package/lib/yamlish.mjs +11 -0
- package/lib/zip.mjs +12 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +2 -2
- package/package.json +5 -2
- package/plugin-tree/index.mjs +74 -0
- package/plugin-tree/manifest.json +23 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file plugin-tree/index.mjs
|
|
3
|
+
* @role 「插件树」附属小插件:给出「某个插件」的候选清单、相关性树与兼容树(全按声明拼,不跑别人代码)
|
|
4
|
+
* @sub 三条只读接口, 3 秒缓存避免拖动时反复拼图, 勾选多个插件就多根展开
|
|
5
|
+
* @exports TREE_ID, TREE_API, treeRoutes
|
|
6
|
+
* @api /dsh-modpack-kit/api/tree/plugins(GET), /dsh-modpack-kit/api/tree/plugin?names=a,b(GET), /dsh-modpack-kit/api/tree/compat?names=a,b(GET)
|
|
7
|
+
* @uses ../lib/plugin-graph.mjs(拼图全在那儿), ../lib/market-catalog.mjs(市场里支持哪些插件)
|
|
8
|
+
* @reads 本插件 package.json、三个附属小插件 manifest.json、<profile>/node_modules 下每个包的 package.json、市场目录缓存(只读)
|
|
9
|
+
* @writes 不写任何文件
|
|
10
|
+
* @risk 兼容判定只看声明;已装包多时(100+)每次重新扫 package.json 会慢,这里用 3 秒缓存顶住连续拖动
|
|
11
|
+
* @touch 改节点字段 → 同步 client.js 的 PluginTreeOverlay 渲染与 test/run.mjs 的断言
|
|
12
|
+
* @since 0.3.0
|
|
13
|
+
*/
|
|
14
|
+
import { buildRelations, compatOf, listTreeCandidates } from '../lib/plugin-graph.mjs'
|
|
15
|
+
import { readIndex } from '../lib/market-catalog.mjs'
|
|
16
|
+
|
|
17
|
+
export const TREE_ID = 'dsh-modpack-plugin-tree'
|
|
18
|
+
export const TREE_API = 1
|
|
19
|
+
|
|
20
|
+
const TTL = 3000
|
|
21
|
+
const memo = new Map()
|
|
22
|
+
|
|
23
|
+
/** 勾了谁很重要:同一个缓存里不能把 A 的树当成 B 的。 */
|
|
24
|
+
function queryNames(req) {
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(String((req && req.url) || '/'), 'http://dsh.local')
|
|
27
|
+
const raw = url.searchParams.get('names') || ''
|
|
28
|
+
return raw.split(',').map((item) => item.trim()).filter(Boolean).slice(0, 12)
|
|
29
|
+
} catch {
|
|
30
|
+
return []
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cacheKey(root, profileDir, config, kind, names) {
|
|
35
|
+
return [
|
|
36
|
+
root,
|
|
37
|
+
profileDir || '',
|
|
38
|
+
kind,
|
|
39
|
+
names.join(','),
|
|
40
|
+
config.showModpackMarket === false ? 0 : 1,
|
|
41
|
+
config.showAnnotate === false ? 0 : 1,
|
|
42
|
+
config.showPluginTree === false ? 0 : 1,
|
|
43
|
+
].join('|')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {{root: string, context: () => {profileDir: string, config: object}}} options
|
|
48
|
+
* context 每次请求都取一次:设置里改了开关、换了 profile,下一张树就应该反映出来。
|
|
49
|
+
*/
|
|
50
|
+
export function treeRoutes({ root, context }) {
|
|
51
|
+
const read = (kind, names) => {
|
|
52
|
+
const { profileDir, config } = context()
|
|
53
|
+
const key = cacheKey(root, profileDir, config, kind, names)
|
|
54
|
+
const now = Date.now()
|
|
55
|
+
const hit = memo.get(key)
|
|
56
|
+
if (hit && now - hit.at < TTL) return hit.value
|
|
57
|
+
let value
|
|
58
|
+
if (kind === 'plugins') {
|
|
59
|
+
value = listTreeCandidates(root, profileDir, config, readIndex(config))
|
|
60
|
+
} else if (kind === 'compat') {
|
|
61
|
+
value = compatOf(buildRelations(root, profileDir, config, names))
|
|
62
|
+
} else {
|
|
63
|
+
value = buildRelations(root, profileDir, config, names)
|
|
64
|
+
}
|
|
65
|
+
memo.set(key, { at: now, value })
|
|
66
|
+
for (const [oldKey, row] of memo) if (now - row.at > TTL * 4) memo.delete(oldKey)
|
|
67
|
+
return value
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
{ path: '/tree/plugins', methods: ['GET'], run: async (req) => read('plugins', queryNames(req)) },
|
|
71
|
+
{ path: '/tree/plugin', methods: ['GET'], run: async (req) => read('relations', queryNames(req)) },
|
|
72
|
+
{ path: '/tree/compat', methods: ['GET'], run: async (req) => read('compat', queryNames(req)) },
|
|
73
|
+
]
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "dsh-modpack-plugin-tree",
|
|
3
|
+
"name": "插件树(整合包的附属小插件)",
|
|
4
|
+
"apiVersion": 1,
|
|
5
|
+
"builtin": true,
|
|
6
|
+
"standalone": true,
|
|
7
|
+
"configKey": "showPluginTree",
|
|
8
|
+
"since": "0.3.0",
|
|
9
|
+
"note": "按声明拼插件树与兼容树,界面上像 AE2 配方树一样滚轮缩放、拖动平移",
|
|
10
|
+
"routes": [
|
|
11
|
+
"/dsh-modpack-kit/api/tree/plugins",
|
|
12
|
+
"/dsh-modpack-kit/api/tree/plugin",
|
|
13
|
+
"/dsh-modpack-kit/api/tree/compat"
|
|
14
|
+
],
|
|
15
|
+
"ui": {
|
|
16
|
+
"title": "插件树",
|
|
17
|
+
"panels": [
|
|
18
|
+
"PluginTree"
|
|
19
|
+
],
|
|
20
|
+
"viewport": "canvas-like svg, wheel zoom 0.35~2.5, drag to pan",
|
|
21
|
+
"settingsBox": "插件树(附属小插件)"
|
|
22
|
+
}
|
|
23
|
+
}
|