From 3cab1d9b5994f9bb0a1dc97f8e94bd7e040f3ed1 Mon Sep 17 00:00:00 2001 From: Nicholas Phillips Date: Sat, 3 Aug 2024 10:56:23 -0400 Subject: [PATCH] Recursive building set up. --- build.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index 8a9847b..e3a88a6 100644 --- a/build.js +++ b/build.js @@ -131,11 +131,23 @@ async function downloadFiles() { } async function buildScript(scriptPath) { + const srcDir = path.dirname(scriptPath); const scriptName = path.basename(scriptPath, ".user.js"); - const metaPath = path.join(srcDir, `${scriptName}.meta.js`); - const outPath = path.join(outDir, `${scriptName}.user.js`); - const tempPath = path.join(outDir, `${scriptName}.user.temp.js`); - const minifiedPath = path.join(outDir, `${scriptName}.min.user.js`); + const metaPath = path.join(srcDir, scriptName + `.meta.js`); + let outdDir = [outDir, srcDir.replace(/^src(\\|\/)?/, "")]; + const outPath = path.join(...outdDir, `${scriptName}.user.js`); + const tempPath = path.join(...outdDir, `${scriptName}.user.temp.js`); + const minifiedPath = path.join(...outdDir, `${scriptName}.min.user.js`); + console.log({ + srcDir, + outdDir, + scriptPath, + scriptName, + metaPath, + outPath, + tempPath, + minifiedPath, + }); if (!fs.existsSync(metaPath)) { console.error(`Meta file not found: ${metaPath}`); @@ -183,8 +195,11 @@ async function buildScript(scriptPath) { } function buildAll() { - const files = fs.readdirSync(srcDir); + const files = fs.readdirSync(srcDir, { + recursive: true, + }); files.forEach((file) => { + console.log(file); if (file.endsWith(".user.js")) { buildScript(path.join(srcDir, file)); }