- 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 一并入库
36 lines
2.0 KiB
JavaScript
36 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
||
'use strict'
|
||
// 生成插件市场索引:plugins/index.json + plugins/meta.json → market/index.json + market/plugins/*
|
||
// 产物用于 market.maqiart.eu.org(纯静态)。
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
const crypto = require('crypto')
|
||
const root = path.resolve(__dirname, '..')
|
||
const man = JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'index.json'), 'utf8'))
|
||
const meta = JSON.parse(fs.readFileSync(path.join(root, 'plugins', 'meta.json'), 'utf8'))
|
||
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)
|
||
fs.writeFileSync(path.join(out, 'plugins', e.file), buf)
|
||
const m = meta[e.id] || {}
|
||
plugins.push({
|
||
id: e.id, name: m.name || e.id, desc: m.desc || '', author: m.author || 'official', icon: m.icon || '', color: m.color || '', tags: Array.isArray(m.tags) ? m.tags : [],
|
||
version: e.version, apiVersion: 1,
|
||
file: 'plugins/' + e.file,
|
||
size: buf.length,
|
||
sha256: sha(buf).digest('hex'),
|
||
integrity: 'sha256-' + sha(buf).digest('base64'),
|
||
})
|
||
}
|
||
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 + ' 个插件' + (skipped ? '(跳过 ' + skipped + ' 个目录插件)' : ''))
|
||
for (const p of plugins) console.log(' ' + p.id.padEnd(16) + p.version.padEnd(8) + (p.size + ' B')) |