2023-05-11 17:10:28 +00:00
|
|
|
const fs = require("fs/promises");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
const exportRegex = /export\s+(?:enum|interface|type)\s+([A-Za-z0-9_]+)/g;
|
|
|
|
|
2024-09-30 12:14:59 +00:00
|
|
|
const baseExports = [
|
|
|
|
'export * from "./http";',
|
2024-12-13 13:44:34 +00:00
|
|
|
'export {UploadImage} from "./other_types";',
|
2024-09-30 12:14:59 +00:00
|
|
|
];
|
2023-05-11 17:10:28 +00:00
|
|
|
|
|
|
|
async function putTypesInIndex() {
|
|
|
|
const typeFiles = await fs.readdir(path.resolve("./src/types"));
|
|
|
|
const exports = [...baseExports];
|
|
|
|
for (const filename of typeFiles) {
|
|
|
|
const localExports = [];
|
|
|
|
const fileText = await fs.readFile(path.resolve(`./src/types/${filename}`));
|
|
|
|
for (
|
|
|
|
let match = exportRegex.exec(fileText);
|
|
|
|
match;
|
|
|
|
match = exportRegex.exec(fileText)
|
|
|
|
) {
|
|
|
|
localExports.push(match[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const spacer = localExports.length > 1 ? "\n" : " ";
|
|
|
|
|
|
|
|
exports.push(
|
|
|
|
`export {${spacer}${localExports.join(
|
2023-08-29 19:53:23 +00:00
|
|
|
",\n",
|
|
|
|
)}${spacer}} from "./types/${filename.replace(/\..+/, "")}";`,
|
2023-05-11 17:10:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFile(path.resolve("./src/index.ts"), exports.join("\n"), {
|
|
|
|
flag: "w",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
putTypesInIndex();
|