feat(plugins): P2 插件市场(market 索引生成 + 应用内安装/更新/卸载,sha256 校验写 plugins/)
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m10s

This commit is contained in:
qiqi committed 2026-11-17 11:49:34 +08:00
1 parent c1b9328978
commit 51bc9c581a
8 files changed
+195 -2

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
#!/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 = []
for (const e of man) {
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',
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 + ' 个插件')
for (const p of plugins) console.log(' ' + p.id.padEnd(16) + p.version.padEnd(8) + (p.size + ' B'))