Skip to content

Instantly share code, notes, and snippets.

@Eczbek
Last active February 24, 2025 03:08
Show Gist options
  • Select an option

  • Save Eczbek/71ee9efced777b1456b376578ff85d68 to your computer and use it in GitHub Desktop.

Select an option

Save Eczbek/71ee9efced777b1456b376578ff85d68 to your computer and use it in GitHub Desktop.
recursive-header-combiner-inator
// this code is terrible
// i hacked this together in like 10 minutes
// it doesn't even work well
// i'm not responsible for brain damanged incurred past this line
// ================================================================
import { readFile, writeFile } from 'node:fs/promises';
import { join, resolve, dirname } from 'node:path';
let done = [];
async function foo(file, indents = 0) {
done.push(resolve(file));
console.log('\t'.repeat(indents), resolve(file));
// if (file.includes('pp/cplr')) {
// console.log('\x1B[31m', done, '\x1B[0m');
// // console.log(done.includes(file));
// }
const text = (await readFile(file)).toString();
const lines = text.split('\n');
let result = '';
for (let i = 0; i < lines.length; ++i) {
let line = lines[i];
if (line.includes('include "')) {
lines[i] = '%%%' + lines[i];
const next = resolve(join(dirname(file), line.split('"')[1].split('"')[0]));
if (done.includes(next)) {
continue;
}
done.push(resolve(next));
// if (next.includes('_var_') || next.includes('_var.') || next.includes('_noex.') || next.includes('c_referent') || next.includes('v_referent') || next.includes('ref_referent') || next.includes('c_noex') || next.includes('v_noex') || next.includes('ref_noex')) {
// continue;
// }
result += (await foo(next, indents + 1)).trim() + '\n\n\n\n';
}
}
return (result + lines.slice((lines[0] == '#pragma once') * 2).filter((x) => !x.startsWith('%%%') && !x.trim().startsWith('// ')).join('\n')).trim() + '\n';
}
await writeFile('test.hpp', (await foo('test.cpp')).replaceAll(`
`, `
`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment