Equicord/scripts/generatePluginList.ts

64 lines
2 KiB
TypeScript
Raw Permalink Normal View History

2023-03-23 04:37:32 +01:00
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2025-11-26 12:11:07 -05:00
import { readdirSync, writeFileSync } from "fs";
import { getEntryPoint, isPluginFile, parseDevs, parseEquicordDevs, parseFile, PluginData } from "./utils";
2023-03-23 04:37:32 +01:00
2025-11-26 12:11:07 -05:00
(async () => {
parseDevs();
parseEquicordDevs();
2025-09-02 16:46:02 -04:00
2025-11-26 12:11:07 -05:00
const args = process.argv.slice(2);
2023-03-23 04:37:32 +01:00
2025-11-26 12:11:07 -05:00
const equicordFlag = args.includes("--equicord");
const vencordFlag = args.includes("--vencord");
2023-03-23 04:37:32 +01:00
2025-11-26 12:11:07 -05:00
let dirs: string[];
2023-03-23 04:37:32 +01:00
2025-11-26 12:11:07 -05:00
if (equicordFlag) {
dirs = ["src/equicordplugins/_core", "src/equicordplugins"];
2025-11-26 12:11:07 -05:00
} else if (vencordFlag) {
dirs = ["src/plugins", "src/plugins/_core"];
} else {
dirs = ["src/plugins", "src/plugins/_core", "src/equicordplugins/_core", "src/equicordplugins"];
2023-03-23 04:37:32 +01:00
}
2025-11-26 12:11:07 -05:00
const outputPath = args.find(a => !a.startsWith("--")) ?? null;
2023-03-23 04:37:32 +01:00
2023-09-08 02:26:22 +02:00
const plugins = [] as PluginData[];
2025-11-26 12:11:07 -05:00
await Promise.all(
dirs.flatMap(dir =>
readdirSync(dir, { withFileTypes: true })
.filter(isPluginFile)
.map(async dirent => {
const [data] = await parseFile(await getEntryPoint(dir, dirent));
plugins.sort().push(data);
})
)
);
2023-03-23 04:37:32 +01:00
2023-09-08 02:26:22 +02:00
const data = JSON.stringify(plugins);
2023-03-23 04:37:32 +01:00
2025-11-26 12:11:07 -05:00
if (outputPath) {
writeFileSync(outputPath, data);
2023-03-23 04:37:32 +01:00
} else {
console.log(data);
}
})();