var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try {
            step(generator.next(value));
        }
        catch (e) {
            reject(e);
        } }
        function rejected(value) { try {
            step(generator["throw"](value));
        }
        catch (e) {
            reject(e);
        } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(() => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const fs = require('fs').promises;
        const distIndexPath = './dist/index.js';
        const distTypesPath = './dist/types/index.d.ts';
        const loaderRelativePath = './loader/index.js';
        const loaderTypesRelativePath = '../loader/index.d.ts';
        // Statements to append
        const exportStatementJS = `\nexport * from '${loaderRelativePath}';\n`;
        const exportStatementTypes = `\nexport * from '${loaderTypesRelativePath}';\n`;
        // Append to the main JS file
        yield fs.appendFile(distIndexPath, exportStatementJS, 'utf8');
        console.log(`Successfully appended JavaScript exports to ${distIndexPath}`);
        // Append to the main types file
        yield fs.appendFile(distTypesPath, exportStatementTypes, 'utf8');
        console.log(`Successfully appended type exports to ${distTypesPath}`);
        const loaderRelativePackageJsonPath = './dist/loader/package.json';
        const customPackageJson = {
            name: 'capsule-loader',
            private: true,
            types: './index.d.ts',
            type: 'module',
            main: './index.js',
        };
        yield fs.writeFile(loaderRelativePackageJsonPath, JSON.stringify(customPackageJson, null, 2));
        console.log('Custom package.json written to loader directory.');
    }
    catch (error) {
        console.error('Error appending loader exports:', error);
        process.exit(1);
    }
}))();
//# sourceMappingURL=appendLoaderExports.js.map
