"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = checkNxVersion;
const devkit_1 = require("@nx/devkit");
function checkNxVersion(tree) {
    devkit_1.logger.info('🔍 Checking Nx version compatibility...');
    const pkg = (0, devkit_1.readJson)(tree, 'package.json');
    const nxVersion = pkg.devDependencies?.nx || pkg.dependencies?.nx;
    if (!nxVersion) {
        devkit_1.logger.error('❌ No Nx version found in package.json');
        throw new Error('No Nx version found in package.json. Please install Nx first.');
    }
    const majorVersion = parseInt(nxVersion.match(/\d+/)?.[0] ?? '0');
    if (majorVersion < 22) {
        const errorMessage = `❌ This migration requires Nx 22 or higher. read https://unisphere.kaltura.com/docs/create/changelog/1-22-7-changelog`;
        devkit_1.logger.error(errorMessage);
        throw new Error(errorMessage);
    }
    devkit_1.logger.info(`✅ Nx version check passed (version: ${nxVersion})`);
}
