"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkNodeVersion = void 0;
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const logger_1 = __importDefault(require("./logger"));
/**
 * Function to get the required Node version from package.json
 * @returns {string} The required Node version specified in package.json
 */
const getRequiredNodeVersion = () => {
    const packageJsonPath = path.resolve(__dirname, '../package.json');
    const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
    return packageJson.engines.node;
};
/**
 * Function to check the current Node version against the required version
 * Logs a warning and exits the process if the current Node version is not supported
 */
const checkNodeVersion = () => {
    const requiredVersion = getRequiredNodeVersion();
    const versionMatch = process.version.match(/^v(\d+)\.(\d+)\.(\d+)/);
    if (!versionMatch) {
        logger_1.default.warn(chalk_1.default.yellow(`Unexpected Node.js version format: ${process.version}. Please use Node.js ${requiredVersion}.`));
        return;
    }
    const [major, minor, patch] = versionMatch.slice(1).map(Number);
    const [requiredMajor, requiredMinor, requiredPatch] = requiredVersion
        .replace('>=', '')
        .split('.')
        .map(Number);
    if (major < requiredMajor ||
        (major === requiredMajor && minor < requiredMinor) ||
        (major === requiredMajor && minor === requiredMinor && patch < requiredPatch)) {
        logger_1.default.warn(chalk_1.default.yellow(`You are using Node.js ${major}.${minor}.${patch}. This version is not supported. Please use Node.js ${requiredVersion}.`));
        process.exit(1);
    }
};
exports.checkNodeVersion = checkNodeVersion;
//# sourceMappingURL=checkNodeVersion.js.map