import * as fs from "fs"; import * as path from "path"; const FOLDERS_TO_INCLUDE = ["render-utils", "misc", "storage"]; function getAllDtsFiles(dir: string, fileList: string[] = []): string[] { const files = fs.readdirSync(dir); for (const file of files) { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); if (stat.isDirectory()) { getAllDtsFiles(filePath, fileList); } else if (file.endsWith(".d.ts")) { fileList.push(filePath); } } return fileList; } function generateIndexDts() { const allModules: string[] = []; for (const folderName of FOLDERS_TO_INCLUDE) { const folderPath = path.join(__dirname, "..", folderName); if (!fs.existsSync(folderPath)) { console.log(`Warning: Folder ${folderName} does not exist, skipping...`); continue; } const dtsFiles = getAllDtsFiles(folderPath); const modules = dtsFiles .map(filePath => { const relativePath = path.relative(folderPath, filePath); const withoutExt = relativePath.replace(/\.d\.ts$/, ""); const modulePath = "sliftutils/" + folderName + "/" + withoutExt.replace(/\\/g, "/"); const content = fs.readFileSync(filePath, "utf8"); const indentedContent = content .split("\n") .map(line => line ? " " + line : line) .join("\n"); return `declare module "${modulePath}" {\n${indentedContent}\n}`; }); allModules.push(...modules); } const sortedModules = allModules.sort().join("\n\n"); const outputPath = path.join(__dirname, "..", "index.d.ts"); const header = `// Auto-generated file. Do not edit manually.\n// Generated by: yarn generate-index-dts\n\n`; fs.writeFileSync(outputPath, header + sortedModules + "\n", "utf8"); console.log(`Generated ${outputPath} with ${allModules.length} module declarations`); } generateIndexDts();