const fs = require('fs'); const path = require('path'); const cp = require('child_process'); const { getProcessArgs } = require('./util'); const envs = getProcessArgs(); const { prefix } = envs; const run = (params) => { const { urlPrefix, homeDir } = params; const metaFiles = `${cp.execSync( `cd plugins && find . -name "plugin-meta.json"` )}`.split('\n').filter(Boolean) .sort(); console.log('files', metaFiles); const metas = metaFiles.map((metaFile) => { try { const metaFilePath = path.join(homeDir, metaFile); const metaDirPath = path.dirname(metaFilePath); const metaDirRelativePath = path.relative(homeDir, metaDirPath); const meta = require(metaFilePath); const { logo } = meta; const readme = `${urlPrefix}${metaDirRelativePath}/README.md` ; return { // 如果插件市场一个category下有重名name,这里可以考虑加个区别的内容 id: `private-for-cnb/${metaDirRelativePath}`, name: meta.name, description: meta.description, tags: [...new Set(['仅内网', ...meta.tags])], readme, logo: logo ? `${urlPrefix}${metaDirRelativePath}/${logo}` : undefined, source: meta.source, bugs: meta.bugs, images: meta.images, // 方便有问题追溯 generate_from: 'cnb/plugins/cnbcool/market', }; } catch (e) { console.error(`parse meta file ${metaFile} error`, e); } }); console.log('metas', metas); fs.writeFileSync(path.join(homeDir, '../plugins.json'), JSON.stringify(metas, null, 2)); }; const main = () => { run({ urlPrefix: prefix, homeDir: path.join(__dirname, '../plugins') }); }; try { main(); } catch (e) { console.error(e); process.exit(-1); }