@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2
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 +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
package/bin/lib.js
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* wasmnest-plugin CLI 共享基建:常量 / 工具函数 / 零依赖 ZIP(自 cli.js 拆出)
|
|
4
|
+
*
|
|
5
|
+
* SDK_ROOT 依赖本文件位于 bin/ 下的相对位置,勿移动。
|
|
6
|
+
*/
|
|
7
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"
|
|
8
|
+
import { crc32 } from "node:zlib"
|
|
9
|
+
import { dirname, join, resolve } from "node:path"
|
|
10
|
+
import { fileURLToPath } from "node:url"
|
|
11
|
+
import { spawnSync } from "node:child_process"
|
|
12
|
+
|
|
13
|
+
const SDK_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
14
|
+
const TEMPLATE_DIR = join(SDK_ROOT, 'template')
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 组件化工具 manifest 的相对定位链(按优先级,逐级向上查找时依次尝试):
|
|
18
|
+
*
|
|
19
|
+
* 1. 桌面 SDK 自带 `tools/componentize`(P1 起的发布落点:平台仓内为
|
|
20
|
+
* `wasmnest-desktop/packages/plugin-sdk-desktop/tools/…`,npm 安装后同相对形状);
|
|
21
|
+
* 2. `node_modules/@binblink/wasmnest-plugin-sdk-desktop/tools/…`(应用工程只装了 npm 包);
|
|
22
|
+
* 3. 旧平台仓级 `tools/componentize`(P1 前的落点,兼容兜底);
|
|
23
|
+
* 4. 三仓兄弟布局 `wasmnest/tools/componentize`(旧布局,兼容兜底)。
|
|
24
|
+
*/
|
|
25
|
+
const COMPONENTIZE_CANDIDATES = [
|
|
26
|
+
join('wasmnest-desktop', 'packages', 'plugin-sdk-desktop', 'tools', 'componentize', 'Cargo.toml'),
|
|
27
|
+
join('node_modules', '@binblink', 'wasmnest-plugin-sdk-desktop', 'tools', 'componentize', 'Cargo.toml'),
|
|
28
|
+
join('tools', 'componentize', 'Cargo.toml'),
|
|
29
|
+
join('wasmnest', 'tools', 'componentize', 'Cargo.toml'),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
// ==================== 工具函数 ====================
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 定位组件化工具 `tools/componentize/Cargo.toml`。
|
|
36
|
+
*
|
|
37
|
+
* 工具原住仓库级 `packages/wasmnest-componentize`,三仓拆分后迁平台仓 `tools/componentize`,
|
|
38
|
+
* 随后(P1)收进桌面 SDK 的 `tools/` 随 npm 包发布——应用侧不再依赖平台仓工作树。
|
|
39
|
+
* 不能按固定深度从 SDK 根拼绝对路径:SDK 作为依赖安装时(pnpm 把 `file:` 依赖**复制**进
|
|
40
|
+
* `node_modules/.pnpm/…`,node 解析入口脚本不会回落到源码目录),那个深度指向包仓库内部
|
|
41
|
+
* ⇒ manifest 找不到,`cargo run --manifest-path` 直接失败。故按下列顺序定位:
|
|
42
|
+
*
|
|
43
|
+
* 1. `WASMNEST_COMPONENTIZE_MANIFEST`(显式覆盖;已设但不存在则直接报错,不静默回退);
|
|
44
|
+
* 2. 自 SDK 根与插件工作目录向上逐级查找 `COMPONENTIZE_CANDIDATES`
|
|
45
|
+
* (桌面 SDK 落点优先,旧平台仓落点仅作兼容兜底)。
|
|
46
|
+
*
|
|
47
|
+
* 全部未命中时报错并给出获取方式(此时通常意味着插件工程不在三仓布局内)。
|
|
48
|
+
*
|
|
49
|
+
* @param {string} cwd 插件工程目录(构建时的工作目录)
|
|
50
|
+
* @returns {string} 组件化工具 manifest 的绝对路径
|
|
51
|
+
*/
|
|
52
|
+
function resolveComponentizeManifest(cwd) {
|
|
53
|
+
const override = process.env.WASMNEST_COMPONENTIZE_MANIFEST
|
|
54
|
+
if (override) {
|
|
55
|
+
if (!existsSync(override)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`WASMNEST_COMPONENTIZE_MANIFEST 指向的 manifest 不存在: ${override}`,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
return override
|
|
61
|
+
}
|
|
62
|
+
for (const start of [SDK_ROOT, resolve(cwd)]) {
|
|
63
|
+
let dir = start
|
|
64
|
+
for (;;) {
|
|
65
|
+
for (const rel of COMPONENTIZE_CANDIDATES) {
|
|
66
|
+
const candidate = join(dir, rel)
|
|
67
|
+
if (existsSync(candidate)) return candidate
|
|
68
|
+
}
|
|
69
|
+
const parent = dirname(dir)
|
|
70
|
+
if (parent === dir) break
|
|
71
|
+
dir = parent
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
throw new Error(
|
|
75
|
+
`找不到组件化工具(已按 WASMNEST_COMPONENTIZE_MANIFEST、SDK 目录与插件目录 ` +
|
|
76
|
+
`${cwd} 向上查找桌面 SDK 的 tools/componentize 与旧平台仓落点)。` +
|
|
77
|
+
'该工具随 @binblink/wasmnest-plugin-sdk-desktop 发布(tools/componentize):' +
|
|
78
|
+
'插件工程需安装该 SDK,或用 WASMNEST_COMPONENTIZE_MANIFEST 指向其 Cargo.toml。',
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 解析命令行参数:positional 数组 + flags 映射(--flag value / --flag=value / 布尔 --flag) */
|
|
83
|
+
function parseArgs(argv) {
|
|
84
|
+
const positional = []
|
|
85
|
+
const flags = {}
|
|
86
|
+
for (let i = 0; i < argv.length; i++) {
|
|
87
|
+
const arg = argv[i]
|
|
88
|
+
if (arg.startsWith('--')) {
|
|
89
|
+
const eq = arg.indexOf('=')
|
|
90
|
+
if (eq !== -1) {
|
|
91
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1)
|
|
92
|
+
} else if (i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
|
|
93
|
+
flags[arg.slice(2)] = argv[++i]
|
|
94
|
+
} else {
|
|
95
|
+
flags[arg.slice(2)] = true
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
positional.push(arg)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { positional, flags }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function toPosix(p) {
|
|
105
|
+
return p.replace(/\\/g, '/')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function readJson(path, what) {
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(readFileSync(path, 'utf-8'))
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error(`[wasmnest-plugin] 读取 ${what} 失败: ${path} — ${e.message}`)
|
|
113
|
+
process.exit(1)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function run(cmd, args, cwd) {
|
|
118
|
+
const r = spawnSync(cmd, args, { cwd, stdio: 'inherit' })
|
|
119
|
+
if (r.status !== 0) {
|
|
120
|
+
console.error(`[wasmnest-plugin] 命令失败 (${cmd} ${args.join(' ')})`)
|
|
121
|
+
process.exit(1)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 解析 cargo 实际产物目录(`target_directory`)。
|
|
127
|
+
*
|
|
128
|
+
* 应用仓根 `.cargo/config.toml` 的 `[build] target-dir = "target/wasm-apps"` 会把
|
|
129
|
+
* 仓内一切 cargo 调用的产物重定向到共享目录(见该文件注释:避免各 app 重复编译
|
|
130
|
+
* 同一份依赖图)。因此不能写死 `<插件>/rust/target`——旧硬编码成立于插件住平台仓、
|
|
131
|
+
* 尚无该 config 的时期;改写后 cargo 在共享目录产出,此处仍找 `rust/target` 就会
|
|
132
|
+
* 出现「cargo 构建成功但未产出 wasm」的假失败。
|
|
133
|
+
*
|
|
134
|
+
* 以 `cargo metadata` 的 target_directory 为准(cargo 自行计算,覆盖仓内 config、
|
|
135
|
+
* `CARGO_TARGET_DIR` 与 `--target-dir`);metadata 失败时退回 `<插件>/rust/target`,
|
|
136
|
+
* 后续「产物缺失」报错仍是显性失败,不静默挑一个存在的目录。
|
|
137
|
+
*/
|
|
138
|
+
function resolveCargoTargetDir(cwd) {
|
|
139
|
+
const r = spawnSync(
|
|
140
|
+
'cargo',
|
|
141
|
+
['metadata', '--no-deps', '--format-version', '1', '--manifest-path', 'rust/Cargo.toml'],
|
|
142
|
+
{ cwd, encoding: 'utf8' },
|
|
143
|
+
)
|
|
144
|
+
if (r.status === 0) {
|
|
145
|
+
try {
|
|
146
|
+
const dir = JSON.parse(r.stdout).target_directory
|
|
147
|
+
if (dir) return dir
|
|
148
|
+
} catch {
|
|
149
|
+
// 解析失败:走兜底路径
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return join(cwd, 'rust', 'target')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** wasm 产物路径(按 cargo 实际 target 目录解析,见 resolveCargoTargetDir) */
|
|
156
|
+
function resolveWasmPath(cwd, rustLibrary) {
|
|
157
|
+
return join(
|
|
158
|
+
resolveCargoTargetDir(cwd),
|
|
159
|
+
'wasm32-unknown-unknown',
|
|
160
|
+
'release',
|
|
161
|
+
`${rustLibrary}.wasm`,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** dev-shell 的 vite 入口(存在即代表该 dev-shell 目录已装好依赖) */
|
|
166
|
+
const DEV_SHELL_VITE = 'node_modules/vite/bin/vite.js'
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 定位可用的 dev-shell 目录:优先已装依赖的仓库内 SDK 检出。
|
|
170
|
+
*
|
|
171
|
+
* 内置插件用 `file:` 说明符依赖 SDK 时,pnpm 把 SDK 硬链注入插件 node_modules:
|
|
172
|
+
* 注入副本带 dev-shell 源码但不带其 node_modules,直接用它等于每次 dev 都重装一遍。
|
|
173
|
+
* 插件 package.json 的 `file:` 说明符能指回仓库内 SDK 检出,检出已装依赖时优先用它。
|
|
174
|
+
* 外部脚手架(npm 发布的 SDK)没有 file: 说明符,走 SDK 自带 dev-shell 自行安装。
|
|
175
|
+
*/
|
|
176
|
+
function resolveDevShellDir(pluginDir) {
|
|
177
|
+
const bundled = join(SDK_ROOT, 'dev-shell')
|
|
178
|
+
const installed = (dir) => existsSync(join(dir, DEV_SHELL_VITE))
|
|
179
|
+
if (installed(bundled)) return bundled
|
|
180
|
+
// 尽力探测:读不到就退回自带 dev-shell,缺失时由调用方报错(此处不能用 readJson,
|
|
181
|
+
// 它遇解析失败直接 process.exit,会把 doctor 这类自检命令一起带走)
|
|
182
|
+
const readPkg = (path) => JSON.parse(readFileSync(path, 'utf-8'))
|
|
183
|
+
try {
|
|
184
|
+
const sdkName = readPkg(join(SDK_ROOT, 'package.json')).name
|
|
185
|
+
const deps = readPkg(join(pluginDir, 'package.json'))
|
|
186
|
+
const spec = deps.dependencies?.[sdkName] ?? deps.devDependencies?.[sdkName]
|
|
187
|
+
if (typeof spec === 'string' && spec.startsWith('file:')) {
|
|
188
|
+
const checkout = join(resolve(pluginDir, spec.slice('file:'.length)), 'dev-shell')
|
|
189
|
+
if (installed(checkout)) return checkout
|
|
190
|
+
}
|
|
191
|
+
} catch {
|
|
192
|
+
// 忽略:非 file: 依赖(npm 发布包)或读不到说明符
|
|
193
|
+
}
|
|
194
|
+
return bundled
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 递归收集目录下所有文件 */
|
|
198
|
+
function walk(dir) {
|
|
199
|
+
const out = []
|
|
200
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
201
|
+
const full = join(dir, entry.name)
|
|
202
|
+
if (entry.isDirectory()) out.push(...walk(full))
|
|
203
|
+
else out.push(full)
|
|
204
|
+
}
|
|
205
|
+
return out
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** 判断文件是否为文本(含 NUL 字节视为二进制,跳过占位符替换) */
|
|
209
|
+
function isText(file) {
|
|
210
|
+
const buf = readFileSync(file)
|
|
211
|
+
return !buf.includes(0)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 递归替换文件中的占位符 */
|
|
215
|
+
function fillPlaceholders(files, repl) {
|
|
216
|
+
for (const file of files) {
|
|
217
|
+
if (!isText(file)) continue
|
|
218
|
+
let content = readFileSync(file, 'utf-8')
|
|
219
|
+
let changed = false
|
|
220
|
+
for (const [key, value] of Object.entries(repl)) {
|
|
221
|
+
if (content.includes(key)) {
|
|
222
|
+
content = content.split(key).join(value)
|
|
223
|
+
changed = true
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (changed) writeFileSync(file, content, 'utf-8')
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** 复制目录内容(不含顶层目录本身) */
|
|
231
|
+
function copyDirContents(src, dest) {
|
|
232
|
+
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
|
233
|
+
const from = join(src, entry.name)
|
|
234
|
+
const to = join(dest, entry.name)
|
|
235
|
+
if (entry.isDirectory()) {
|
|
236
|
+
mkdirSync(to, { recursive: true })
|
|
237
|
+
copyDirContents(from, to)
|
|
238
|
+
} else {
|
|
239
|
+
copyFileSync(from, to)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ==================== ZIP 打包(store 模式,零依赖) ====================
|
|
245
|
+
|
|
246
|
+
/** 构造 store 模式 zip 字节流 */
|
|
247
|
+
function buildZip(entries) {
|
|
248
|
+
const chunks = []
|
|
249
|
+
const central = []
|
|
250
|
+
let offset = 0
|
|
251
|
+
|
|
252
|
+
// DOS 时间戳(本地时间)
|
|
253
|
+
const now = new Date()
|
|
254
|
+
const dosTime = (now.getHours() << 11) | (now.getMinutes() << 5) | (now.getSeconds() >> 1)
|
|
255
|
+
const dosDate = ((now.getFullYear() - 1980) << 9) | ((now.getMonth() + 1) << 5) | now.getDate()
|
|
256
|
+
|
|
257
|
+
for (const entry of entries) {
|
|
258
|
+
const nameBuf = Buffer.from(entry.name, 'utf-8')
|
|
259
|
+
const data = entry.data
|
|
260
|
+
const crc = crc32(data) >>> 0
|
|
261
|
+
|
|
262
|
+
// 本地文件头
|
|
263
|
+
const lh = Buffer.alloc(30)
|
|
264
|
+
lh.writeUInt32LE(0x04034b50, 0) // signature
|
|
265
|
+
lh.writeUInt16LE(20, 4) // version needed
|
|
266
|
+
lh.writeUInt16LE(0, 6) // flags
|
|
267
|
+
lh.writeUInt16LE(0, 8) // method: store
|
|
268
|
+
lh.writeUInt16LE(dosTime, 10)
|
|
269
|
+
lh.writeUInt16LE(dosDate, 12)
|
|
270
|
+
lh.writeUInt32LE(crc, 14)
|
|
271
|
+
lh.writeUInt32LE(data.length, 18) // compressed size
|
|
272
|
+
lh.writeUInt32LE(data.length, 22) // uncompressed size
|
|
273
|
+
lh.writeUInt16LE(nameBuf.length, 26)
|
|
274
|
+
lh.writeUInt16LE(0, 28) // extra len
|
|
275
|
+
chunks.push(lh, nameBuf, data)
|
|
276
|
+
|
|
277
|
+
// 中央目录项
|
|
278
|
+
const ch = Buffer.alloc(46)
|
|
279
|
+
ch.writeUInt32LE(0x02014b50, 0) // signature
|
|
280
|
+
ch.writeUInt16LE(20, 4) // version made by
|
|
281
|
+
ch.writeUInt16LE(20, 6) // version needed
|
|
282
|
+
ch.writeUInt16LE(0, 8) // flags
|
|
283
|
+
ch.writeUInt16LE(0, 10) // method
|
|
284
|
+
ch.writeUInt16LE(dosTime, 12)
|
|
285
|
+
ch.writeUInt16LE(dosDate, 14)
|
|
286
|
+
ch.writeUInt32LE(crc, 16)
|
|
287
|
+
ch.writeUInt32LE(data.length, 20)
|
|
288
|
+
ch.writeUInt32LE(data.length, 24)
|
|
289
|
+
ch.writeUInt16LE(nameBuf.length, 28)
|
|
290
|
+
ch.writeUInt16LE(0, 30) // extra len
|
|
291
|
+
ch.writeUInt16LE(0, 32) // comment len
|
|
292
|
+
ch.writeUInt16LE(0, 34) // disk start
|
|
293
|
+
ch.writeUInt16LE(0, 36) // internal attrs
|
|
294
|
+
ch.writeUInt32LE(0, 38) // external attrs
|
|
295
|
+
ch.writeUInt32LE(offset, 42) // local header offset
|
|
296
|
+
central.push(ch, nameBuf)
|
|
297
|
+
|
|
298
|
+
offset += lh.length + nameBuf.length + data.length
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const centralSize = central.reduce((sum, b) => sum + b.length, 0)
|
|
302
|
+
|
|
303
|
+
// 中央目录结束记录
|
|
304
|
+
const eocd = Buffer.alloc(22)
|
|
305
|
+
eocd.writeUInt32LE(0x06054b50, 0) // signature
|
|
306
|
+
eocd.writeUInt16LE(0, 4) // disk number
|
|
307
|
+
eocd.writeUInt16LE(0, 6) // cd start disk
|
|
308
|
+
eocd.writeUInt16LE(entries.length, 8)
|
|
309
|
+
eocd.writeUInt16LE(entries.length, 10)
|
|
310
|
+
eocd.writeUInt32LE(centralSize, 12)
|
|
311
|
+
eocd.writeUInt32LE(offset, 16)
|
|
312
|
+
eocd.writeUInt16LE(0, 20) // comment len
|
|
313
|
+
|
|
314
|
+
return Buffer.concat([...chunks, ...central, eocd])
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
function findViteBin(startDir) {
|
|
319
|
+
let dir = startDir
|
|
320
|
+
for (let i = 0; i < 6; i++) {
|
|
321
|
+
const candidate = join(dir, 'node_modules/vite/bin/vite.js')
|
|
322
|
+
if (existsSync(candidate)) return candidate
|
|
323
|
+
const parent = resolve(dir, '..')
|
|
324
|
+
if (parent === dir) break
|
|
325
|
+
dir = parent
|
|
326
|
+
}
|
|
327
|
+
return null
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
export {
|
|
332
|
+
SDK_ROOT,
|
|
333
|
+
TEMPLATE_DIR,
|
|
334
|
+
COMPONENTIZE_CANDIDATES,
|
|
335
|
+
DEV_SHELL_VITE,
|
|
336
|
+
resolveComponentizeManifest,
|
|
337
|
+
parseArgs,
|
|
338
|
+
toPosix,
|
|
339
|
+
readJson,
|
|
340
|
+
run,
|
|
341
|
+
resolveCargoTargetDir,
|
|
342
|
+
resolveWasmPath,
|
|
343
|
+
resolveDevShellDir,
|
|
344
|
+
walk,
|
|
345
|
+
fillPlaceholders,
|
|
346
|
+
copyDirContents,
|
|
347
|
+
buildZip,
|
|
348
|
+
findViteBin,
|
|
349
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* manifest-gen — plugin.json contributes/permissions 自动填充
|
|
3
|
+
*
|
|
4
|
+
* 单一事实来源是插件源码:前端 register* 调用推导 UI 扩展点,
|
|
5
|
+
* 前端 context API 使用 + Rust host 调用推导权限,
|
|
6
|
+
* Rust invoke_command 匹配臂推导 commands。
|
|
7
|
+
* (terminal handlers 推导线已随票 15 阶段 B 删除——terminal-hooks 退役,
|
|
8
|
+
* `terminal:input` 权限位同步退役;`.terminal` 宽推导规则一并移除,
|
|
9
|
+
* 否则终端 UI 域源码里的 `.terminal` 子串会把退役权限自动加回 manifest)
|
|
10
|
+
*
|
|
11
|
+
* 合并策略(保守,避免误删导致运行时拒绝):
|
|
12
|
+
* - permissions:派生结果与手工声明取并集
|
|
13
|
+
* - contributes.routes/settings/commands:
|
|
14
|
+
* 扫描到注册调用时以扫描结果为准(按 id 从旧条目继承无法静态求值的字段,
|
|
15
|
+
* 如 i18n.t() 动态 title);未扫描到时保留原值
|
|
16
|
+
* - contributes.views/navTab/terminal.toolbarItems:票 2026-10-10 批次 C2 起不再派生
|
|
17
|
+
* (对应扩展点整面退役);存量字段按「退役残留」处理,由 manifest 清理落掉
|
|
18
|
+
* - configuration/lifecycle/icon 等手工字段永不覆盖
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
|
22
|
+
import { join } from 'node:path'
|
|
23
|
+
|
|
24
|
+
// ==================== 权限映射表 ====================
|
|
25
|
+
|
|
26
|
+
/** 前端 context API 使用 → 权限(正则按合并后的前端源码匹配) */
|
|
27
|
+
const FRONTEND_PERMISSION_RULES = [
|
|
28
|
+
{ re: /\.(storage)\b/, perm: 'storage' },
|
|
29
|
+
// `session:read` 只从真实会话 API 用法推导(`context.session.list/get/onStatusChange`)。
|
|
30
|
+
// 裸 `\.session\b` 会把 i18n key(如 `monitor.footer.session`) / 普通字段名误判成
|
|
31
|
+
// 权限使用 → 构建期静默给 manifest 加一条未用到的权限。
|
|
32
|
+
{ re: /\.session\s*\.\s*(list|get|onStatusChange)\b/, perm: 'session:read' },
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
/** Rust host API 调用 → 权限(与 SDK permission 常量一一对应) */
|
|
36
|
+
const RUST_PERMISSION_RULES = [
|
|
37
|
+
{ re: /\b(storage_get|storage_set|storage_delete|db_execute|db_query)\b/, perm: 'storage' },
|
|
38
|
+
{ re: /\b(session_list|session_get)\b/, perm: 'session:read' },
|
|
39
|
+
{ re: /\bhttp_fetch\b/, perm: 'network:http' },
|
|
40
|
+
{ re: /\b(fs_read|fs_copy)\b/, perm: 'fs:read' },
|
|
41
|
+
{ re: /\bfs_write\b/, perm: 'fs:write' },
|
|
42
|
+
// 内网穿透(T06):服务端 / 客户端分域;configure / status 是共用面,不推导。
|
|
43
|
+
{ re: /\btunnel_(expose|unexpose|issue_pairing_ticket)\b/, perm: 'tunnel:serve' },
|
|
44
|
+
{ re: /\btunnel_(connect|close)\b/, perm: 'tunnel:connect' },
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* UI 注册调用 → 权限
|
|
49
|
+
*
|
|
50
|
+
* 票 2026-10-10 批次 C2:`registerToolboxPage` / `registerNavTab` /
|
|
51
|
+
* `registerTerminalToolbarItem` / `registerTerminalView` 四个旧嵌入扩展点已随宿主壳
|
|
52
|
+
* 改纯 surface 形态整面退役,对应权限位(ui:toolbox / ui:navtab / ui:input)同时失效。
|
|
53
|
+
* 本生成器不再为它们产出 `contributes` 与权限位——继续产出等于让 manifest 声明
|
|
54
|
+
* 退役权限,装载期会被 fail-visible 闸门直接拒绝(见 SDK permission::RETIRED_PERMISSIONS)。
|
|
55
|
+
*/
|
|
56
|
+
const REGISTER_PERMISSIONS = {
|
|
57
|
+
registerSettingsSection: 'ui:settings',
|
|
58
|
+
registerRoute: 'ui:route',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 已退役权限位(票 2026-10-10 批次 C2)
|
|
63
|
+
*
|
|
64
|
+
* 与 SDK `permission::RETIRED_PERMISSIONS` 逐字一致;生成期剔除,宿主装载期拒载,
|
|
65
|
+
* 两道闸门都认这张表(见 SDK permission.rs 的同名常量与装载期校验)。
|
|
66
|
+
*/
|
|
67
|
+
const RETIRED_PERMISSIONS = ['ui:toolbox', 'ui:navtab', 'ui:input']
|
|
68
|
+
|
|
69
|
+
// ==================== 文件收集 ====================
|
|
70
|
+
|
|
71
|
+
const FRONTEND_EXTS = new Set(['.ts', '.tsx', '.vue', '.js'])
|
|
72
|
+
|
|
73
|
+
/** 递归收集指定扩展名的文件 */
|
|
74
|
+
function collectFiles(dir, exts, out = []) {
|
|
75
|
+
if (!existsSync(dir)) return out
|
|
76
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
77
|
+
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name.startsWith('.')) continue
|
|
78
|
+
const full = join(dir, entry.name)
|
|
79
|
+
if (entry.isDirectory()) {
|
|
80
|
+
collectFiles(full, exts, out)
|
|
81
|
+
} else if (entry.isFile() && exts.some((e) => entry.name.endsWith(e))) {
|
|
82
|
+
out.push(full)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ==================== 对象字面量解析 ====================
|
|
89
|
+
|
|
90
|
+
/** 从源码指定下标起提取配对的 {...} 对象字面量文本 */
|
|
91
|
+
function extractObjectLiteral(source, fromIndex) {
|
|
92
|
+
const start = source.indexOf('{', fromIndex)
|
|
93
|
+
if (start === -1) return null
|
|
94
|
+
let depth = 0
|
|
95
|
+
let inStr = null
|
|
96
|
+
for (let i = start; i < source.length; i++) {
|
|
97
|
+
const ch = source[i]
|
|
98
|
+
if (inStr) {
|
|
99
|
+
if (ch === '\\') i++
|
|
100
|
+
else if (ch === inStr) inStr = null
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
if (ch === "'" || ch === '"' || ch === '`') inStr = ch
|
|
104
|
+
else if (ch === '{') depth++
|
|
105
|
+
else if (ch === '}') {
|
|
106
|
+
depth--
|
|
107
|
+
if (depth === 0) return source.slice(start, i + 1)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 按顶层逗号切分对象字面量内部(忽略嵌套与字符串内的逗号) */
|
|
114
|
+
function splitTopLevel(body) {
|
|
115
|
+
const parts = []
|
|
116
|
+
let depth = 0
|
|
117
|
+
let inStr = null
|
|
118
|
+
let cur = ''
|
|
119
|
+
for (let i = 0; i < body.length; i++) {
|
|
120
|
+
const ch = body[i]
|
|
121
|
+
if (inStr) {
|
|
122
|
+
cur += ch
|
|
123
|
+
if (ch === '\\') cur += body[++i] ?? ''
|
|
124
|
+
else if (ch === inStr) inStr = null
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
if (ch === "'" || ch === '"' || ch === '`') { inStr = ch; cur += ch; continue }
|
|
128
|
+
if (ch === '{' || ch === '[' || ch === '(') depth++
|
|
129
|
+
else if (ch === '}' || ch === ']' || ch === ')') depth--
|
|
130
|
+
if (ch === ',' && depth === 0) {
|
|
131
|
+
parts.push(cur)
|
|
132
|
+
cur = ''
|
|
133
|
+
} else {
|
|
134
|
+
cur += ch
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (cur.trim()) parts.push(cur)
|
|
138
|
+
return parts
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 分类字面量值:字符串/数字/布尔/标识符,动态表达式返回 null */
|
|
142
|
+
function classifyValue(raw) {
|
|
143
|
+
const text = raw.trim().replace(/,$/, '').trim()
|
|
144
|
+
const strMatch = text.match(/^(['"])((?:\\.|(?!\1).)*)\1$/s)
|
|
145
|
+
if (strMatch) return strMatch[2]
|
|
146
|
+
if (/^-?\d+(\.\d+)?$/.test(text)) return Number(text)
|
|
147
|
+
if (text === 'true') return true
|
|
148
|
+
if (text === 'false') return false
|
|
149
|
+
if (/^[A-Za-z_$][\w$]*$/.test(text)) return { __ident: text }
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 解析简单对象字面量为键值映射(嵌套对象/动态值 → null) */
|
|
154
|
+
function parseObjectLiteral(literal) {
|
|
155
|
+
const body = literal.slice(literal.indexOf('{') + 1, literal.lastIndexOf('}'))
|
|
156
|
+
const result = {}
|
|
157
|
+
for (const part of splitTopLevel(body)) {
|
|
158
|
+
const m = part.match(/^\s*(?:['"](\w+)['"]|(\w+))\s*:\s*([\s\S]+)$/)
|
|
159
|
+
if (!m) continue
|
|
160
|
+
const key = m[1] || m[2]
|
|
161
|
+
result[key] = classifyValue(m[3])
|
|
162
|
+
}
|
|
163
|
+
return result
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 提取源码中所有 `.callName({...})` 注册调用的对象参数 */
|
|
167
|
+
function findRegisterCalls(source, callName) {
|
|
168
|
+
const results = []
|
|
169
|
+
const re = new RegExp(`\\.${callName}\\s*\\(`, 'g')
|
|
170
|
+
let m
|
|
171
|
+
while ((m = re.exec(source)) !== null) {
|
|
172
|
+
const literal = extractObjectLiteral(source, m.index + m[0].length - 1)
|
|
173
|
+
if (literal) results.push(parseObjectLiteral(literal))
|
|
174
|
+
}
|
|
175
|
+
return results
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ==================== 字段合并 ====================
|
|
179
|
+
|
|
180
|
+
/** 旧条目按 id 建索引 */
|
|
181
|
+
function indexById(entries) {
|
|
182
|
+
const map = new Map()
|
|
183
|
+
for (const e of entries || []) {
|
|
184
|
+
if (e && e.id) map.set(e.id, e)
|
|
185
|
+
}
|
|
186
|
+
return map
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 合并扫描条目与旧条目:扫描值优先,null(动态表达式)回退旧值,再回退默认值 */
|
|
190
|
+
function mergeEntry(scanned, old, defaults = {}) {
|
|
191
|
+
const merged = { ...defaults }
|
|
192
|
+
if (old) Object.assign(merged, old)
|
|
193
|
+
for (const [key, value] of Object.entries(scanned)) {
|
|
194
|
+
if (value === null || value === undefined) continue
|
|
195
|
+
if (value && typeof value === 'object' && value.__ident) {
|
|
196
|
+
merged[key] = value.__ident
|
|
197
|
+
continue
|
|
198
|
+
}
|
|
199
|
+
merged[key] = value
|
|
200
|
+
}
|
|
201
|
+
return merged
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ==================== Rust 扫描 ====================
|
|
205
|
+
|
|
206
|
+
/** 提取 invoke_command 匹配臂中的 command id 列表 */
|
|
207
|
+
function extractRustCommands(rustSource) {
|
|
208
|
+
const fnIndex = rustSource.search(/\bfn\s+invoke_command\b/)
|
|
209
|
+
if (fnIndex === -1) return []
|
|
210
|
+
const body = extractObjectLiteral(rustSource, fnIndex)
|
|
211
|
+
if (!body) return []
|
|
212
|
+
const ids = []
|
|
213
|
+
const re = /"([\w][\w.-]*)"\s*=>/g
|
|
214
|
+
let m
|
|
215
|
+
while ((m = re.exec(body)) !== null) ids.push(m[1])
|
|
216
|
+
return [...new Set(ids)]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ==================== 主入口 ====================
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 扫描插件源码并自动填充 plugin.json 的 contributes/permissions
|
|
223
|
+
* @param {string} cwd 插件工程根目录
|
|
224
|
+
* @param {{ check?: boolean }} options check 模式只报告不写入
|
|
225
|
+
* @returns {{ changed: boolean, report: string[] }}
|
|
226
|
+
*/
|
|
227
|
+
export function generateManifest(cwd, { check = false } = {}) {
|
|
228
|
+
const manifestPath = join(cwd, 'plugin.json')
|
|
229
|
+
if (!existsSync(manifestPath)) {
|
|
230
|
+
throw new Error(`plugin.json 不存在: ${manifestPath}`)
|
|
231
|
+
}
|
|
232
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'))
|
|
233
|
+
const report = []
|
|
234
|
+
const permissions = new Set(manifest.permissions || [])
|
|
235
|
+
const contributes = { ...(manifest.contributes || {}) }
|
|
236
|
+
|
|
237
|
+
// ---------- 前端扫描 ----------
|
|
238
|
+
const frontendSource = collectFiles(join(cwd, 'src'), [...FRONTEND_EXTS])
|
|
239
|
+
.map((f) => readFileSync(f, 'utf-8'))
|
|
240
|
+
.join('\n')
|
|
241
|
+
|
|
242
|
+
const settingsSections = findRegisterCalls(frontendSource, 'registerSettingsSection')
|
|
243
|
+
|
|
244
|
+
if (settingsSections.length > 0) {
|
|
245
|
+
const old = contributes.settings && contributes.settings.id ? contributes.settings : null
|
|
246
|
+
contributes.settings = mergeEntry(
|
|
247
|
+
settingsSections[0],
|
|
248
|
+
old && old.id === settingsSections[0].id ? old : null
|
|
249
|
+
)
|
|
250
|
+
permissions.add(REGISTER_PERMISSIONS.registerSettingsSection)
|
|
251
|
+
report.push(`contributes.settings ← ${contributes.settings.id}`)
|
|
252
|
+
}
|
|
253
|
+
const routes = findRegisterCalls(frontendSource, 'registerRoute')
|
|
254
|
+
if (routes.length > 0) {
|
|
255
|
+
const old = indexById(contributes.routes)
|
|
256
|
+
contributes.routes = routes.map((s) => mergeEntry(s, old.get(s.id)))
|
|
257
|
+
permissions.add(REGISTER_PERMISSIONS.registerRoute)
|
|
258
|
+
report.push(`contributes.routes ← ${contributes.routes.map((v) => v.id).join(', ')}`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (const rule of FRONTEND_PERMISSION_RULES) {
|
|
262
|
+
if (rule.re.test(frontendSource)) {
|
|
263
|
+
if (!permissions.has(rule.perm)) report.push(`permissions + ${rule.perm}(前端 API 使用)`)
|
|
264
|
+
permissions.add(rule.perm)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ---------- Rust 扫描 ----------
|
|
269
|
+
const rustSource = collectFiles(join(cwd, 'rust/src'), ['.rs'])
|
|
270
|
+
.map((f) => readFileSync(f, 'utf-8'))
|
|
271
|
+
.join('\n')
|
|
272
|
+
|
|
273
|
+
if (rustSource) {
|
|
274
|
+
for (const rule of RUST_PERMISSION_RULES) {
|
|
275
|
+
if (rule.re.test(rustSource)) {
|
|
276
|
+
if (!permissions.has(rule.perm)) report.push(`permissions + ${rule.perm}(Rust host 调用)`)
|
|
277
|
+
permissions.add(rule.perm)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const commandIds = extractRustCommands(rustSource)
|
|
282
|
+
if (commandIds.length > 0) {
|
|
283
|
+
const old = indexById(contributes.commands)
|
|
284
|
+
contributes.commands = commandIds.map((id) =>
|
|
285
|
+
mergeEntry({ id }, old.get(id), { id, title: id })
|
|
286
|
+
)
|
|
287
|
+
report.push(`contributes.commands ← ${commandIds.length} 个`)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ---------- 退役面清理(票 2026-10-10 批次 C2) ----------
|
|
292
|
+
//
|
|
293
|
+
// 上面不再派生 contributes.views / navTab / terminal.toolbarItems,但存量 manifest
|
|
294
|
+
// 里还留着它们;按上面的「未扫描到则保留」策略会被原样保留——那等于每次重新生成
|
|
295
|
+
// 都把退役面原样带回,且 permissions 里的退役位会让宿主装载期直接拒载。
|
|
296
|
+
// 这里显式剔除:退役是不可逆的,生成器必须幂等地把它落干净。
|
|
297
|
+
for (const key of ['views', 'navTab']) {
|
|
298
|
+
if (contributes[key] !== undefined) {
|
|
299
|
+
delete contributes[key]
|
|
300
|
+
report.push(`contributes.${key} - 退役面(票 2026-10-10 C2)已剔除`)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (contributes.terminal?.toolbarItems) {
|
|
304
|
+
delete contributes.terminal.toolbarItems
|
|
305
|
+
report.push('contributes.terminal.toolbarItems - 退役面(票 2026-10-10 C2)已剔除')
|
|
306
|
+
if (Object.keys(contributes.terminal).length === 0) delete contributes.terminal
|
|
307
|
+
}
|
|
308
|
+
for (const perm of RETIRED_PERMISSIONS) {
|
|
309
|
+
if (permissions.delete(perm)) {
|
|
310
|
+
report.push(`permissions - ${perm}(票 2026-10-10 C2 退役位)已剔除`)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ---------- 生成结果 ----------
|
|
315
|
+
const generated = {
|
|
316
|
+
...manifest,
|
|
317
|
+
permissions: [...permissions].sort(),
|
|
318
|
+
contributes,
|
|
319
|
+
}
|
|
320
|
+
const changed = JSON.stringify(generated, null, 2) !== JSON.stringify(manifest, null, 2)
|
|
321
|
+
|
|
322
|
+
if (changed && !check) {
|
|
323
|
+
writeFileSync(manifestPath, JSON.stringify(generated, null, 2) + '\n', 'utf-8')
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return { changed, report }
|
|
327
|
+
}
|