"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("./src/serializer"));
// TODO: export as a function w
const dry = {
    version: "1",
    tables: {},
    enums: {}
};
const prepareMigration = (path = 'drizzle') => {
    const root = path;
    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 = fs_1.default.readFileSync(`./${root}/${lastSnapshotFolder}/snapshot.json`).toJSON();
    }
    const timestamp = Date.now();
    const migrationFolder = `./${root}/${timestamp}`;
    fs_1.default.mkdirSync(migrationFolder);
    const version = 'v3';
    const dir = `./data/${version}`;
    const tbls = `${dir}/tables/`;
    const tps = `${dir}/types/`;
    const result = serializer_1.default(tbls, tps);
    fs_1.default.writeFileSync(`${migrationFolder}/snapshot.json`, JSON.stringify(result, null, 2));
    return { prev: prevSnapshot, cur: result };
};
exports.default = prepareMigration;
//# sourceMappingURL=fstest.js.map