'use strict';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { cliLogSubtitle, cliLogSeparator, cliLogSuccess } from '../../../fd-toolbox/logging/cli-logger.js';
import { formatListWithPrefix } from '../../../fd-toolbox/logging/format-list.js';
import { execOutput } from '../tools/exec.js';
import { npxCommands } from '../constants/npm-commands.js';
import { branches, head } from '../../../base-repo/app-constants/internal-system-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x3b4902,_0x8e6441)=>__defProp(_0x3b4902,'name',{'value':_0x8e6441,'configurable':!![]});const prettierFileRegex=/\.(js|jsx|ts|tsx|json|yaml|yml)$/;async function runPrettierForMergeRequest(){cliLogSubtitle('Starting\x20Prettier\x20MR\x20check...'),cliLogSeparator();const _0x2669c1=getChangedFiles();cliLogSubtitle('Prettier\x20candidate\x20files:\x20'+_0x2669c1['length']),cliLogSeparator();if(_0x2669c1['length']===-0x46*0x71+-0x1a2b+0x7*0x827){cliLogSuccess('No\x20files\x20to\x20check.\x20Exiting.');return;}runPrettierCheck(_0x2669c1),cliLogSuccess('Prettier\x20check\x20passed');}__name(runPrettierForMergeRequest,'runPrettierForMergeRequest');function getChangedFiles(){const _0x242322=branches['originMain'];cliLogSubtitle('Calculating\x20diff:\x20'+_0x242322+'..'+head);const _0x342d27=execOutput('git\x20diff\x20--diff-filter=ACMR\x20--name-only\x20'+_0x242322+'\x20'+head);return _0x342d27['split']('\x0a')['filter'](Boolean)['filter'](_0x30768d=>prettierFileRegex['test'](_0x30768d));}__name(getChangedFiles,'getChangedFiles');function runPrettierCheck(_0x530783){try{execOutput(npxCommands['prettierCheckIgnoreUnknown']+'\x20'+_0x530783['map'](_0x7d6095=>'\x22'+_0x7d6095['replace'](/"/g,'\x5c\x22')+'\x22')['join']('\x20'));}catch(_0x301486){let _0x53a0b5='';_0x301486 instanceof Error&&(_0x53a0b5=_0x301486['message']??'');const _0x2ca19b=_0x53a0b5['split']('\x0a')['filter'](Boolean)['map'](_0x3b5e37=>_0x3b5e37['replace'](/^\[warn\]\s*/,'')['trim']())['filter'](_0x15e5c5=>prettierFileRegex['test'](_0x15e5c5));cliLogSeparator();throw createEarlyInfraError(['Prettier\x20check\x20failed','','Unformatted\x20files:',formatListWithPrefix(_0x2ca19b),'','Fix\x20locally\x20by\x20running:\x20npm\x20run\x20pretty']['join']('\x0a'));}}__name(runPrettierCheck,'runPrettierCheck');

export { runPrettierForMergeRequest };
