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 _configParser=require("../core/configManager/configParser");

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

var taskRnvKill=function taskRnvKill(c,parentTask,originTask){var usedPorts,platArray,results,i,_c$buildConfig,_c$buildConfig$defaul,_c$buildConfig$defaul2,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');_context.next=3;return _regenerator.default.awrap(

(0,_configParser.configureRuntimeDefaults)(c));case 3:_context.next=5;return _regenerator.default.awrap(
(0,_engineManager.executeTask)(c,_constants.TASK_APP_CONFIGURE,parentTask,originTask));case 5:_context.next=7;return _regenerator.default.awrap(
(0,_configParser.configureRuntimeDefaults)(c));case 7:


usedPorts=[];
platArray=Object.values(c.runtime.supportedPlatforms);
results=[];
for(i=0;i<platArray.length;i++){
plat=platArray[i];
port=(_c$buildConfig=c.buildConfig)==null?void 0:(_c$buildConfig$defaul=_c$buildConfig.defaults)==null?void 0:(_c$buildConfig$defaul2=_c$buildConfig$defaul.ports)==null?void 0:_c$buildConfig$defaul2[plat.platform];
plat.port=port;
results.push((0,_common.checkPortInUse)(c,plat.platform,port));
}_context.next=13;return _regenerator.default.awrap(

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


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

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


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