add copy of JS files
This commit is contained in:
@@ -654,6 +654,72 @@ function writeEnvironmentTemplates(sourceDir, outputRoot) {
|
|||||||
return dotenvVariablesByTarget;
|
return dotenvVariablesByTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeJsFiles(sourceDir, outputRoot) {
|
||||||
|
const targets = [];
|
||||||
|
// const dotenvVariablesByTarget = new Map();
|
||||||
|
|
||||||
|
const visit = (currentDir) => {
|
||||||
|
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
||||||
|
const hasJsFiles = entries.some((entry) => entry.isFile() && /\.js$/i.test(entry.name));
|
||||||
|
|
||||||
|
if (hasJsFiles) {
|
||||||
|
targets.push(currentDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
visit(path.join(currentDir, entry.name));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
visit(sourceDir);
|
||||||
|
|
||||||
|
for (const dir of targets) {
|
||||||
|
const relativeDir = path.relative(sourceDir, dir);
|
||||||
|
const targetDir = relativeDir && relativeDir !== '.' ? path.join(outputRoot, relativeDir) : outputRoot;
|
||||||
|
ensureDir(targetDir);
|
||||||
|
|
||||||
|
const jsFileDir = dir;
|
||||||
|
if (!fs.existsSync(jsFileDir)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsFiles = fs.readdirSync(jsFileDir, { withFileTypes: true })
|
||||||
|
.filter((entry) => entry.isFile() && /\.js$/i.test(entry.name))
|
||||||
|
.map((entry) => [ path.join(jsFileDir, entry.name), path.join(targetDir, entry.name) ]);
|
||||||
|
|
||||||
|
// const variableNames = [];
|
||||||
|
// const seenNames = new Set();
|
||||||
|
|
||||||
|
// for (const jsFile of jsFiles) {
|
||||||
|
// const parsed = parseYaml(jsFile);
|
||||||
|
// const variables = Array.isArray(parsed.variables) ? parsed.variables : [];
|
||||||
|
// for (const variable of variables) {
|
||||||
|
// if (!variable || !variable.name) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// const name = String(variable.name).trim();
|
||||||
|
// if (!name || seenNames.has(name)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// seenNames.add(name);
|
||||||
|
// variableNames.push(name);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const templateContent = variableNames.length > 0 ? `${variableNames.map(v => `${v}=${DEFAULT_ENV_VAR_VALUE}`).join('\n')}\n` : '';
|
||||||
|
// fs.writeFileSync(path.join(targetDir, '.env.template'), templateContent, 'utf8');
|
||||||
|
// dotenvVariablesByTarget.set(targetDir, new Set(variableNames));
|
||||||
|
for (const jsFile of jsFiles) {
|
||||||
|
fs.copyFileSync(jsFile[0], jsFile[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
function cleanFolder(dir) {
|
function cleanFolder(dir) {
|
||||||
if (!fs.existsSync(dir)) return;
|
if (!fs.existsSync(dir)) return;
|
||||||
|
|
||||||
@@ -670,16 +736,15 @@ function cleanFolder(dir) {
|
|||||||
const remaining = fs.readdirSync(fullPath);
|
const remaining = fs.readdirSync(fullPath);
|
||||||
if (remaining.length === 0) {
|
if (remaining.length === 0) {
|
||||||
fs.rmdirSync(fullPath);
|
fs.rmdirSync(fullPath);
|
||||||
//console.log(`🗑️ Cartella rimossa: ${fullPath}`);
|
|
||||||
}
|
}
|
||||||
} else if (entry.isFile()) {
|
} else if (entry.isFile()) {
|
||||||
// File da eliminare
|
// File da eliminare
|
||||||
if (
|
if (
|
||||||
|
entry.name.endsWith(".js") ||
|
||||||
entry.name.endsWith(".http") ||
|
entry.name.endsWith(".http") ||
|
||||||
entry.name.endsWith(".env.template")
|
entry.name.endsWith(".env.template")
|
||||||
) {
|
) {
|
||||||
fs.unlinkSync(fullPath);
|
fs.unlinkSync(fullPath);
|
||||||
console.log(`🗑️ File rimosso: ${fullPath}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -712,6 +777,8 @@ function main() {
|
|||||||
const outputRoot = path.join(outputBaseRoot, collection.name);
|
const outputRoot = path.join(outputBaseRoot, collection.name);
|
||||||
ensureDir(outputRoot);
|
ensureDir(outputRoot);
|
||||||
|
|
||||||
|
const writtenJsFiles = writeJsFiles(sourceDir, outputRoot);
|
||||||
|
|
||||||
const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot);
|
const dotenvVariablesByTarget = writeEnvironmentTemplates(sourceDir, outputRoot);
|
||||||
|
|
||||||
const yamlFiles = walkYamlFiles(sourceDir);
|
const yamlFiles = walkYamlFiles(sourceDir);
|
||||||
@@ -738,7 +805,7 @@ function main() {
|
|||||||
processed += 1;
|
processed += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Generated ${processed} .http file(s) for ${collection.name}`);
|
console.log(`${collection.name.padEnd(33)} => generated ${processed.toString().padStart(3)} .http file(s) and ${writtenJsFiles.length.toString().padStart(3)} .js file(s)`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user