@lrplrplrp/dsh-live2d 0.1.2 → 0.1.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lrplrplrp/dsh-live2d",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Live2D 看板娘插件 for DeepSeek Harness — 可拖动的 Live2D 模型,支持 DSH 状态驱动动画、本地模型导入和完整配置页。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "files": [
13
13
  "lib/",
14
+ "scripts/",
14
15
  "assets/deepseek_l2d/",
15
16
  "assets/model_list.json",
16
17
  "cordis.patch.yml",
@@ -18,7 +19,9 @@
18
19
  "LICENSE"
19
20
  ],
20
21
  "scripts": {
21
- "check": "node --check lib/index.js && node --check lib/client.js"
22
+ "build": "node scripts/build-client.mjs",
23
+ "build:check": "node scripts/build-client.mjs --check",
24
+ "check": "npm run build:check && node --check lib/index.js && node --check lib/client.js"
22
25
  },
23
26
  "keywords": [
24
27
  "deepseek-harness",
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ // dsh-live2d — 客户端单文件构建脚本。
3
+ //
4
+ // 背景:host 端(@deepseek-ai/dsh-client-modules)只读取单个 `lib/client.js` 并原样
5
+ // 投递给浏览器(无打包器,client 侧 require 只能解析已注册的 dsh.client 模块,无法
6
+ // import 本地文件)。因此源码按功能拆分在 `lib/src/`,由本脚本按文件名顺序拼接生成
7
+ // 唯一的投放产物 `lib/client.js`。
8
+ //
9
+ // 同时把 `lib/shared/states.js`(host/client 的状态常量单一来源)内联进来:剥离
10
+ // ESM 的 `export` 关键字,使其在 client 的工厂闭包内等价于一段普通声明。
11
+ //
12
+ // 用法:
13
+ // node scripts/build-client.mjs # 生成 lib/client.js
14
+ // node scripts/build-client.mjs --check # 仅校验产物是否与源码一致(CI/回归用)
15
+
16
+ import { readFileSync, writeFileSync, readdirSync } from 'node:fs'
17
+ import { join, dirname } from 'node:path'
18
+ import { fileURLToPath } from 'node:url'
19
+
20
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
21
+ const SRC_DIR = join(ROOT, 'lib', 'src')
22
+ const OUT = join(ROOT, 'lib', 'client.js')
23
+ const SHARED = join(ROOT, 'lib', 'shared', 'states.js')
24
+
25
+ const MARK_A = '// >>> shared/states.js (generated — do not edit here) >>>'
26
+ const MARK_B = '// <<< shared/states.js <<<'
27
+
28
+ const GENERATED_NOTICE = [
29
+ '// ⚠️ 本文件由 scripts/build-client.mjs 从 lib/src/ 源码拼接生成,请勿直接编辑。',
30
+ '// 修改请改 lib/src/*.js 或 lib/shared/states.js,然后运行 `npm run build`。',
31
+ '// `npm run check` 会校验本产物与源码是否一致。',
32
+ '',
33
+ ].join('\n')
34
+
35
+ /** 把共享 ESM 模块转成可内联进 client 工厂闭包的普通声明片段。 */
36
+ function inlineShared() {
37
+ const raw = readFileSync(SHARED, 'utf8')
38
+ const body = raw
39
+ .split('\n')
40
+ // 去掉 ESM export 关键字(本文件只导出常量,内联后直接是闭包内声明)
41
+ .map((line) => line.replace(/^export\s+const\s/, 'const '))
42
+ .filter((line) => !/^import\s/.test(line))
43
+ .join('\n')
44
+ .trimEnd()
45
+ return [
46
+ ' ' + MARK_A,
47
+ ' // 由 scripts/build-client.mjs 从 lib/shared/states.js 内联生成,请勿直接修改此处。',
48
+ ...body.split('\n').map((l) => (l.length ? ' ' + l : l)),
49
+ ' ' + MARK_B,
50
+ '',
51
+ ].join('\n')
52
+ }
53
+
54
+ function build() {
55
+ const files = readdirSync(SRC_DIR)
56
+ .filter((f) => f.endsWith('.js'))
57
+ .sort() // 文件名前缀(00/10/20/...)决定拼接顺序
58
+
59
+ if (files.length === 0) throw new Error(`no source fragments found in ${SRC_DIR}`)
60
+
61
+ const parts = files.map((f) => readFileSync(join(SRC_DIR, f), 'utf8'))
62
+
63
+ // shared/states.js 内联在 config 片段(10-)之前,保证 DSHState 在最早被使用前已声明。
64
+ const insertAt = parts.findIndex((_, i) => files[i].startsWith('10-'))
65
+ const withShared = insertAt === -1
66
+ ? [...parts, inlineShared()]
67
+ : [...parts.slice(0, insertAt), inlineShared(), ...parts.slice(insertAt)]
68
+
69
+ let out = GENERATED_NOTICE + withShared.join('')
70
+ if (!out.endsWith('\n')) out += '\n'
71
+ return out
72
+ }
73
+
74
+ const generated = build()
75
+ const checkOnly = process.argv.includes('--check')
76
+
77
+ if (checkOnly) {
78
+ let current = ''
79
+ try { current = readFileSync(OUT, 'utf8') } catch {}
80
+ if (current !== generated) {
81
+ console.error('[build-client] lib/client.js 与 lib/src/ 源码不一致,请运行 `npm run build`。')
82
+ process.exit(1)
83
+ }
84
+ console.log('[build-client] 产物与源码一致 ✓')
85
+ } else {
86
+ writeFileSync(OUT, generated)
87
+ console.log(`[build-client] 已生成 ${OUT}(${generated.length} 字节)`)
88
+ }