var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvPluginAdd=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _inquirer=_interopRequireDefault(require("inquirer"));
var _ora=_interopRequireDefault(require("ora"));
var _configParser=require("../core/configManager/configParser");
var _constants=require("../core/constants");
var _logger=require("../core/systemManager/logger");




var _pluginManager=require("../core/pluginManager");
var _engineManager=require("../core/engineManager");



var taskRnvPluginAdd=function taskRnvPluginAdd(c,parentTask,originTask){var selPluginKey,o,selPlugin,selectedPlugins,installMessage,_await$inquirer$promp,plugin,questionPlugins,pluginKeys,i,pluginKey,_plugin,pluginProps,finalProps,i2,_await$inquirer$promp2,propValue,spinner;return _regenerator.default.async(function taskRnvPluginAdd$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvPluginAdd');_context.next=3;return _regenerator.default.awrap(

(0,_engineManager.executeTask)(c,_constants.TASK_PROJECT_CONFIGURE,_constants.TASK_PLUGIN_ADD,originTask));case 3:if(!

c.runtime.isWrapper){_context.next=5;break;}return _context.abrupt("return",
Promise.reject('Adding plugins in wrapper project is not supported.'));case 5:


selPluginKey=c.program.rawArgs[4];

o=(0,_pluginManager.getPluginList)(c);

selPlugin=selPluginKey&&o.allPlugins[selPluginKey];
selectedPlugins={};
installMessage=[];if(

selPlugin){_context.next=19;break;}_context.next=13;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'plugin',
type:'rawlist',
message:'Select the plugins you want to add',
choices:o.asArray,
pageSize:50}));case 13:_await$inquirer$promp=_context.sent;plugin=_await$inquirer$promp.plugin;


selectedPlugins[plugin]=o.allPlugins[plugin];
installMessage.push(
(0,_logger.chalk)().white(plugin)+" v("+(0,_logger.chalk)().green(
o.allPlugins[plugin].version)+")");_context.next=21;break;case 19:



selectedPlugins[selPluginKey]=selPlugin;
installMessage.push(
(0,_logger.chalk)().white(selPluginKey)+" v("+(0,_logger.chalk)().green(selPlugin.version)+")");case 21:



questionPlugins={};

Object.keys(selectedPlugins).forEach(function(key){

var plugin=selectedPlugins[key];
if(plugin.props)questionPlugins[key]=plugin;

c.files.project.config.plugins[key]='source:rnv';


});

pluginKeys=Object.keys(questionPlugins);
i=0;case 25:if(!(i<pluginKeys.length)){_context.next=45;break;}
pluginKey=pluginKeys[i];
_plugin=questionPlugins[pluginKey];
pluginProps=Object.keys(_plugin.props);
finalProps={};
i2=0;case 31:if(!(i2<pluginProps.length)){_context.next=40;break;}_context.next=34;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'propValue',
type:'input',
message:pluginKey+": Add value for "+
pluginProps[i2]+" (You can do this later in ./renative.json file)"}));case 34:_await$inquirer$promp2=_context.sent;propValue=_await$inquirer$promp2.propValue;


finalProps[pluginProps[i2]]=propValue;case 37:i2++;_context.next=31;break;case 40:

c.files.project.config.plugins[pluginKey]={};
c.files.project.config.plugins[pluginKey].props=finalProps;case 42:i++;_context.next=25;break;case 45:


spinner=(0,_ora.default)("Installing: "+installMessage.join(', ')).start();

(0,_configParser.writeRenativeConfigFile)(c,c.paths.project.config,c.files.project.config);_context.next=49;return _regenerator.default.awrap(

(0,_pluginManager.resolvePluginDependants)(c));case 49:_context.next=51;return _regenerator.default.awrap(

(0,_engineManager.executeTask)(c,_constants.TASK_INSTALL,_constants.TASK_PLUGIN_ADD,originTask));case 51:

spinner.succeed('All plugins installed!');
(0,_logger.logSuccess)('Plugins installed successfully!');return _context.abrupt("return",
true);case 54:case"end":return _context.stop();}}},null,null,null,Promise);};exports.taskRnvPluginAdd=taskRnvPluginAdd;var _default=


{
description:'Add selected plugin to the project',
fn:taskRnvPluginAdd,
task:'plugin add',
params:_constants.PARAMS.withBase(),
platforms:[]};exports.default=_default;
//# sourceMappingURL=task.rnv.plugin.add.js.map