- loader 新增 loadFolder():manifest → main.js(逐文件 sha256,内置信随包 index.json)→ blob 注入;
样式文本暂存,激活时注入、停用时移除(配合 host 新增 onActivate/onDeactivate 钩子)
- storage-file 增加 plugins.listDirs/readFile/writeFile/writeBinary/mkdir/removeDir(按段校验,禁 ..)
- app.js:三路合并支持目录条目(dir/main/style/files),失败隔离 + 按 id 排序
- 修复:无 iwb_plugins 记录时插件永不激活(首次安装面板显示「未加载」)
- 备份模块兼容目录形态;市场暂时跳过目录插件(M3 zip 后恢复)
- 试点:image-annotate 转为 plugins/image-annotate/{manifest.json,main.js}
- 方案文档 docs/PLUGIN-ARCHITECTURE-PLAN.md 一并入库
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
||
'use strict'
|
||
// 桌面版专用:把 plugins/runtime/ 下的运行时插件拷进 dist/plugins/。
|
||
// 网页版插件由 Cloudflare KV 在 /plugins/* 提供;桌面端没有服务端,只能随包发布。
|
||
// 刻意不改 scripts/build.js(上游文件),单独一步执行,保持桌面侧差异最小。
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
const root = path.resolve(__dirname, '..')
|
||
const src = path.join(root, 'plugins', 'runtime')
|
||
const dst = path.join(root, 'dist', 'plugins')
|
||
|
||
if (!fs.existsSync(src)) {
|
||
console.error('[copy-plugins] 缺少 plugins/runtime,无法打包运行时插件')
|
||
process.exit(1)
|
||
}
|
||
fs.mkdirSync(dst, { recursive: true })
|
||
|
||
let count = 0
|
||
for (const name of fs.readdirSync(src)) {
|
||
fs.copyFileSync(path.join(src, name), path.join(dst, name))
|
||
count++
|
||
}
|
||
// v3.25.41(M1):目录插件 <plugins>/<id>/{manifest.json,main.js} 一并进包(应用按 /plugins/<id>/… 取)
|
||
let folders = 0
|
||
const pluginsRoot = path.join(root, 'plugins')
|
||
for (const name of fs.readdirSync(pluginsRoot)) {
|
||
const abs = path.join(pluginsRoot, name)
|
||
if (!fs.statSync(abs).isDirectory()) continue
|
||
if (name === 'runtime' || name === 'local') continue
|
||
if (!fs.existsSync(path.join(abs, 'manifest.json'))) continue
|
||
fs.cpSync(abs, path.join(dst, name), { recursive: true })
|
||
folders++
|
||
}
|
||
// 索引与插件文件必须同源同包:应用按 index.json 里的 filename / dir 去 /plugins/ 取
|
||
fs.copyFileSync(path.join(root, 'plugins', 'index.json'), path.join(dst, 'index.json'))
|
||
console.log('[copy-plugins] 已拷入 ' + count + ' 个文件 + ' + folders + ' 个目录插件 → dist/plugins/')
|