feat(plugin): 插件目录化 M1 —— 目录插件加载 + 旧单文件兼容 v3.25.41
- 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 一并入库
This commit is contained in:
1 parent
8dbc0c0603
commit
7ed3ba6738
17 files changed
+673
-22
No files matched your search
+13
-2
@@ -21,6 +21,17 @@ for (const name of fs.readdirSync(src)) {
|
||||
fs.copyFileSync(path.join(src, name), path.join(dst, name))
|
||||
count++
|
||||
}
|
||||
// 索引与插件文件必须同源同包:应用按 index.json 里的 filename 去 /plugins/ 取
|
||||
// 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 + ' 个插件 → dist/plugins/')
|
||||
console.log('[copy-plugins] 已拷入 ' + count + ' 个文件 + ' + folders + ' 个目录插件 → dist/plugins/')
|
||||
@@ -12,7 +12,10 @@ const out = path.join(root, 'market')
|
||||
fs.mkdirSync(path.join(out, 'plugins'), { recursive: true })
|
||||
const sha = (buf) => crypto.createHash('sha256').update(buf)
|
||||
const plugins = []
|
||||
let skipped = 0
|
||||
for (const e of man) {
|
||||
// 目录插件(v3.25.41):市场打包(zip)在 M3 落地,这一版先跳过,避免生成缺 bundle 的条目
|
||||
if (e.dir) { skipped++; console.warn('跳过目录插件(待 M3 打包):' + e.id); continue }
|
||||
const src = path.join(root, 'plugins', 'runtime', e.file)
|
||||
if (!fs.existsSync(src)) { console.warn('缺少产物:' + e.file); continue }
|
||||
const buf = fs.readFileSync(src)
|
||||
@@ -29,5 +32,5 @@ for (const e of man) {
|
||||
}
|
||||
const index = { version: 1, updatedAt: new Date().toISOString(), plugins: plugins }
|
||||
fs.writeFileSync(path.join(out, 'index.json'), JSON.stringify(index, null, 2) + '\n')
|
||||
console.log('market/index.json:' + plugins.length + ' 个插件')
|
||||
console.log('market/index.json:' + plugins.length + ' 个插件' + (skipped ? '(跳过 ' + skipped + ' 个目录插件)' : ''))
|
||||
for (const p of plugins) console.log(' ' + p.id.padEnd(16) + p.version.padEnd(8) + (p.size + ' B'))
|
||||
@@ -11,6 +11,8 @@ const root = path.resolve(__dirname, '..')
|
||||
const srcRoot = process.argv[2] ? path.resolve(process.argv[2]) : path.resolve(root, '..', 'iwb-plugins-desktop')
|
||||
const outDir = path.join(root, 'plugins', 'runtime')
|
||||
const IDS = ['batch-export', 'blank-canvas', 'browser', 'image-annotate', 'image-vectorize', 'style-source', 'white-bg-800', 'xianyi-cutout']
|
||||
// v3.25.41(M1):目录化插件试点 —— 这些 id 产出 <id>/{manifest.json,main.js},其余仍是单文件(双轨兼容)
|
||||
const FOLDER_IDS = ['image-annotate']
|
||||
|
||||
const sha = (buf) => crypto.createHash('sha256').update(buf).digest()
|
||||
const shaHex = (buf) => sha(buf).toString('hex')
|
||||
@@ -21,12 +23,43 @@ fs.mkdirSync(outDir, { recursive: true })
|
||||
|
||||
const manifest = []
|
||||
let copied = 0, changed = 0
|
||||
const metaAll = (() => { try { return JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'meta.json'), 'utf8')) } catch (e) { return {} } })()
|
||||
for (const id of IDS) {
|
||||
const artifact = path.join(srcRoot, id, 'src', 'index.js')
|
||||
if (!fs.existsSync(artifact)) { console.warn('跳过 ' + id + '(无 ' + artifact + ')'); continue }
|
||||
const buf = fs.readFileSync(artifact)
|
||||
const name = 'plugin-' + id + '.' + shaHex(buf).slice(0, 12) + '.js'
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(srcRoot, id, 'package.json'), 'utf8'))
|
||||
|
||||
if (FOLDER_IDS.indexOf(id) >= 0) {
|
||||
// 目录形态:plugins/<id>/{manifest.json,main.js}
|
||||
const dir = path.join(root, 'plugins', id)
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
const mainPath = path.join(dir, 'main.js')
|
||||
if (!fs.existsSync(mainPath) || shaHex(fs.readFileSync(mainPath)) !== shaHex(buf)) { fs.writeFileSync(mainPath, buf); copied++ }
|
||||
const meta = metaAll[id] || {}
|
||||
const manifestJson = {
|
||||
id: id,
|
||||
name: meta.name || id,
|
||||
version: pkg.version,
|
||||
apiVersion: Number((pkg.ibwPlugin && pkg.ibwPlugin.apiVersion) || 1),
|
||||
main: 'main.js',
|
||||
description: meta.desc || '',
|
||||
author: meta.author || 'official',
|
||||
icon: meta.icon || '',
|
||||
tags: Array.isArray(meta.tags) ? meta.tags : [],
|
||||
files: { 'main.js': shaHex(buf) },
|
||||
}
|
||||
fs.writeFileSync(path.join(dir, 'manifest.json'), JSON.stringify(manifestJson, null, 2) + '\n')
|
||||
// 同 id 的旧单文件产物清理(目录优先,留着会造成两份)
|
||||
for (const old of fs.readdirSync(outDir)) {
|
||||
if (old.indexOf('plugin-' + id + '.') === 0) { fs.unlinkSync(path.join(outDir, old)); changed++ }
|
||||
}
|
||||
manifest.push({ id: id, dir: id, main: 'main.js', style: manifestJson.style || '', version: pkg.version, files: manifestJson.files })
|
||||
console.log(id.padEnd(16), pkg.version.padEnd(8), 'dir/' + id + '/main.js')
|
||||
continue
|
||||
}
|
||||
|
||||
const name = 'plugin-' + id + '.' + shaHex(buf).slice(0, 12) + '.js'
|
||||
for (const old of fs.readdirSync(outDir)) {
|
||||
if (old.indexOf('plugin-' + id + '.') === 0 && old !== name) { fs.unlinkSync(path.join(outDir, old)); changed++ }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user