"use strict";
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const utils_1 = require("./utils");
const fs_1 = __importDefault(require("fs"));
const releaseBuilder_1 = __importDefault(require("./init/helpers/releaseBuilder"));
const releaseBuilder = new releaseBuilder_1.default();
const TYPE = {
    exsp: "exsp",
    mysql: "mysql",
    postgres: "exsp_postgresql",
    build: "build",
};
const command = process.argv.slice(2);
const builder = command[0];
console.log("builder", builder);
switch (builder) {
    case TYPE.build:
        if (command[1] === "--name") {
            const rname = command[2].split(":")[0];
            const tagname = (_a = command[2]) === null || _a === void 0 ? void 0 : _a.split(":")[1];
            let releaseName;
            console.log({ rname });
            switch (rname) {
                case TYPE.exsp:
                    releaseName = rname + tagname.split("v")[1];
                    releaseInit(releaseName);
                    break;
                case TYPE.mysql:
                    releaseName = rname + tagname.split("v")[1];
                    releaseInit(releaseName);
                    break;
                case TYPE.postgres:
                    releaseName = rname;
                    //  + tagname.split("v")[1];
                    releaseInit(releaseName);
                    break;
            }
        }
        break;
    default:
        utils_1.logger.info(`Invalid command`);
}
function releaseInit(releaseName) {
    utils_1.logger.info(`Build ${releaseName}`);
    const dirPath = path_1.default.join(__dirname, `../../exsp-releases/${releaseName}`);
    if (!fs_1.default.existsSync(dirPath)) {
        utils_1.logger.error(`Release version ${releaseName} done not exist!!!`);
    }
    else {
        console.log({ dirPath });
        releaseBuilder.createReleaseJSON(dirPath, (err, res) => __awaiter(this, void 0, void 0, function* () {
            if (err)
                utils_1.logger.info(err.message);
            const fileName = `${releaseName}.json`;
            releaseBuilder.isFileExistAndCreated(fileName, res);
            utils_1.logger.info(`Successfully Release version ${releaseName}.!!!`);
        }));
    }
}
