var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports._spawnCommand=exports.rnvHelp=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _chalk=_interopRequireDefault(require("chalk"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _logger=require("../systemTools/logger");
var _workspace=require("../projectTools/workspace");
var _projectGenerator=require("../projectTools/projectGenerator");
var _templateTools=require("../templateTools");
var _target=require("../platformTools/target");
var _pluginTools=require("../pluginTools");
var _platformTools=require("../platformTools");
var _buildHooks=require("../projectTools/buildHooks");
var _projectTools=require("../projectTools");
var _crypto=require("../systemTools/crypto");
var _fastlane=require("../deployTools/fastlane");
var _cleaner=require("../systemTools/cleaner");
var _prompt=require("../systemTools/prompt");
var _runner=require("../platformTools/runner");
var _constants=require("../constants");


var _config=_interopRequireDefault(require("../config"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}

var rnvHelp=function rnvHelp(){
var cmdsString='';
for(var key in COMMANDS){
cmdsString+=key+", ";
}

(0,_logger.logToSummary)("\n"+
_chalk.default.bold.white('COMMANDS:')+"\n\n"+

cmdsString+"\n\n"+

_chalk.default.bold.white('OPTIONS:')+"\n\n'-i, --info', 'Show full debug info'\n'-u, --update', 'Force update dependencies (iOS only)'\n'-p, --platform <value>', 'Select specific platform' // <ios|android|web|...>\n'-c, --appConfigID <value>', 'Select specific appConfigID' // <ios|android|web|...>\n'-t, --target <value>', 'Select specific simulator' // <.....>\n'-d, --device [value]', 'Select connected device'\n'-s, --scheme <value>', 'Select build scheme' // <Debug | Release>\n'-f, --filter <value>', 'Filter Value'\n'-l, --list', 'Return list of items related to command' // <alpha|beta|prod>\n'-r, --reset', 'Also perform reset'\n'-b, --blueprint', 'Blueprint for targets'\n'-h, --host <value>', 'Custom Host IP'\n'-x, --exeMethod <value>', 'Executable method in buildHooks'\n'-P, --port <value>', 'Custom Port'\n'-H, --help', 'Help'\n'-D, --debug', 'enable remote debugger'\n'--hosted', 'Run in a hosted environment (skip bundleAssets)'\n'--debugIp <value>', '(optional) overwrite the ip to which the remote debugger will connect'\n");




















};exports.rnvHelp=rnvHelp;

var COMMANDS={
start:{
fn:_runner.rnvStart},

run:{
desc:'Run your app on target device or emulator',
fn:_runner.rnvRun},

package:{
desc:'Package JS Code',
platforms:[_constants.IOS,_constants.ANDROID,_constants.ANDROID_TV,_constants.ANDROID_WEAR,_constants.TVOS],
fn:_runner.rnvPackage},

deploy:{
desc:'Deploy whole app via preconfigured or custom integration',
fn:_runner.rnvDeploy},

build:{
desc:'Build your app',
fn:_runner.rnvBuild},

export:{
desc:'Export your app (ios only)',
platforms:[_constants.IOS,_constants.TVOS,_constants.MACOS,_constants.WINDOWS],
fn:_runner.rnvExport},

log:{
desc:'Attach logger to device or emulator and print out logs',
platforms:[_constants.IOS,_constants.ANDROID,_constants.ANDROID_TV,_constants.ANDROID_WEAR,_constants.TVOS],
fn:_runner.rnvLog},

new:{
fn:_projectGenerator.createNewProject,
desc:'Creates new project',
params:['mono','ci']},

help:{
desc:'Displays help',
fn:rnvHelp},

configure:{
desc:'Configures app config',
fn:_projectTools.rnvConfigure,
params:['appConfigID','mono','ci']},

switch:{
desc:'Switches to app confing without rebuilding',
fn:_projectTools.rnvSwitch,
params:['appConfigID','mono','ci']},

link:{
desc:'Local dependency linking of your project',
fn:_pluginTools.rnvLink},

platform:{
desc:'Manages native platform projects',
subCommands:{
eject:{
fn:_platformTools.rnvPlatformEject},

list:{
fn:_platformTools.rnvPlatformList},

connect:{
fn:_platformTools.rnvPlatformConnect},

configure:{
fn:_platformTools.rnvPlatformConfigure}}},



target:{
desc:'Manages simulators and emulators',
platforms:[_constants.IOS,_constants.ANDROID,_constants.ANDROID_TV,_constants.ANDROID_WEAR,_constants.TIZEN,_constants.TIZEN_MOBILE,_constants.TVOS,_constants.WEBOS,_constants.TIZEN_WATCH],
subCommands:{
launch:{
fn:_target.rnvTargetLaunch},

list:{
fn:_target.rnvTargetList}}},



plugin:{
desc:'Manages all plugins',
subCommands:{
add:{
fn:_pluginTools.rnvPluginAdd},

list:{
fn:_pluginTools.rnvPluginList},

update:{
fn:_pluginTools.rnvPluginUpdate}}},



hooks:{
desc:'Manages project based build hooks. This allows you to extend functionality of RNV CLI',
subCommands:{
run:{
fn:_buildHooks.rnvHooksRun},

list:{
fn:_buildHooks.rnvHooksList},

pipes:{
fn:_buildHooks.rnvHooksPipes}}},



status:{
desc:'Prints out summary of your project',
fn:_logger.rnvStatus},

clean:{
desc:'Automatically removes all node_modules and lock in your project and its dependencies',
fn:_cleaner.rnvClean},

template:{
desc:'Manages rnv and project templates',
subCommands:{
add:{
fn:_templateTools.rnvTemplateAdd},

list:{
fn:_templateTools.rnvTemplateList},

apply:{
fn:_templateTools.rnvTemplateApply}}},



crypto:{
desc:'Utility to manage encrytped files in your project, provisioning profiles, kestores and other sensitive information',
platforms:[_constants.IOS,_constants.TVOS],
subCommands:{
encrypt:{
fn:_crypto.rnvCryptoEncrypt},

decrypt:{
fn:_crypto.rnvCryptoDecrypt},

installCerts:{
fn:_crypto.rnvCryptoInstallCerts},

updateProfile:{
requiredParams:['scheme','platform'],
fn:_crypto.rnvCryptoUpdateProfile},

updateProfiles:{
fn:_crypto.rnvCryptoUpdateProfiles},

installProfiles:{
fn:_crypto.rnvCryptoInstallProfiles}}},



workspace:{
desc:'Manages global workspaces for ReNative projects',
subCommands:{
add:{
fn:_workspace.rnvWorkspaceAdd},

connect:{
fn:_workspace.rnvWorkspaceConnect},

list:{
fn:_workspace.rnvWorkspaceList},

update:{
fn:_workspace.rnvWorkspaceUpdate}}},



fastlane:{
desc:'Run fastlane commands on currectly active app/platform directly via rnv command',
platforms:[_constants.IOS,_constants.ANDROID,_constants.ANDROID_TV,_constants.ANDROID_WEAR,_constants.TVOS],
fn:_fastlane.rnvFastlane}};








var run=function run(c,spawnC){var _cmd$subCommands;var oldC,cmd,cmdFn,subCmd,subCmdFn;return _regenerator.default.async(function run$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('cli');


if(spawnC){
oldC=c;
c=_spawnCommand(c,spawnC);
_config.default.initializeConfig(c);
}

cmd=COMMANDS[c.command];
cmdFn=cmd==null?void 0:cmd.fn;
subCmd=cmd==null?void 0:(_cmd$subCommands=cmd.subCommands)==null?void 0:_cmd$subCommands[c.subCommand];
subCmdFn=subCmd==null?void 0:subCmd.fn;if(!

cmd){_context.next=31;break;}if(!(
c.subCommand==='help')){_context.next=12;break;}_context.next=10;return _regenerator.default.awrap(
_execCommandHep(c,cmd));case 10:_context.next=29;break;case 12:if(!
cmdFn){_context.next=22;break;}if(!
subCmdFn){_context.next=18;break;}_context.next=16;return _regenerator.default.awrap(
_execute(c,subCmdFn,cmd,c.command,c.subCommand));case 16:_context.next=20;break;case 18:_context.next=20;return _regenerator.default.awrap(

_execute(c,cmdFn,cmd,c.command,c.subCommand));case 20:_context.next=29;break;case 22:if(!

subCmdFn){_context.next=27;break;}_context.next=25;return _regenerator.default.awrap(
_execute(c,subCmdFn,cmd,c.command,c.subCommand));case 25:_context.next=29;break;case 27:_context.next=29;return _regenerator.default.awrap(

_handleUnknownSubCommand(c));case 29:_context.next=33;break;case 31:_context.next=33;return _regenerator.default.awrap(


_handleUnknownCommand(c));case 33:

if(spawnC)_config.default.initializeConfig(oldC);case 34:case"end":return _context.stop();}}});};


var _execute=function _execute(c,cmdFn,cmd,command,subCommand){var subCmd,_cmd$subCommands$c$su,requiredParams,i,requiredParam;return _regenerator.default.async(function _execute$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:if(!(
cmd.platforms&&!cmd.platforms.includes(c.platform))){_context2.next=4;break;}_context2.next=3;return _regenerator.default.awrap(
_handleUnknownPlatform(c,cmd.platforms));case 3:return _context2.abrupt("return");case 4:


subCmd='';
if(subCommand){
subCmd=":"+c.subCommand;
requiredParams=(_cmd$subCommands$c$su=cmd.subCommands[c.subCommand])==null?void 0:_cmd$subCommands$c$su.requiredParams;
if(requiredParams){
for(i=0;i<requiredParams.length;i++){
requiredParam=requiredParams[i];

}
}
}_context2.next=8;return _regenerator.default.awrap(

(0,_buildHooks.executePipe)(c,""+c.command+subCmd+":before"));case 8:_context2.next=10;return _regenerator.default.awrap(
cmdFn(c));case 10:_context2.next=12;return _regenerator.default.awrap(
(0,_buildHooks.executePipe)(c,""+c.command+subCmd+":after"));case 12:case"end":return _context2.stop();}}});};






var _execCommandHep=function _execCommandHep(c,cmd){var opts,subCommands;return _regenerator.default.async(function _execCommandHep$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
opts='';
subCommands='';

if(cmd.subCommands){
subCommands='\nSub Commands: \n';
subCommands+=Object.keys(cmd.subCommands).join(', ');
subCommands+='\n';
}

if(cmd.params){
opts='Options:\n';
opts+=(cmd.params||[]).reduce(function(t,v){return t+"--"+v+"\n";},'');
}

(0,_logger.logToSummary)("\nCommand: "+
c.command+"\n\nDescription: "+

cmd.desc+".\n"+
subCommands+"\n"+
opts+"\nMore info at "+
_chalk.default.grey("https://renative.org/docs/rnv-"+c.command)+"\n");return _context3.abrupt("return",

Promise.resolve());case 6:case"end":return _context3.stop();}}});};


var _handleUnknownSubCommand=function _handleUnknownSubCommand(c){var _COMMANDS$c$command;var cmds,_ref,subCommand;return _regenerator.default.async(function _handleUnknownSubCommand$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:
(0,_logger.logTask)('_handleUnknownSubCommand');
cmds=(_COMMANDS$c$command=COMMANDS[c.command])==null?void 0:_COMMANDS$c$command.subCommands;_context4.next=4;return _regenerator.default.awrap(

(0,_prompt.inquirerPrompt)({
type:'list',
name:'subCommand',
message:'Pick a subCommand',
choices:Object.keys(cmds),
logMessage:"cli: Command "+_chalk.default.bold(c.command)+" does not support method "+_chalk.default.bold(c.subCommand)+"!"}));case 4:_ref=_context4.sent;subCommand=_ref.subCommand;


c.subCommand=subCommand;return _context4.abrupt("return",
run(c));case 8:case"end":return _context4.stop();}}});};


var _handleUnknownCommand=function _handleUnknownCommand(c){var _ref2,command;return _regenerator.default.async(function _handleUnknownCommand$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:
(0,_logger.logTask)('_handleUnknownCommand');

c.program.scheme='?';
c.program.appConfigID='?';
c.runtime.appId='?';_context5.next=6;return _regenerator.default.awrap(

(0,_prompt.inquirerPrompt)({
type:'list',
name:'command',
message:'Pick a command',
choices:Object.keys(COMMANDS),
logMessage:"cli: Command "+_chalk.default.bold(c.command)+" not supported!"}));case 6:_ref2=_context5.sent;command=_ref2.command;

c.command=command;return _context5.abrupt("return",
run(c));case 10:case"end":return _context5.stop();}}});};



var _handleUnknownPlatform=function _handleUnknownPlatform(c,platforms){var _ref3,platform;return _regenerator.default.async(function _handleUnknownPlatform$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:
(0,_logger.logTask)('_handleUnknownPlatform');_context6.next=3;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'list',
name:'platform',
message:'pick one of the following',
choices:platforms,
logMessage:"cli: Command "+_chalk.default.grey(c.command)+" does not support platform "+_chalk.default.grey(c.platform)+". "}));case 3:_ref3=_context6.sent;platform=_ref3.platform;


c.platform=platform;return _context6.abrupt("return",
run(c));case 7:case"end":return _context6.stop();}}});};


var _arrayMergeOverride=function _arrayMergeOverride(destinationArray,sourceArray,mergeOptions){return sourceArray;};

var _spawnCommand=function _spawnCommand(c,overrideParams){
var newCommand={};

Object.keys(c).forEach(function(k){
if(typeof newCommand[k]==='object'&&!(newCommand[k]instanceof'String')){
newCommand[k]=_objectSpread({},c[k]);
}else{
newCommand[k]=c[k];
}
});

var merge=require('deepmerge');

Object.keys(overrideParams).forEach(function(k){
if(newCommand[k]&&typeof overrideParams[k]==='object'){
newCommand[k]=merge(newCommand[k],overrideParams[k],{arrayMerge:_arrayMergeOverride});
}else{
newCommand[k]=overrideParams[k];
}
});




return newCommand;
};exports._spawnCommand=_spawnCommand;var _default=






run;exports.default=_default;