var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvKill=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _killPort=_interopRequireDefault(require("kill-port"));
var _prompt=require("../../cli/prompt");
var _common=require("../../core/common");
var _engineManager=require("../../core/engineManager");
var _logger=require("../../core/systemManager/logger");
var _runtimeParser=require("../../core/configManager/runtimeParser");

var _constants=require("../../core/constants");

var taskRnvKill=function taskRnvKill(c,parentTask,originTask){var usedPorts,platArray,results,ports,_c$buildConfig,_c$buildConfig$defaul,i,_ports,plat,port,usedPortsArr,_await$inquirerPrompt,confirm,killPromise;return _regenerator.default.async(function taskRnvKill$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvKill');

usedPorts=[];

results=[];_context.next=5;return _regenerator.default.awrap(


(0,_runtimeParser.configureRuntimeDefaults)(c));case 5:if(!

c.paths.project.configExists){_context.next=14;break;}_context.next=8;return _regenerator.default.awrap(
(0,_engineManager.executeTask)(c,_constants.TASK_APP_CONFIGURE,parentTask,originTask));case 8:_context.next=10;return _regenerator.default.awrap(
(0,_runtimeParser.configureRuntimeDefaults)(c));case 10:
platArray=Object.values(c.runtime.supportedPlatforms);
ports=((_c$buildConfig=c.buildConfig)==null?void 0:(_c$buildConfig$defaul=_c$buildConfig.defaults)==null?void 0:_c$buildConfig$defaul.ports)||{};_context.next=18;break;case 14:

(0,_logger.logWarning)('This folder is not a ReNative project!. only DEFAULT ports will be checked.');
platArray=_constants.SUPPORTED_PLATFORMS;
ports={};
Object.keys(_constants.PLATFORMS).forEach(function(k){
ports[k]=_constants.PLATFORMS[k].defaultPort;
});case 18:


for(i=0;i<platArray.length;i++){
plat=platArray[i];
port=(_ports=ports)==null?void 0:_ports[plat.platform];
plat.port=port;
results.push((0,_common.checkPortInUse)(c,plat.platform,port));
}_context.next=21;return _regenerator.default.awrap(

Promise.all(results));case 21:usedPortsArr=_context.sent;
usedPortsArr.forEach(function(isInUse,i){
if(isInUse){
usedPorts.push(platArray[i]);
}
});if(!


usedPorts.length){_context.next=34;break;}_context.next=26;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'confirm',
message:'Processes attached to the ports will be killed. Continue?',
warningMessage:"Found active ports:\n"+
usedPorts.map(function(v){return(0,_logger.chalk)().white("> "+v.port+" ("+v.platform+")");}).join('\n')}));case 26:_await$inquirerPrompt=_context.sent;confirm=_await$inquirerPrompt.confirm;if(!

confirm){_context.next=34;break;}
killPromise=[];
usedPorts.forEach(function(v){
killPromise.push((0,_killPort.default)(v.port));
});_context.next=33;return _regenerator.default.awrap(
Promise.all(usedPorts));case 33:
(0,_logger.logSuccess)('Processes KILLED');case 34:return _context.abrupt("return",


true);case 35:case"end":return _context.stop();}}},null,null,null,Promise);};exports.taskRnvKill=taskRnvKill;var _default=


{
description:'Kills all the processes related to this project',
fn:taskRnvKill,
task:_constants.TASK_KILL,
params:_constants.PARAMS.withBase(),
platforms:[],
isGlobalScope:true};exports.default=_default;
//# sourceMappingURL=task.rnv.kill.js.map