"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = preflightFn;
const child_process_1 = require("child_process");
const console_colors_1 = __importDefault(require("../utils/console-colors"));
/**
 * ## Preflight Function
 * @param {string[] | string} preflight
 * @param {boolean} [postflight]
 * @returns {boolean}
 */
function preflightFn(preflight, postflight) {
    const tag = postflight ? "Postflight" : "Preflight";
    console.log(`${tag} Running ...`);
    const options = {
        cwd: process.cwd(),
        stdio: "inherit",
    };
    try {
        if (typeof preflight == "string") {
            (0, child_process_1.execFileSync)(preflight, options);
        }
        else if (typeof preflight == "object" && (preflight === null || preflight === void 0 ? void 0 : preflight[0])) {
            for (let i = 0; i < preflight.length; i++) {
                const cmd = preflight[i];
                try {
                    const execCmd = (0, child_process_1.execSync)(cmd, options);
                }
                catch (error) {
                    console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} ${tag} command ${cmd} Failed! => ${error.message}`);
                    return false;
                    break;
                }
            }
        }
        return true;
    }
    catch (error) {
        console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} ${tag} Failed! => ${error.message}`);
        return false;
    }
}
