summary refs log tree commit diff
path: root/scripts/build/plugin_prepare.js
blob: 247ad22d068ae33017306612ae4a09e26e562fbb (plain) (blame)
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
const { execSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const { argv, stdout, exit } = require("process");
const { execIn, parts, getDirs, walk, sanitizeVarName } = require("../utils");

module.exports = function (config) {
	console.log(`==> Building plugin index...`);
	let output = 'import { Plugin } from "util/plugin";\n';

	const dirs = fs.readdirSync(config.pluginDir).filter((x) => {
		try {
			fs.readdirSync(path.join(config.pluginDir, x));
			return true;
		} catch (e) {
			return false;
		}
	});
	dirs.forEach((x) => {
		let pluginManifest = require(path.join(config.pluginDir, x, "plugin.json"));
		console.log(`  ==> Registering plugin: ${pluginManifest.name} (${pluginManifest.id}) by ${pluginManifest.authors}`);
		output += `import * as ${sanitizeVarName(x)} from "./${x}/${pluginManifest.mainClass}";\n`;
	});
	output += `\nexport const PluginIndex: any = {\n`;
	dirs.forEach((x) => {
		output += `    "${x}": new ${sanitizeVarName(x)}.default(),\n`; //ctor test: '${path.resolve(path.join(pluginDir, x))}', require('./${x}/plugin.json')
	});
	output += `};`;

	fs.writeFileSync(path.join(config.pluginDir, "PluginIndex.ts"), output);
};