Streamline management of API collections #1
@@ -654,6 +654,37 @@ function writeEnvironmentTemplates(sourceDir, outputRoot) {
|
|||||||
return dotenvVariablesByTarget;
|
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() {
|
function main() {
|
||||||
const workspaceRoot = findWorkspaceRoot(__dirname);
|
const workspaceRoot = findWorkspaceRoot(__dirname);
|
||||||
const workspaceFile = path.join(workspaceRoot, 'workspace.yml');
|
const workspaceFile = path.join(workspaceRoot, 'workspace.yml');
|
||||||
@@ -664,6 +695,9 @@ function main() {
|
|||||||
throw new Error('No collections found in workspace.yml');
|
throw new Error('No collections found in workspace.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const outputBaseRoot = path.join(workspaceRoot, 'autogen', 'httpyac');
|
||||||
|
cleanFolder(outputBaseRoot);
|
||||||
|
|
||||||
for (const collection of collections) {
|
for (const collection of collections) {
|
||||||
if (!collection || !collection.name || !collection.path) {
|
if (!collection || !collection.name || !collection.path) {
|
||||||
continue;
|
continue;
|
||||||
@@ -675,8 +709,9 @@ function main() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputRoot = path.join(workspaceRoot, 'autogen', 'httpyac', collection.name);
|
const outputRoot = path.join(outputBaseRoot, collection.name);
|
||||||
ensureDir(outputRoot);
|
ensureDir(outputRoot);
|
||||||
|
|
||||||
const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot);
|
const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot);
|
||||||
|
|
||||||
const yamlFiles = walkYamlFiles(sourceDir);
|
const yamlFiles = walkYamlFiles(sourceDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user