/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
function run(cwd,rtf,appCtx,fnOpenWriter,JafVersion,fnShowVersion){var mig,isVerboseDebug=rtf.verboseMode||rtf.debugMode;var ctx;appCtx.debug("Loading migrator entry-point...");try{if(rtf.outPath){if(!fnOpenWriter(rtf.outPath)){return}}ctx=_makeContext(rtf,appCtx,JafVersion,cwd);mig=new(require("../corePackMigrator/cli"))(ctx)}catch(e){let s="[JAF-9104]: Error loading Migrator support.";if(isVerboseDebug){s+=`\n{e.message}`}appCtx.msg(appCtx.colors.RED(s))}if(!mig){return}appCtx.debug("Checking entry-points...");let isError;if(!mig.run){_missingEntry("run",appCtx);isError=true}if(rtf.unitTest&&!mig.test){_missingEntry("test",appCtx);isError=true}if(!mig.getVersion){}if(isError){return}_displayOptions(ctx,appCtx);if(rtf.help){let migVer;if(mig.getVersion){migVer=mig.getVersion()}migVer?appCtx.console(migVer,"I"):fnShowVersion();return}appCtx.debug("Invoking migrator...");try{return mig.run()}catch(e){let s,x,i;s=e.stack;if((x=s.indexOf("migrator.js"))>=0){for(i=x;;i--){if(s.charAt(i)==="\n"){s=s.substring(0,i);break}}}appCtx.error(appCtx.colors.RED(`[JAF-9102]: Migrator run failure.\n${s}`))}return 0};function _makeContext(rtf,appCtx,JafVersion,cwd){return{jafVersion:JafVersion,jetVersion:rtf.jetverSet?rtf.jetverSet:appCtx.defaultJetVer,configPath:rtf.configPath||null,cwd:cwd,logPath:rtf.outPath,log:{error:appCtx.error,warn:appCtx.warn,info:appCtx.info,msg:appCtx.msg,console:appCtx.console,debug:appCtx.debug},options:{verboseMode:rtf.verboseMode,debugMode:rtf.debugMode,dryRunMode:rtf.dryRunSet,colorMode:appCtx.colors.isColor(),unitTest:!!rtf.unitTest},runMode:appCtx.runMode,platform:appCtx.platform,utils:{utils:appCtx.utils,fsUtils:appCtx.fsUtils,color:appCtx.colors}}};function _displayOptions(ctx,appCtx){if(ctx.options.debugMode){appCtx.debug("Migrator options:");appCtx.debug(`  jafVersion:  ${ctx.jafVersion}`);appCtx.debug(`  jetVersion:  ${ctx.jetVersion}`);appCtx.debug(`  configPath:  ${ctx.configPath}`);appCtx.debug(`  runMode:     ${ctx.options.runMode}`);appCtx.debug(`  debugMode:   ${ctx.options.debugMode}`);appCtx.debug(`  verboseMode: ${ctx.options.verboseMode}`);appCtx.debug(`  dryRunMode:  ${ctx.options.dryRunMode}`);appCtx.debug(`  colorMode:   ${ctx.options.colorMode}`);appCtx.debug(`  logPath:     ${ctx.logPath}`);appCtx.debug(`  unitTest:    ${ctx.options.unitTest}`)}else{appCtx.info(`Migrator log -> ${ctx.logPath}\n`)}};function _missingEntry(method,appCtx){appCtx.error(appCtx.colors.RED(`[JAF-9102]: Internal error - Migrator support method ${method}() not exported.`))};module.exports={run};