From 9d6021f0b985ca09fded65af87166c1f7a70141a Mon Sep 17 00:00:00 2001 From: megumin Date: Mon, 17 Oct 2022 22:46:52 +0100 Subject: feat: gitignored src/userplugins directory (#112) --- scripts/build/common.mjs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 59153a6..deb8ff4 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -1,5 +1,6 @@ import { execSync } from "child_process"; import esbuild from "esbuild"; +import { existsSync } from "fs"; import { readdir } from "fs/promises"; const watch = process.argv.includes("--watch"); @@ -41,21 +42,27 @@ export const globPlugins = { }); build.onLoad({ filter: /^plugins$/, namespace: "import-plugins" }, async () => { - const files = await readdir("./src/plugins"); + const pluginDirs = ["plugins", "userplugins"]; let code = ""; let plugins = "\n"; - for (let i = 0; i < files.length; i++) { - if (files[i] === "index.ts") { - continue; + let i = 0; + for (const dir of pluginDirs) { + if (!existsSync(`./src/${dir}`)) continue; + const files = await readdir(`./src/${dir}`); + for (const file of files) { + if (file === "index.ts") { + continue; + } + const mod = `p${i}`; + code += `import ${mod} from "./${dir}/${file.replace(/.tsx?$/, "")}";\n`; + plugins += `[${mod}.name]:${mod},\n`; + i++; } - const mod = `p${i}`; - code += `import ${mod} from "./${files[i].replace(/.tsx?$/, "")}";\n`; - plugins += `[${mod}.name]:${mod},\n`; } code += `export default {${plugins}};`; return { contents: code, - resolveDir: "./src/plugins" + resolveDir: "./src" }; }); } -- cgit