"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const __1 = require("../..");
const argument_parser_1 = require("@eigenspace/argument-parser");
const argParser = new argument_parser_1.ArgumentParser();
const argv = argParser.get(process.argv.slice(2));
const sourceDirParam = argv.get('src');
const sourceDir = sourceDirParam || 'dist';
const distDirParam = argv.get('dist');
const distDir = distDirParam || sourceDir;
bundleDts(sourceDir, distDir);
function bundleDts(fromDir, toDir) {
    const files = [];
    __1.walkThrough(fromDir, (dir, file) => {
        const fillPath = path.join(dir, file);
        if (fs.statSync(fillPath).isFile() && /\.d\.ts$/.test(fillPath)) {
            files.push(fillPath);
        }
    });
    const statements = files
        .map(file => file.replace(/\\/g, '/'))
        .map(file => new RegExp(`^${fromDir}/(.*)\.d\.ts$`).exec(file))
        .filter(match => Boolean(match))
        // @ts-ignore: Object is possibly 'null'
        .map(match => match[1])
        .map(file => `export * from './${file}';`)
        .join('\n');
    fs.writeFileSync(`${toDir}/index.d.ts`, statements);
}
//# sourceMappingURL=bundle-dts.js.map