'use strict';
import { spawn } from 'child_process';
import { appEnvironments } from '../../../fd-toolbox/constants/environment-constants.js';
import { getDotenvConfig } from '../../../fd-toolbox/infra/env-config.js';
import { parseJson } from '../../../fd-toolbox/lib/utils.js';
import { environmentVariables } from '../../../infra/ci/constants/ci-constants.js';
import _0x1869d0__default from 'path';
import _0x3881d1__default from 'fs';

var __defProp=Object['defineProperty'],__name=(_0x2e244e,_0x355f89)=>__defProp(_0x2e244e,'name',{'value':_0x355f89,'configurable':!![]});const packageJsonPath=_0x1869d0__default['join'](process['cwd'](),'package.json'),packageJsonData=_0x3881d1__default['readFileSync'](packageJsonPath,'utf-8'),packageJson=parseJson(packageJsonData),pkg=packageJson,stdio='inherit';function getEnvironment(){const _0x378f06=process['argv'][-0xb5*0x1f+-0x2*0x124b+-0x3*-0x1381];let _0xc33afb=appEnvironments['development'];return _0x378f06&&_0x378f06['toLowerCase']()===appEnvironments['production']&&(_0xc33afb=appEnvironments['production']),getDotenvConfig(),_0xc33afb;}__name(getEnvironment,'getEnvironment');function runCommand(_0x4d0db3,_0x5ebeb2=[],_0x274118={}){return new Promise((_0x46f839,_0x5429cf)=>{let _0x3fa0b7,_0x4d2d42=_0x5ebeb2,_0x4d7dca={...process['env'],..._0x274118['env']};const _0x5cff11=pkg['scripts']?.[_0x4d0db3];_0x5cff11?(_0x3fa0b7=_0x5cff11,_0x4d2d42=[],_0x4d7dca[environmentVariables['nodeEnv']]=getEnvironment()):_0x3fa0b7=_0x4d0db3;const _0x4a20a7=spawn(_0x3fa0b7,_0x4d2d42,{'shell':!![],'stdio':_0x274118['stdio']??stdio,'env':_0x4d7dca,..._0x274118});_0x4a20a7['on']('close',_0x32335c=>{if(_0x32335c!==0x2c0+-0x1637+0x1377){const _0x4cb87e=_0x5cff11?'Script\x20\x22'+_0x4d0db3+'\x22\x20exited\x20with\x20code\x20'+_0x32335c:'Command\x20\x22'+_0x4d0db3+'\x22\x20exited\x20with\x20code\x20'+_0x32335c;_0x5429cf(new Error(_0x4cb87e));return;}_0x46f839();});});}__name(runCommand,'runCommand');

export { getEnvironment, runCommand };
