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 _taskManager=require("../../core/taskManager");
var _logger=require("../../core/systemManager/logger");
var _runtimeManager=require("../../core/runtimeManager");

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=[];
platArray=[];
results=[];_context.next=6;return _regenerator.default.awrap(


(0,_runtimeManager.configureRuntimeDefaults)(c));case 6:if(!

c.paths.project.configExists){_context.next=13;break;}_context.next=9;return _regenerator.default.awrap(
(0,_taskManager.executeTask)(c,_constants.TASK_APP_CONFIGURE,_constants.TASK_KILL,originTask));case 9:_context.next=11;return _regenerator.default.awrap(
(0,_runtimeManager.configureRuntimeDefaults)(c));case 11:
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)||{};case 13:


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=16;return _regenerator.default.awrap(

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


usedPorts.length){_context.next=29;break;}_context.next=21;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 21:_await$inquirerPrompt=_context.sent;confirm=_await$inquirerPrompt.confirm;if(!

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


true);case 30: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