"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Adding kaltura-tools preinstall script...');
    try {
        (0, devkit_1.updateJson)(tree, 'package.json', (json) => {
            if (!json.scripts) {
                json.scripts = {};
            }
            json.scripts.preinstall =
                'npx --yes --prefer-online --registry=https://npm.pkg.github.com --package @kaltura/kaltura-tools@latest kaltura-tools check --allow-missing --root=.';
            return json;
        });
        devkit_1.logger.info('✅ Successfully added kaltura-tools preinstall script');
    }
    catch (error) {
        devkit_1.logger.error(`❌ Failed to add preinstall script: ${error?.message || 'Unknown error'}`);
        throw error;
    }
}
