-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeRepo.js
66 lines (52 loc) · 2.05 KB
/
makeRepo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const fs = require('fs');
const path = require('path');
const jsToml = require('js-toml');
const moment = require('moment');
const pluginsRoot = 'plugins';
const downloadRoot = `https://raw.githubusercontent.com/${ process.env.GITHUB_REPOSITORY }/main/plugins`;
// 读取并解析 manifest 文件
function readManifest(name) {
const manifestPath = path.join(pluginsRoot, `stable/${name}/${name}.json`);
const manifestContent = fs.readFileSync(manifestPath, 'utf-8');
return JSON.parse(manifestContent);
}
// 主函数
(async () => {
// 读取并解析 State.toml 文件
const stateTomlPath = path.join(pluginsRoot, 'State.toml');
const stateTomlContent = fs.readFileSync(stateTomlPath, 'utf-8');
const config = jsToml.load(stateTomlContent);
let pluginNames = [];
for (const [channel, plugins] of Object.entries(config.channels)) {
for (const [pluginName, pluginData] of Object.entries(plugins.plugins)) {
const timeBuiltRaw = pluginData.time_built;
const timeBuilt = moment(timeBuiltRaw, moment.ISO_8601).utc();
pluginNames.push({
name: pluginName,
timeBuilt
});
}
}
let pluginList = [];
for (const plugin of pluginNames) {
let manifest;
try {
manifest = readManifest(plugin.name);
} catch (error) {
console.log('Could not parse plugin manifest.');
continue;
}
manifest.LastUpdate = Math.floor(plugin.timeBuilt.valueOf() / 1000);
manifest.IconUrl = `${ downloadRoot }/stable/${ plugin.name }/images/icon.png`;
manifest.DownloadLinkInstall = `${ downloadRoot }/stable/${ plugin.name }/latest.zip`;
// TODO: these aren't supposed to be the same
manifest.DownloadLinkTesting = manifest.DownloadLinkInstall;
manifest.DownloadLinkUpdate = manifest.DownloadLinkInstall;
manifest.DownloadCount = 999999999;
manifest._isDip17Plugin = true;
manifest._Dip17Channel = 'stable';
pluginList.push(manifest);
}
fs.writeFileSync('repo.json', JSON.stringify(pluginList, null, 2));
console.log('repo.json has been written successfully.');
})();