diff --git a/scripts/sync-plugins-from-repo.js b/scripts/sync-plugins-from-repo.js new file mode 100644 index 0000000..25d6045 --- /dev/null +++ b/scripts/sync-plugins-from-repo.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node +'use strict' +// 从插件源仓同步产物到本仓 plugins/runtime/ 并重建 plugins/index.json(内容寻址 + SRI)。 +// 用法:node scripts/sync-plugins-from-repo.mjs [源仓路径,默认 ../iwb-plugins-desktop] +// 幂等:内容不变时生成完全相同的文件名与清单(可直接用 git diff 验证)。 +const fs = require('fs') +const path = require('path') +const crypto = require('crypto') + +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', 'image-annotate', 'image-vectorize', 'style-source', 'white-bg-800', 'xianyi-cutout'] + +const sha = (buf) => crypto.createHash('sha256').update(buf).digest() +const shaHex = (buf) => sha(buf).toString('hex') +const sri = (buf) => 'sha256-' + sha(buf).toString('base64') + +if (!fs.existsSync(srcRoot)) { console.error('找不到插件源仓:' + srcRoot); process.exit(1) } +fs.mkdirSync(outDir, { recursive: true }) + +const manifest = [] +let copied = 0, changed = 0 +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')) + for (const old of fs.readdirSync(outDir)) { + if (old.indexOf('plugin-' + id + '.') === 0 && old !== name) { fs.unlinkSync(path.join(outDir, old)); changed++ } + } + const target = path.join(outDir, name) + if (!fs.existsSync(target) || shaHex(fs.readFileSync(target)) !== shaHex(buf)) { fs.writeFileSync(target, buf); copied++ } + manifest.push({ id: id, file: name, version: pkg.version, integrity: sri(buf) }) + console.log(id.padEnd(16), pkg.version.padEnd(8), name) +} +fs.writeFileSync(path.join(root, 'plugins', 'index.json'), JSON.stringify(manifest, null, 2) + '\n') +console.log('完成:' + manifest.length + ' 个插件,新写入 ' + copied + ' 个,清理旧产物 ' + changed + ' 个') \ No newline at end of file diff --git a/src/ui-settings-sections.js b/src/ui-settings-sections.js index 233e063..69e94b2 100644 --- a/src/ui-settings-sections.js +++ b/src/ui-settings-sections.js @@ -46,7 +46,13 @@ onChange: (e) => { const r = PluginHost.setEnabled(p.id, e.target.checked); setPluginsRev((v) => v + 1); if (!r.ok) setMsg({ type: 'err', text: p.name + ':' + r.error }) }, }), el('span', null, p.name + '(' + p.id + ' v' + p.version + (p.compatible ? '' : ',apiVersion 不兼容') + ')'), - (() => { const rt = wRuntimePlugins.find((r) => r.id === p.id); return rt ? el('span', { className: 'iwb-plugin-tag' + (rt.status === 'loaded' ? '' : ' iwb-plugin-tag-warn'), title: rt.file + ' · ' + rt.status + (rt.error ? ':' + rt.error : '') }, rt.status === 'loaded' ? '远程' : '远程·' + rt.status) : null })(), + (() => { + const rt = wRuntimePlugins.find((r) => r.id === p.id) + if (!rt) return null + // 桌面端不再有「远程 KV」概念:标签只表达 已加载/未加载,来源在行首已经标了 + const tag = isDesk() ? (rt.status === 'loaded' ? '已加载' : rt.status) : (rt.status === 'loaded' ? '远程' : '远程·' + rt.status) + return el('span', { className: 'iwb-plugin-tag' + (rt.status === 'loaded' ? '' : ' iwb-plugin-tag-warn'), title: rt.file + ' · ' + rt.status + (rt.error ? ':' + rt.error : '') }, tag) + })(), ), p.error ? el('div', { className: 'iwb-status-err' }, p.error) : null, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setTab('plugin:' + p.id) }, '设置'),