Files
image-workbench-desktop/scripts/gen-market.js
T
2026-11-17 11:49:34 +08:00

33 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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'))