"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const serializer_1 = __importDefault(require("./serializer"));
// TODO: export as a function w
const dry = {
    version: "1",
    tables: {},
    enums: {}
};
const prepareMigration = (migrationRootFolderName = 'drizzle', dataFolderPath) => {
    const root = migrationRootFolderName;
    const files = fs_1.default.readdirSync('./');
    const drizzleFolder = files.find((it) => {
        return it === root;
    });
    if (!drizzleFolder) {
        fs_1.default.mkdirSync(root);
    }
    const migrationFolders = fs_1.default.readdirSync(`./${root}`);
    let prevSnapshot;
    if (migrationFolders.length === 0) {
        prevSnapshot = dry;
    }
    else {
        migrationFolders.sort();
        const lastSnapshotFolder = migrationFolders[migrationFolders.length - 1];
        prevSnapshot = JSON.parse(fs_1.default.readFileSync(`./${root}/${lastSnapshotFolder}/snapshot.json`).toString());
    }
    const result = serializer_1.default(dataFolderPath);
    return { prev: prevSnapshot, cur: result };
};
exports.default = prepareMigration;
//# sourceMappingURL=migrationPreparator.js.map