'use strict';
import { execSyncCommand } from '../tools/exec.js';
import { nxProjects, nxProjectPaths } from '../constants/paths.js';
import { gitCommands } from '../constants/git-commands.js';
import { npxCommands, systemCommands, npmCommands } from '../constants/npm-commands.js';
import { environmentVariables } from '../constants/ci-constants.js';
import { getBooleanEnvSetting, getStringEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { submodulesConfig } from '../submodules-config.js';
import { lintNxRunMany } from '../tools/npm-command-funcs.js';
import { cliLogSubtitle, cliLogSeparator, cliLogInfo, cliLogSuccess } from '../../../fd-toolbox/logging/cli-logger.js';
import { formatListWithPrefix } from '../../../fd-toolbox/logging/format-list.js';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { packagesPath, folders } from '../../../base-repo/app-constants/project-paths.js';
import { runPrettierForMergeRequest } from '../setup/prettier.js';
import { getGitDiffFiles } from '../tools/git.js';
import { branches } from '../../../base-repo/app-constants/internal-system-constants.js';

var __defProp=Object['defineProperty'],__name=(_0xd94da3,_0x5ea4dd)=>__defProp(_0xd94da3,'name',{'value':_0x5ea4dd,'configurable':!![]});const lintStrategies={'full':0x0,'affected':0x1,'none':0x2};async function lint(){cliLogSubtitle('Step\x201:\x20Determining\x20changed\x20projects\x20for\x20linting...');const _0x3b6a4f=[];checkSubmoduleChanges(_0x3b6a4f),checkRootProjects(_0x3b6a4f),cliLogSeparator(),cliLogSubtitle('Step\x202:\x20Executing\x20linting\x20strategy...'),executeLint(_0x3b6a4f),cliLogSeparator(),cliLogSubtitle('Step\x203:\x20Executing\x20string\x20duplication\x20check...');const _0x16358a=npxCommands['npxTsx']+'\x20'+packagesPath['packagesTools']+folders['stringDuplication'];execSyncCommand(_0x16358a),cliLogSeparator(),cliLogSubtitle('Step\x204:\x20Executing\x20Prettier\x20check...'),await runPrettierForMergeRequest();}__name(lint,'lint');function executeLint(_0x1b7ba0){const _0x4fa138=getBooleanEnvSetting(environmentVariables['fullLint'])===!![],_0x145eb5=getStringEnvSetting(environmentVariables['ciCommitRefName'])===branches['main'],_0x49ecd8=_0x1b7ba0['includes'](nxProjects['flint'])||_0x1b7ba0['includes'](nxProjects['flintInfra']);let _0x181f10;if(_0x4fa138||_0x49ecd8||_0x145eb5)_0x181f10=lintStrategies['full'];else _0x1b7ba0['length']>0x1b40+-0x22e1+0x7a1?_0x181f10=lintStrategies['affected']:_0x181f10=lintStrategies['none'];switch(_0x181f10){case lintStrategies['full']:{if(_0x4fa138)cliLogSubtitle('CI_FULL_LINT\x20variable\x20is\x20set\x20to\x20\x27true\x27.\x20Running\x20full\x20lint\x20for\x20all\x20projects.');else _0x145eb5?cliLogSubtitle('CI_COMMIT_REF_NAME\x20variable\x20is\x20set\x20to\x20\x27main\x27.\x20Running\x20full\x20lint\x20for\x20all\x20projects.'):cliLogSubtitle('Changes\x20detected\x20in\x20\x22'+nxProjects['flint']+'\x22\x20project.\x20Running\x20full\x20lint\x20for\x20all\x20projects.');const _0x5b0f95=''+systemCommands['unsetNxKey']+npmCommands['lint'];execSyncCommand(_0x5b0f95);break;}case lintStrategies['affected']:{const _0x3f8b25=[...new Set(_0x1b7ba0)],_0x440ea0=_0x3f8b25['join'](',');cliLogSubtitle('Executing\x20lint\x20for\x20changed\x20projects:\x20'+_0x440ea0);const _0x4b2fbe=lintNxRunMany(_0x440ea0),_0x5ce9a4=''+systemCommands['unsetNxKey']+_0x4b2fbe;execSyncCommand(_0x5ce9a4);break;}case lintStrategies['none']:{cliLogSubtitle('No\x20linting\x20required\x20as\x20no\x20relevant\x20project\x20changes\x20were\x20detected.');break;}default:{const _0x12fa9e=_0x181f10;throw createEarlyInfraError('Unhandled\x20lint\x20strategy:\x20'+_0x12fa9e);}}}__name(executeLint,'executeLint');function checkSubmoduleChanges(_0x50b389){cliLogSubtitle('Checking\x20for\x20changes\x20within\x20submodules...');if(submodulesConfig['length']===0x221f+-0x5f*-0x21+-0x2e5e){cliLogSubtitle('No\x20submodules\x20configured.\x20Skipping.');return;}for(const _0x14d531 of submodulesConfig){cliLogSubtitle('->\x20Analyzing\x20submodule\x20at\x20path:\x20\x22'+_0x14d531['path']+'\x22');const _0x2ccfbc='cd\x20'+_0x14d531['path']+'\x20&&\x20'+gitCommands['diffNameOnlyOriginMainHead'],_0xc94dfe=getGitDiffFiles(_0x2ccfbc);if(_0xc94dfe['length']>-0x263f+0x2*-0x127d+0x4b39){const _0x42ebff=_0xc94dfe['map'](_0x53ff96=>_0x14d531['path']+'/'+_0x53ff96),_0x359246=_0x42ebff['length']+'\x20changed\x20file(s)\x20in\x20submodule\x20\x22'+_0x14d531['repoName']+'\x22.';cliLogSubtitle('Found\x20'+_0x359246),cliLogInfo(formatListWithPrefix(_0x42ebff)),findChangedProjects(_0x42ebff,_0x14d531['nxProjects'],_0x50b389);}else cliLogSubtitle('No\x20git\x20changes\x20detected\x20in\x20submodule\x20\x22'+_0x14d531['repoName']+'\x22.');}}__name(checkSubmoduleChanges,'checkSubmoduleChanges');function checkRootProjects(_0x3af917){cliLogSubtitle('Checking\x20for\x20changes\x20within\x20the\x20root\x20monorepo...');const _0x304625=getGitDiffFiles(gitCommands['diffNameOnlyOriginMainHead']);_0x304625['length']>-0x2277+-0x11*-0x161+0xb06?(cliLogSubtitle('Found\x20'+_0x304625['length']+'\x20changed\x20file(s)\x20in\x20the\x20root\x20repository.'),cliLogInfo(formatListWithPrefix(_0x304625)),findChangedProjects(_0x304625,Object['keys'](nxProjectPaths),_0x3af917)):cliLogSubtitle('No\x20git\x20changes\x20detected\x20in\x20the\x20root\x20repository.');}__name(checkRootProjects,'checkRootProjects');function findChangedProjects(_0x2df7a3,_0x329e7d,_0x54e70e){cliLogSubtitle('Analyzing\x20'+_0x2df7a3['length']+'\x20changed\x20files\x20to\x20find\x20affected\x20projects...');for(const _0x2bb5f6 of _0x329e7d){const _0x1835fe=nxProjectPaths[_0x2bb5f6];if(_0x1835fe){const _0x34c850=_0x2df7a3['some'](_0x3e3e26=>_0x1835fe['some'](_0x26e2ce=>_0x3e3e26['startsWith'](''+_0x26e2ce)));_0x34c850&&(cliLogSuccess('\x20->\x20Match\x20found!\x20File\x20change\x20affects\x20project:\x20\x22'+_0x2bb5f6+'\x22'),!_0x54e70e['includes'](_0x2bb5f6)&&_0x54e70e['push'](_0x2bb5f6));}}}__name(findChangedProjects,'findChangedProjects');

export { lint };
