From f8358c93616bd3ef54b946c8977f558a8089ad25 Mon Sep 17 00:00:00 2001 From: Pier-Paolo Mammi Date: Mon, 29 Jun 2026 13:52:58 +0200 Subject: [PATCH] clean destination of all files and empty subfolders --- scripts/generate-http-docs.js | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/scripts/generate-http-docs.js b/scripts/generate-http-docs.js index 1852a6d..befad3f 100644 --- a/scripts/generate-http-docs.js +++ b/scripts/generate-http-docs.js @@ -654,6 +654,37 @@ function writeEnvironmentTemplates(sourceDir, outputRoot) { return dotenvVariablesByTarget; } +function cleanFolder(dir) { + if (!fs.existsSync(dir)) return; + + const entries = fs.readdirSync(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + + if (entry.isDirectory()) { + // Ricorsione + cleanFolder(fullPath); + + // Dopo la pulizia, se la cartella รจ vuota โ†’ cancellala + const remaining = fs.readdirSync(fullPath); + if (remaining.length === 0) { + fs.rmdirSync(fullPath); + //console.log(`๐Ÿ—‘๏ธ Cartella rimossa: ${fullPath}`); + } + } else if (entry.isFile()) { + // File da eliminare + if ( + entry.name.endsWith(".http") || + entry.name.endsWith(".env.template") + ) { + fs.unlinkSync(fullPath); + console.log(`๐Ÿ—‘๏ธ File rimosso: ${fullPath}`); + } + } + } +} + function main() { const workspaceRoot = findWorkspaceRoot(__dirname); const workspaceFile = path.join(workspaceRoot, 'workspace.yml'); @@ -664,6 +695,9 @@ function main() { throw new Error('No collections found in workspace.yml'); } + const outputBaseRoot = path.join(workspaceRoot, 'autogen', 'httpyac'); + cleanFolder(outputBaseRoot); + for (const collection of collections) { if (!collection || !collection.name || !collection.path) { continue; @@ -675,8 +709,9 @@ function main() { continue; } - const outputRoot = path.join(workspaceRoot, 'autogen', 'httpyac', collection.name); + const outputRoot = path.join(outputBaseRoot, collection.name); ensureDir(outputRoot); + const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot); const yamlFiles = walkYamlFiles(sourceDir);