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
package/lib/store.mjs
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/store.mjs
|
|
3
|
+
* @role 路径与状态:dshHome、profileDir、配置读写与迁移(hostsVersion/netVersion)、历史与日志
|
|
4
|
+
* @sub 配置、路径、迁移、历史
|
|
5
|
+
* @exports dshHome / pluginHome / profileName / profileDir / HOSTS_VERSION / NET_VERSION / DEFAULT_CONFIG / pathsFor / clampConfig / loadConfig / writeJsonAtomic / saveConfig / readHistory / appendHistory / clearHistory / removeHistory / appendLog / slugify / ensureDir
|
|
6
|
+
* @reads ~/.dsh、插件自己的 config.json / history.json
|
|
7
|
+
* @writes 插件的 config.json(原子写)、历史文件、日志
|
|
8
|
+
* @risk clipConfig 决定了哪些开关「关不掉」;profile 名字写死会让临时 profile 全部装进 desktop(踩过)
|
|
9
|
+
* @touch 加配置键要同步 clampConfig、客户端设置页、README 的配置表;改版本号要写迁移
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* dsh-modpack —— 本地状态:设置、历史、目录解析。
|
|
3
15
|
*
|
|
@@ -15,6 +27,11 @@ export function dshHome() {
|
|
|
15
27
|
}
|
|
16
28
|
|
|
17
29
|
export function pluginHome() {
|
|
30
|
+
// 状态目录(设置、记录、下载的包、日志)跟着 DSH_HOME 走。
|
|
31
|
+
// DSH_MODPACK_STATE_DIR 只给测试与排查用:想用真实 profile 里的插件跑测试、
|
|
32
|
+
// 又不想把设置和记录写进使用者的 ~/.dsh 时,把它指到一个临时目录即可。
|
|
33
|
+
const override = String(process.env.DSH_MODPACK_STATE_DIR || '').trim()
|
|
34
|
+
if (override) return path.resolve(override)
|
|
18
35
|
return path.join(dshHome(), 'dsh-modpack')
|
|
19
36
|
}
|
|
20
37
|
|
|
@@ -70,6 +87,8 @@ export const DEFAULT_CONFIG = {
|
|
|
70
87
|
maxFileBytes: 16 * 1024 * 1024,
|
|
71
88
|
// 进度窗里「收尾」的记录留多久(秒):0 = 留到 DSH 下次启动(或手动清空);给正数就按秒自动清
|
|
72
89
|
jobKeepSeconds: 0,
|
|
90
|
+
// 测试模式:所有会真的下载 / 真的安装 / 真的改本机的操作只走流程,进度与弹窗照常(见 lib/testmode.mjs)
|
|
91
|
+
testMode: false,
|
|
73
92
|
// 二次开发用:额外扫描规则(形状同 lib/scan.mjs 的 SECRET_RULES)
|
|
74
93
|
extraScanRules: [],
|
|
75
94
|
historyLimit: 50,
|
|
@@ -91,6 +110,18 @@ export const DEFAULT_CONFIG = {
|
|
|
91
110
|
// 社区资源(自建目录,插件自带、默认开启;设置里关掉只是不显示那一栏)
|
|
92
111
|
showModpackMarket: true,
|
|
93
112
|
modpackRefreshHours: 24,
|
|
113
|
+
// 附属小插件:总开关(设置里显示「本插件下面挂着哪些小插件」)+ 每个小插件自己的开关。
|
|
114
|
+
// 关掉某个小插件只是不挂它的接口、界面上不显示,主体流程不受影响。
|
|
115
|
+
showSubplugins: true,
|
|
116
|
+
showAnnotate: true,
|
|
117
|
+
showPluginTree: true,
|
|
118
|
+
// 配色:预设 id(mist/forest/dusk/native/custom)+ 自定义两个颜色。
|
|
119
|
+
// 只管本插件自己的界面;native = 不注入任何颜色,完全跟宿主主题。
|
|
120
|
+
// 界面风格:new = 新版(蓝白 + 分区卡片 + 章节跳转),classic = 改版前的样子(不注入配色、平铺列表)
|
|
121
|
+
uiStyle: 'new',
|
|
122
|
+
themeId: 'mist',
|
|
123
|
+
themePrimary: '',
|
|
124
|
+
themeAccent: '',
|
|
94
125
|
// 白名单迁移标记:跑过一次就别再往里并默认域名,尊重用户自己的增删
|
|
95
126
|
hostsVersion: HOSTS_VERSION,
|
|
96
127
|
}
|
|
@@ -132,6 +163,13 @@ export function clampConfig(raw) {
|
|
|
132
163
|
// 0 是合法的:等于「收尾就立刻清掉」,测试也靠它把时间压到零
|
|
133
164
|
const keepRaw = raw && typeof raw.jobKeepSeconds === 'number' ? raw.jobKeepSeconds : DEFAULT_CONFIG.jobKeepSeconds
|
|
134
165
|
cfg.jobKeepSeconds = Math.min(3600, Math.max(0, Math.floor(Number(keepRaw) || 0)))
|
|
166
|
+
cfg.testMode = raw && raw.testMode === true
|
|
167
|
+
// 配色:认得的预设 id 才留,颜色只认 #rrggbb(看不懂就清空,themeOf 会退回预设色)
|
|
168
|
+
const themeIds = ['mist', 'forest', 'dusk', 'native', 'custom']
|
|
169
|
+
cfg.themeId = themeIds.includes(String(cfg.themeId || '')) ? String(cfg.themeId) : 'mist'
|
|
170
|
+
cfg.themePrimary = /^#[0-9a-fA-F]{6}$/u.test(String(cfg.themePrimary || '')) ? String(cfg.themePrimary) : ''
|
|
171
|
+
cfg.themeAccent = /^#[0-9a-fA-F]{6}$/u.test(String(cfg.themeAccent || '')) ? String(cfg.themeAccent) : ''
|
|
172
|
+
cfg.uiStyle = String(cfg.uiStyle || '') === 'classic' ? 'classic' : 'new'
|
|
135
173
|
// 网络参数:超时 5~120 秒、重试 0~5 次,curl 兜底只能是布尔
|
|
136
174
|
cfg.netTimeoutSeconds = Math.min(120, Math.max(5, Math.floor(Number(cfg.netTimeoutSeconds) || DEFAULT_CONFIG.netTimeoutSeconds)))
|
|
137
175
|
cfg.netRetries = Math.min(5, Math.max(0, Math.floor(Number(cfg.netRetries) || 0)))
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/subplugins.mjs
|
|
3
|
+
* @role 附属小插件的登记处:谁有什么清单、归哪个设置开关、对外接口有哪些
|
|
4
|
+
* @sub 登记表, 读清单, 算启用态, 汇总给 status 与设置页
|
|
5
|
+
* @exports SUBPLUGINS, readSubManifest, readSubManifests, listSubplugins, findSubplugin, subEnabled
|
|
6
|
+
* @uses lib/community.mjs(社区资源的 external 判定与它保持一致)
|
|
7
|
+
* @reads <dir>/manifest.json(每个附属小插件一份,内置、只读)
|
|
8
|
+
* @writes 不写任何文件
|
|
9
|
+
* @risk 表里少一项 = 那个小插件没被挂载、界面也看不见;configKey 写错 = 开关点了没用
|
|
10
|
+
* @touch 新增附属小插件 → 这里加一行 + 建 <dir>/manifest.json + index.js 挂路由 + client.js 设置页自动列出
|
|
11
|
+
* @since 0.3.0
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { resolveCommunity } from './community.mjs'
|
|
16
|
+
|
|
17
|
+
// 三个附属小插件,一个插件一条:dir 是插件根下的目录名,configKey 是设置里那个开关。
|
|
18
|
+
export const SUBPLUGINS = [
|
|
19
|
+
{
|
|
20
|
+
id: 'dsh-modpack-community',
|
|
21
|
+
dir: 'community',
|
|
22
|
+
label: '社区资源',
|
|
23
|
+
note: '浏览/下载/上传整合包,接入插件市场',
|
|
24
|
+
configKey: 'showModpackMarket',
|
|
25
|
+
since: '0.2.3',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'dsh-modpack-annotate',
|
|
29
|
+
dir: 'annotate',
|
|
30
|
+
label: '代码标注',
|
|
31
|
+
note: '读源码头部的标注,列文件职责与改动注意事项',
|
|
32
|
+
configKey: 'showAnnotate',
|
|
33
|
+
since: '0.3.0',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'dsh-modpack-plugin-tree',
|
|
37
|
+
dir: 'plugin-tree',
|
|
38
|
+
label: '插件树',
|
|
39
|
+
note: 'AE2 式插件树与兼容树,按声明拼出来',
|
|
40
|
+
configKey: 'showPluginTree',
|
|
41
|
+
since: '0.3.0',
|
|
42
|
+
},
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
const cache = new Map()
|
|
46
|
+
|
|
47
|
+
/** 读一个附属小插件的清单;读不到就用登记表里那点信息兜底。 */
|
|
48
|
+
export function readSubManifest(root, entry) {
|
|
49
|
+
const file = path.join(root, entry.dir, 'manifest.json')
|
|
50
|
+
let stat = null
|
|
51
|
+
try {
|
|
52
|
+
stat = fs.statSync(file)
|
|
53
|
+
} catch {
|
|
54
|
+
stat = null
|
|
55
|
+
}
|
|
56
|
+
const key = file + '|' + (stat ? stat.mtimeMs : 0)
|
|
57
|
+
if (cache.has(key)) return cache.get(key)
|
|
58
|
+
let manifest = {}
|
|
59
|
+
try {
|
|
60
|
+
manifest = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
61
|
+
} catch {
|
|
62
|
+
manifest = {}
|
|
63
|
+
}
|
|
64
|
+
const merged = {
|
|
65
|
+
id: String(manifest.id || entry.id),
|
|
66
|
+
name: String(manifest.name || entry.label),
|
|
67
|
+
apiVersion: Number(manifest.apiVersion) || 1,
|
|
68
|
+
builtin: manifest.builtin !== false,
|
|
69
|
+
standalone: manifest.standalone !== false,
|
|
70
|
+
configKey: String(manifest.configKey || entry.configKey || ''),
|
|
71
|
+
since: String(manifest.since || entry.since || ''),
|
|
72
|
+
routes: Array.isArray(manifest.routes) ? manifest.routes.filter((item) => typeof item === 'string') : [],
|
|
73
|
+
ui: manifest.ui || {},
|
|
74
|
+
note: String(manifest.note || entry.note || ''),
|
|
75
|
+
dir: entry.dir,
|
|
76
|
+
entryLabel: entry.label,
|
|
77
|
+
}
|
|
78
|
+
// 只留最近 8 个清单的解析结果:够用,也不会一直涨
|
|
79
|
+
if (cache.size > 8) cache.clear()
|
|
80
|
+
cache.set(key, merged)
|
|
81
|
+
return merged
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 全部清单(按登记表顺序,代码地图与插件树都按这个顺序)。 */
|
|
85
|
+
export function readSubManifests(root) {
|
|
86
|
+
return SUBPLUGINS.map((entry) => readSubManifest(root, entry)).filter(Boolean)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function findSubplugin(root, idOrDir) {
|
|
90
|
+
const entry = SUBPLUGINS.find((item) => item.id === idOrDir || item.dir === idOrDir)
|
|
91
|
+
if (!entry) return null
|
|
92
|
+
return readSubManifest(root, entry)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 这个附属小插件现在算不算开着(设置开关 + 外部实现合并后的结果)。 */
|
|
96
|
+
export function subEnabled(manifest, config = {}) {
|
|
97
|
+
if (!manifest) return false
|
|
98
|
+
if (!manifest.configKey) return true
|
|
99
|
+
return config[manifest.configKey] !== false
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 设置页与 status 用:每个附属小插件现在什么状态、有多少接口、是内置还是外部实现。
|
|
104
|
+
* @returns {Array<{id,name,label,note,dir,apiVersion,enabled,standalone,mode,version,routes,configKey,since,ui}>}
|
|
105
|
+
*/
|
|
106
|
+
export function listSubplugins(root, profileDir, config = {}) {
|
|
107
|
+
const out = []
|
|
108
|
+
for (const entry of SUBPLUGINS) {
|
|
109
|
+
const manifest = readSubManifest(root, entry)
|
|
110
|
+
if (!manifest) continue
|
|
111
|
+
let mode = 'builtin'
|
|
112
|
+
let version = ''
|
|
113
|
+
if (manifest.id === 'dsh-modpack-community') {
|
|
114
|
+
try {
|
|
115
|
+
const resolved = resolveCommunity(profileDir, config)
|
|
116
|
+
mode = resolved.mode
|
|
117
|
+
version = resolved.version || ''
|
|
118
|
+
} catch {
|
|
119
|
+
mode = 'builtin'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
out.push({
|
|
123
|
+
id: manifest.id,
|
|
124
|
+
name: manifest.name,
|
|
125
|
+
label: manifest.label || entry.label,
|
|
126
|
+
note: manifest.note || entry.note || '',
|
|
127
|
+
dir: manifest.dir,
|
|
128
|
+
apiVersion: manifest.apiVersion,
|
|
129
|
+
enabled: subEnabled(manifest, config),
|
|
130
|
+
standalone: manifest.standalone,
|
|
131
|
+
mode,
|
|
132
|
+
version,
|
|
133
|
+
routes: manifest.routes,
|
|
134
|
+
routeCount: manifest.routes.length,
|
|
135
|
+
configKey: manifest.configKey,
|
|
136
|
+
since: manifest.since,
|
|
137
|
+
ui: manifest.ui,
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
return out
|
|
141
|
+
}
|
package/lib/tar.mjs
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/tar.mjs
|
|
3
|
+
* @role 最小 tar.gz 读取:解 npm tarball,带条数与总体积上限
|
|
4
|
+
* @sub 压缩包、限额
|
|
5
|
+
* @exports readTarball / stripPackagePrefix / tarLimits
|
|
6
|
+
* @risk 解压炸弹:上限必须同时限制条目数、单条体积与总量
|
|
7
|
+
* @touch 改上限要同步 lib/zip.mjs 的同类上限与测试用例
|
|
8
|
+
* @since 0.3.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* dsh-modpack —— 最小 tgz 读取(npm 包用)。
|
|
3
13
|
*
|
package/lib/testmode.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/testmode.mjs
|
|
3
|
+
* @role 测试模式:让所有会「真的下载 / 真的安装 / 真的改本机」的操作只走流程
|
|
4
|
+
* @sub 测试模式开关判定、假任务步骤表、任务投放到悬浮窗(只模拟,不落盘)
|
|
5
|
+
* @exports api:testModeOn、api:testNote、api:playTestJob、api:testPayload、api:testStepsFor
|
|
6
|
+
* @uses lib/store.mjs 的 config.testMode
|
|
7
|
+
* @risk 忘了在这里短路,就会在「测试模式」下真的装东西:所有写本机 / 联网的入口都必须先问 testModeOn
|
|
8
|
+
* @touch 新增一条会写本机或联网的路由时,在 index.js 里同步加一个 testModeOn(config) 分支;改步骤名时同步 client.js 的 JOB_KIND_LABEL
|
|
9
|
+
* @since 0.3.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 测试模式下所有提示的统一前缀——界面上要能一眼看出「这些都没真发生」。 */
|
|
13
|
+
export const TEST_PREFIX = '测试模式'
|
|
14
|
+
|
|
15
|
+
/** 测试模式开关:只有明确 true 才算开,缺省与「写坏了」都当关闭。 */
|
|
16
|
+
export function testModeOn(config) {
|
|
17
|
+
return Boolean(config && config.testMode === true)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 一句统一的说明,任务完成时挂在 job.note 上。 */
|
|
21
|
+
export function testNote(action) {
|
|
22
|
+
return TEST_PREFIX + ':只跑了流程,没有真的' + (action || '操作')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 把假步骤推进到界面上时用的间隔(毫秒):测试里可以调小,真机默认 90ms 看着像在干活。 */
|
|
26
|
+
function stepDelay() {
|
|
27
|
+
const raw = Number(process.env.DSH_MODPACK_TEST_STEP_MS)
|
|
28
|
+
if (Number.isFinite(raw) && raw >= 0) return raw
|
|
29
|
+
return 90
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 各操作的假步骤表。key 与 index.js 的任务 kind 对齐。
|
|
34
|
+
* 步骤名要写清「这一步真做会干什么」,不然测试模式看不出流程缺哪步。
|
|
35
|
+
*/
|
|
36
|
+
export const TEST_STEPS = {
|
|
37
|
+
pack: [
|
|
38
|
+
'读插件清单与本机配置',
|
|
39
|
+
'扫描风险与敏感信息(假扫)',
|
|
40
|
+
'按策略算要带哪些插件本体(假算)',
|
|
41
|
+
'生成 .dshpack(没写文件)',
|
|
42
|
+
],
|
|
43
|
+
download: ['从社区目录取条目(假取)', '取包体(假取)', '写进 packs 目录(没写)'],
|
|
44
|
+
install: [
|
|
45
|
+
'读包、校验 sha256 与清单(假校验)',
|
|
46
|
+
'核对依赖与引擎(假核对)',
|
|
47
|
+
'生成安装计划(假计划)',
|
|
48
|
+
'装依赖(没装)',
|
|
49
|
+
'回填配置与分组(没写)',
|
|
50
|
+
],
|
|
51
|
+
update: ['查市场最新版本(假查)', '按版本装(没装)', '恢复启用状态(没动)'],
|
|
52
|
+
reinstall: ['读当前启用状态(假读)', '处理本机配置(没动)', '卸载(没卸)', '安装(没装)', '恢复启用状态(没动)'],
|
|
53
|
+
upload: ['读包与清单(假读)', '算 sha256(真算,只读)', '拼条目(没写)', '开 PR(没开)'],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 某个操作在测试模式下的步骤表;没有登记就退一条通用步骤。 */
|
|
57
|
+
export function testStepsFor(kind) {
|
|
58
|
+
const steps = TEST_STEPS[kind]
|
|
59
|
+
return Array.isArray(steps) && steps.length ? steps.slice() : ['走一遍流程(没有真的做)']
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 在一个已建好的 job 上「演」一遍:步骤逐个标成 running → done,pct 跟着走,
|
|
64
|
+
* 最后 done + note。不会碰任何真实资源(文件、网络、本机 profile)。
|
|
65
|
+
* @param {{steps?: Array<object|string>, status?: string, pct?: number, note?: string, data?: object, finishedAt?: string}} job 任务对象(index.js 的 createJob 产物)
|
|
66
|
+
* @param {string[]} steps 步骤名
|
|
67
|
+
* @param {{action?: string, data?: object, cancelled?: () => boolean}} options
|
|
68
|
+
*/
|
|
69
|
+
export async function playTestJob(job, steps, options = {}) {
|
|
70
|
+
const list = Array.isArray(steps) && steps.length ? steps : testStepsFor('generic')
|
|
71
|
+
const delay = stepDelay()
|
|
72
|
+
job.status = 'running'
|
|
73
|
+
job.pct = 0
|
|
74
|
+
job.note = TEST_PREFIX + ':开始走流程'
|
|
75
|
+
job.steps = list.map((name) => ({ name, state: 'pending' }))
|
|
76
|
+
for (let index = 0; index < job.steps.length; index += 1) {
|
|
77
|
+
const step = job.steps[index]
|
|
78
|
+
if (options.cancelled && options.cancelled()) {
|
|
79
|
+
step.state = 'failed'
|
|
80
|
+
job.status = 'cancelled'
|
|
81
|
+
job.note = TEST_PREFIX + ':已取消(什么都没做)'
|
|
82
|
+
job.finishedAt = new Date().toISOString()
|
|
83
|
+
return { cancelled: true }
|
|
84
|
+
}
|
|
85
|
+
step.state = 'running'
|
|
86
|
+
job.pct = Math.round((index / job.steps.length) * 90)
|
|
87
|
+
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay))
|
|
88
|
+
step.state = 'done'
|
|
89
|
+
job.pct = Math.round(((index + 1) / job.steps.length) * 100)
|
|
90
|
+
}
|
|
91
|
+
job.status = 'done'
|
|
92
|
+
job.pct = 100
|
|
93
|
+
job.note = testNote(options.action)
|
|
94
|
+
job.data = { test: true, ...(options.data || {}) }
|
|
95
|
+
job.finishedAt = new Date().toISOString()
|
|
96
|
+
return { cancelled: false, data: job.data }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 同步接口(不打任务队列的)在测试模式下统一回这个形状。 */
|
|
100
|
+
export function testPayload(action, extra = {}) {
|
|
101
|
+
return { ok: true, test: true, note: testNote(action), ...extra }
|
|
102
|
+
}
|
package/lib/theme.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/theme.mjs
|
|
3
|
+
* @role 配色:四套预设 + 自定义主色/附属色,把主题算成一组 CSS 变量(只作用于本插件自己的界面)
|
|
4
|
+
* @sub 预设、取色、颜色合法性、CSS 变量、前景色可读性(readableOn)
|
|
5
|
+
* @exports THEME_PRESETS / THEME_IDS / DEFAULT_THEME_ID / isHexColor / readableOn / themeOf / themeVars / themeCss / themeActive
|
|
6
|
+
* @api 无(由 /status 带出 theme 与 themePresets 给界面)
|
|
7
|
+
* @uses 无
|
|
8
|
+
* @reads 无
|
|
9
|
+
* @writes 无
|
|
10
|
+
* @risk 预设里的 hex 写错会让界面整片变透明;themeOf 必须永远回一份完整可用的颜色,看不懂就落回默认
|
|
11
|
+
* @touch 加预设要同步 client.js 的 --mp-* 用法与 test/run.mjs 的配色用例
|
|
12
|
+
* @since 0.3.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 配色只在本插件自己的界面里生效:客户端把 --mp-* 变量挂在 :root 上,
|
|
17
|
+
* 本插件的样式里用 var(--mp-primary, 原色) 取值——注入失败时自然退回原色。
|
|
18
|
+
*
|
|
19
|
+
* 主色管重点(主按钮、选中胶囊、链接),附属色管强调(筛选胶囊、开关、进度条)。
|
|
20
|
+
*
|
|
21
|
+
* 文字颜色不再写死:--mp-on-primary / --mp-on-accent 由 readableOn() 按底色亮度算出来
|
|
22
|
+
* (深底白字、浅底黑字),--mp-accent-strong 是「浅色底上还能看清」的深一档附属色。
|
|
23
|
+
* 所以新增浅色系预设(琥珀、樱粉、青)时,不需要再手动挑字色。
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export const THEME_PRESETS = [
|
|
27
|
+
{
|
|
28
|
+
id: 'mist',
|
|
29
|
+
label: '雾蓝(PCL 色系)',
|
|
30
|
+
recommended: true,
|
|
31
|
+
primary: '#1B7BE8',
|
|
32
|
+
accent: '#16C2C8',
|
|
33
|
+
note: '标题栏蓝 + 青,白卡片、浅蓝渐变底',
|
|
34
|
+
swatch: ['#1B7BE8', '#16C2C8', '#EEF5FF'],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'forest',
|
|
38
|
+
label: '墨绿 + 琥珀',
|
|
39
|
+
primary: '#2E7D6B',
|
|
40
|
+
accent: '#E0A33E',
|
|
41
|
+
note: '安静一点,适合长时间看列表',
|
|
42
|
+
swatch: ['#2E7D6B', '#E0A33E', '#F2F7F5'],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'dusk',
|
|
46
|
+
label: '暮紫 + 樱粉',
|
|
47
|
+
primary: '#6A5AE0',
|
|
48
|
+
accent: '#F2A0A8',
|
|
49
|
+
note: '夜间观感更柔,暗色下偏蓝紫',
|
|
50
|
+
swatch: ['#6A5AE0', '#F2A0A8', '#F4F2FF'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'native',
|
|
54
|
+
label: '跟 DSH 原生(黑 / 白)',
|
|
55
|
+
primary: '',
|
|
56
|
+
accent: '',
|
|
57
|
+
note: '底色是黑是白,跟着系统的夜间 / 白天走;不注入任何颜色',
|
|
58
|
+
swatch: [],
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
export const THEME_IDS = THEME_PRESETS.map((preset) => preset.id)
|
|
63
|
+
export const DEFAULT_THEME_ID = 'mist'
|
|
64
|
+
|
|
65
|
+
const HEX_RE = /^#[0-9a-fA-F]{6}$/u
|
|
66
|
+
|
|
67
|
+
export function isHexColor(value) {
|
|
68
|
+
return typeof value === 'string' && HEX_RE.test(value)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** RGB 三通道都往目标色拉一部分:0 = 原色,1 = 纯白/纯黑 */
|
|
72
|
+
function mix(hex, target, weight) {
|
|
73
|
+
const num = Number.parseInt(hex.slice(1), 16)
|
|
74
|
+
const r = (num >> 16) & 255
|
|
75
|
+
const g = (num >> 8) & 255
|
|
76
|
+
const b = num & 255
|
|
77
|
+
const t = target === 'white' ? 255 : 0
|
|
78
|
+
const to = (channel) => Math.round(channel + (t - channel) * weight)
|
|
79
|
+
return '#' + [to(r), to(g), to(b)].map((v) => v.toString(16).padStart(2, '0')).join('')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 把配置算成一份「永远可用」的主题。
|
|
84
|
+
* 自定义色看不懂就退回预设色;预设 id 不认识就退回默认预设。
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* 在某个底色上该用黑字还是白字:按 sRGB 相对亮度算,阈值 0.55。
|
|
88
|
+
* 这就是「有些主题下文字看不清」的解药——不再一律写死白字。
|
|
89
|
+
*/
|
|
90
|
+
export function readableOn(hex) {
|
|
91
|
+
if (!isHexColor(hex)) return '#ffffff'
|
|
92
|
+
const channel = (offset) => {
|
|
93
|
+
const value = parseInt(hex.slice(offset, offset + 2), 16) / 255
|
|
94
|
+
return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4)
|
|
95
|
+
}
|
|
96
|
+
const luminance = 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5)
|
|
97
|
+
// 0.35 是个折中:低于它的深色(蓝、绿、紫)继续用白字(观感更稳),
|
|
98
|
+
// 高于它的浅色(琥珀、樱粉、青)改用黑字,避免白字糊在浅底上。
|
|
99
|
+
return luminance > 0.35 ? '#1b1d21' : '#ffffff'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function themeOf(config) {
|
|
103
|
+
const wanted = String((config && config.themeId) || DEFAULT_THEME_ID)
|
|
104
|
+
if (wanted === 'custom') {
|
|
105
|
+
const primary = isHexColor(config && config.themePrimary) ? String(config.themePrimary) : '#1B7BE8'
|
|
106
|
+
const accent = isHexColor(config && config.themeAccent) ? String(config.themeAccent) : '#16C2C8'
|
|
107
|
+
return { id: 'custom', label: '自定义', primary, accent, custom: true }
|
|
108
|
+
}
|
|
109
|
+
const preset = THEME_PRESETS.find((item) => item.id === wanted) || THEME_PRESETS[0]
|
|
110
|
+
return { id: preset.id, label: preset.label, primary: preset.primary, accent: preset.accent, custom: false }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 主题 → CSS 变量表。native 返回空对象(客户端据此不注入任何样式)。
|
|
115
|
+
* 颜色之间的关系一次算好,界面里只写 var(--mp-*)。
|
|
116
|
+
*/
|
|
117
|
+
function rgba(hex, alpha) {
|
|
118
|
+
const num = Number.parseInt(hex.slice(1), 16)
|
|
119
|
+
const r = (num >> 16) & 255
|
|
120
|
+
const g = (num >> 8) & 255
|
|
121
|
+
const b = num & 255
|
|
122
|
+
return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 主题 → CSS 变量表。native 返回空对象(客户端据此不注入任何样式)。
|
|
127
|
+
* 颜色之间的关系一次算好,界面里只写 var(--mp-*),换色时整片一起动。
|
|
128
|
+
* 变量分三层:颜色(primary/accent 系)、面(card/page/page-grad/line)、字(text/muted)。
|
|
129
|
+
*/
|
|
130
|
+
export function themeVars(theme) {
|
|
131
|
+
if (!theme || theme.id === 'native' || !isHexColor(theme.primary)) return {}
|
|
132
|
+
const primary = theme.primary
|
|
133
|
+
const accent = isHexColor(theme.accent) ? theme.accent : primary
|
|
134
|
+
const page = mix(primary, 'white', 0.94)
|
|
135
|
+
return {
|
|
136
|
+
'--mp-primary': primary,
|
|
137
|
+
'--mp-primary-strong': mix(primary, 'black', 0.18),
|
|
138
|
+
'--mp-primary-soft': mix(primary, 'white', 0.88),
|
|
139
|
+
'--mp-on-primary': readableOn(primary),
|
|
140
|
+
'--mp-accent': accent,
|
|
141
|
+
'--mp-accent-strong': mix(accent, 'black', 0.62),
|
|
142
|
+
'--mp-accent-soft': mix(accent, 'white', 0.86),
|
|
143
|
+
'--mp-on-accent': readableOn(accent),
|
|
144
|
+
'--mp-on-soft': mix(primary, 'black', 0.74),
|
|
145
|
+
'--mp-line': mix(primary, 'white', 0.8),
|
|
146
|
+
'--mp-line-strong': mix(primary, 'white', 0.62),
|
|
147
|
+
'--mp-hover': mix(primary, 'white', 0.92),
|
|
148
|
+
'--mp-text': '#2a2e35',
|
|
149
|
+
'--mp-muted': '#77839a',
|
|
150
|
+
'--mp-card': '#ffffff',
|
|
151
|
+
'--mp-card-soft': mix(primary, 'white', 0.97),
|
|
152
|
+
'--mp-page': page,
|
|
153
|
+
'--mp-page-grad': 'linear-gradient(180deg,' + page + ' 0%,#ffffff 78%)',
|
|
154
|
+
'--mp-header': primary,
|
|
155
|
+
'--mp-header-soft': mix(primary, 'white', 0.88),
|
|
156
|
+
'--mp-shadow': '0 2px 12px ' + rgba(primary, 0.1),
|
|
157
|
+
'--mp-shadow-strong': '0 6px 22px ' + rgba(primary, 0.16),
|
|
158
|
+
'--mp-radius': '10px',
|
|
159
|
+
'--mp-focus': '0 0 0 2px ' + rgba(primary, 0.25),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 这套主题要不要真的上色:native 与 classic 都不上 */
|
|
164
|
+
export function themeActive(theme, uiStyle) {
|
|
165
|
+
return uiStyle !== 'classic' && Boolean(theme) && theme.id !== 'native' && isHexColor(theme.primary)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function themeCss(theme) {
|
|
169
|
+
const vars = themeVars(theme)
|
|
170
|
+
const keys = Object.keys(vars)
|
|
171
|
+
if (!keys.length) return ''
|
|
172
|
+
return ':root{' + keys.map((key) => key + ':' + vars[key]).join(';') + '}'
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 设置页用:给界面一份可点的清单 */
|
|
176
|
+
export function themeOptions() {
|
|
177
|
+
return THEME_PRESETS.map((preset) => ({
|
|
178
|
+
id: preset.id,
|
|
179
|
+
label: preset.label,
|
|
180
|
+
note: preset.note || '',
|
|
181
|
+
primary: preset.primary,
|
|
182
|
+
accent: preset.accent,
|
|
183
|
+
recommended: preset.recommended === true,
|
|
184
|
+
swatch: Array.isArray(preset.swatch) ? preset.swatch.slice(0, 3) : [],
|
|
185
|
+
}))
|
|
186
|
+
}
|
package/lib/yamlish.mjs
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/yamlish.mjs
|
|
3
|
+
* @role 极简 YAML:读写 cordis.patch.yml 的顶层条目(解析、生成、按 id 找/替换条目)
|
|
4
|
+
* @sub YAML、配置文件
|
|
5
|
+
* @exports parseYaml / emitScalar / emitYaml / splitTopLevelItems / upsertPatchItem / findPatchItem / YamlError
|
|
6
|
+
* @reads 纯文本
|
|
7
|
+
* @risk 生成非法的 YAML 会让整份 profile 配置失效(空数组/空对象必须同行输出,踩过)
|
|
8
|
+
* @touch 改输出格式要同步 lib/pack.mjs 的 captureConfigs 与 lib/plugin-manager.mjs 的 dropPatchEntries
|
|
9
|
+
* @since 0.3.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
/**
|
|
2
13
|
* dsh-modpack —— 够用的 YAML 子集(只服务 profile 的 cordis.patch.yml)。
|
|
3
14
|
*
|
package/lib/zip.mjs
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file lib/zip.mjs
|
|
3
|
+
* @role 最小 zip 读写:打整合包、读整合包与封面,带解压炸弹上限
|
|
4
|
+
* @sub 压缩包、限额
|
|
5
|
+
* @exports safeEntryName / alreadyCompressed / writeZip / readZip / readZipText / zipLimits
|
|
6
|
+
* @reads 包内字节
|
|
7
|
+
* @writes 只在内存里组装
|
|
8
|
+
* @risk 路径穿越(../)与解压炸弹是这里的两条红线;条目名必须 sanitize
|
|
9
|
+
* @touch 改上限要同步 /pack/drop 与 /inspect 的体积提示
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
/**
|
|
2
14
|
* dsh-modpack —— 最小 ZIP 读写(只用 node:zlib,不引入依赖)。
|
|
3
15
|
*
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Modpack Kit",
|
|
4
|
-
"description": "\"Put these plugins together and it is genuinely good.\" A PCL/HMCL-style modpack tool for DSH: bundle plugins with their config and data into one .dshpack and install them in one go; a bare DSH can install it too. \"Community\" browses, downloads and one-click uploads your packs
|
|
4
|
+
"description": "dsh-modpack-kit (Modpack Hub): \"Put these plugins together and it is genuinely good.\" A PCL/HMCL-style modpack tool for DSH: bundle plugins together with their config and data into one .dshpack and install them in one go; a bare DSH can install it too. \"Community\" browses, downloads and one-click uploads your packs. A better plugin-manager page. Three strategies: lazy pack (payload included, installs offline), light (install codes only, smallest), hybrid (picked per how each plugin is configured). Per-plugin setup: \"plugin preset\" or \"custom config\"; entries restored item by item, local files not overwritten by default, sha256, compatibility and licences are checked before installing. In step with the plugin market, and without it plugin management, updates, packing and installing all still work. Sources include file and folder pickers, any directory, imported list and links. Installing the plugin market (dshmarket) is recommended. npm: https://www.npmjs.com/package/dsh-modpack-kit",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "整合包工坊",
|
|
4
|
+
"description": "整合包工坊(dsh-modpack-kit):(你说这几个插件整一块不牛逼坏了) 类似 HMCL / PCL 的 DSH 整合包工具:把插件连同配置与数据打成一个 .dshpack,一次装好,纯净 DSH 也能装;「社区资源」浏览、下载和一键上传你的整合包。更好的插件管理页面 三种打包策略:懒人包(带本体,离线可装)、轻量包(只记安装码,最省空间)、混合(按插件配置类型选)。 逐插件定制:「插件预设」或「自定义配置」,按条目回填、默认不覆盖本机文件,安装前校验 sha256、兼容性与许可证。 与插件市场同源,没装市场也能正常进行插件管理更新打包安装。 取包支持文件/文件夹选择器、任意目录、已导入列表与链接。 建议先装插件市场(dshmarket)。 npm:https://www.npmjs.com/package/dsh-modpack-kit",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-modpack-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "整合包工坊(dsh-modpack-kit):(你说这几个插件整一块不牛逼坏了) 类似 HMCL / PCL 的 DSH 整合包工具:把插件连同配置与数据打成一个 .dshpack,一次装好,纯净 DSH 也能装;「社区资源」浏览、下载和一键上传你的整合包。更好的插件管理页面 三种打包策略:懒人包(带本体,离线可装)、轻量包(只记安装码,最省空间)、混合(按插件配置类型选)。 逐插件定制:「插件预设」或「自定义配置」,按条目回填、默认不覆盖本机文件,安装前校验 sha256、兼容性与许可证。 与插件市场同源,没装市场也能正常进行插件管理更新打包安装。 取包支持文件/文件夹选择器、任意目录、已导入列表与链接。 建议先装插件市场(dshmarket)。 npm:https://www.npmjs.com/package/dsh-modpack-kit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"index.js",
|
|
16
16
|
"client.js",
|
|
17
17
|
"lib",
|
|
18
|
+
"community",
|
|
19
|
+
"annotate",
|
|
20
|
+
"plugin-tree",
|
|
18
21
|
"cordis.patch.yml",
|
|
19
22
|
"locale/*.json",
|
|
20
23
|
"docs",
|