var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.DEPLOY_TARGET_NONE=exports.DEPLOY_TARGET_AWS=exports.DEPLOY_TARGET_NOW=exports.DEPLOY_TARGET_FTP=exports.selectWebToolAndExport=exports.selectWebToolAndDeploy=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));
var _minimist=_interopRequireDefault(require("minimist"));

var _integrationNow=require("../../integration-now");
var _integrationFtp=require("../../integration-ftp");
var _common=require("../common");
var _logger=require("../systemManager/logger");
var _configure=require("./configure");



var _prompt=require("../../cli/prompt");

var DEPLOY_TARGET_DOCKER='docker';
var DEPLOY_TARGET_AWS='aws';exports.DEPLOY_TARGET_AWS=DEPLOY_TARGET_AWS;
var DEPLOY_TARGET_FTP='ftp';exports.DEPLOY_TARGET_FTP=DEPLOY_TARGET_FTP;
var DEPLOY_TARGET_NOW='now';exports.DEPLOY_TARGET_NOW=DEPLOY_TARGET_NOW;
var DEPLOY_TARGET_NONE='none';exports.DEPLOY_TARGET_NONE=DEPLOY_TARGET_NONE;

var _runDeployment=function _runDeployment(c,platform,deployType){var deployToDocker,deployerPackage;return _regenerator.default.async(function _runDeployment$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.t0=
deployType;_context.next=_context.t0===
DEPLOY_TARGET_FTP?3:_context.t0===

DEPLOY_TARGET_NOW?4:_context.t0===

DEPLOY_TARGET_NONE?5:_context.t0===

DEPLOY_TARGET_DOCKER?6:_context.t0===










DEPLOY_TARGET_AWS?9:12;break;case 3:return _context.abrupt("return",(0,_integrationFtp.deployToFtp)(c));case 4:return _context.abrupt("return",(0,_integrationNow.taskRnvDeployNow)(c));case 5:return _context.abrupt("return",Promise.resolve());case 6:deployToDocker=(0,_common.importPackageFromProject)('@rnv/deploy-docker');deployToDocker.setRNVPath(process.mainModule.filename.split('/bin/index.js')[0]);return _context.abrupt("return",deployToDocker.doDeploy());case 9:
deployerPackage=(0,_common.importPackageFromProject)('@rnv/deploy-aws');
deployerPackage.setRNVPath(process.mainModule.filename.split('/bin/index.js')[0]);return _context.abrupt("return",
deployerPackage.doDeploy());case 12:return _context.abrupt("return",


Promise.reject(
new Error("Deploy Type not supported "+deployType)));case 13:case"end":return _context.stop();}}},null,null,null,Promise);};




var _runExport=function _runExport(c,platform,exportType){
switch(exportType){
case DEPLOY_TARGET_DOCKER:{
var rnvPath=process.mainModule.filename.split(
'/bin/index.js')[
0];
var deployToDocker=(0,_common.importPackageFromProject)(
'@rnv/deploy-docker');

deployToDocker.setRNVPath(rnvPath);
return deployToDocker.doExport();
}
case DEPLOY_TARGET_NONE:
return Promise.resolve();
default:
return Promise.reject(
new Error("Export Type not supported "+exportType));}


};

var selectToolAndExecute=function selectToolAndExecute(_ref){var c,platform,choices,configFunction,executeFunction,_ref$isDeploy,isDeploy,defaultChoice,argv,type,deployConfig,_await$inquirerPrompt,selectedTarget;return _regenerator.default.async(function selectToolAndExecute$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
c=_ref.c,
platform=_ref.platform,
choices=_ref.choices,
configFunction=_ref.configFunction,
executeFunction=_ref.executeFunction,_ref$isDeploy=_ref.
isDeploy,isDeploy=_ref$isDeploy===void 0?true:_ref$isDeploy,
defaultChoice=_ref.defaultChoice;

argv=(0,_minimist.default)(c.process.argv.slice(2));
type=argv.t;
deployConfig=(0,_common.getConfigProp)(c,c.platform,'deploy');if(!(

type||(deployConfig==null?void 0:deployConfig.type))){_context2.next=8;break;}_context2.next=7;return _regenerator.default.awrap(

configFunction(type||deployConfig.type));case 7:return _context2.abrupt("return",
executeFunction(c,platform,type||deployConfig.type));case 8:_context2.next=10;return _regenerator.default.awrap(

(0,_prompt.inquirerPrompt)({
name:'selectedTarget',
type:'list',
choices:choices,
default:defaultChoice,
message:"Which type of "+(
isDeploy?'deploy':'export')+" option would you like to use for "+
(0,_logger.chalk)().white(c.platform)+"?"}));case 10:_await$inquirerPrompt=_context2.sent;selectedTarget=_await$inquirerPrompt.selectedTarget;_context2.next=14;return _regenerator.default.awrap(


configFunction(c,selectedTarget));case 14:

(0,_logger.logInfo)("Setting your appconfig for "+
(0,_logger.chalk)().white(platform)+" to include "+(
isDeploy?'deploy':'export')+" type: "+
(0,_logger.chalk)().white(selectedTarget)+" at "+(0,_logger.chalk)().white(
c.paths.appConfig.config));return _context2.abrupt("return",


executeFunction(c,platform,selectedTarget));case 16:case"end":return _context2.stop();}}},null,null,null,Promise);};


var selectWebToolAndDeploy=function selectWebToolAndDeploy(c,platform){return selectToolAndExecute({
c:c,
platform:platform,
choices:[DEPLOY_TARGET_DOCKER,DEPLOY_TARGET_AWS,DEPLOY_TARGET_FTP,DEPLOY_TARGET_NOW,DEPLOY_TARGET_NONE],
configFunction:_configure.configureDeploymentIfRequired,
executeFunction:_runDeployment});};exports.selectWebToolAndDeploy=selectWebToolAndDeploy;


var selectWebToolAndExport=function selectWebToolAndExport(c,platform){return selectToolAndExecute({
c:c,
platform:platform,
choices:[DEPLOY_TARGET_DOCKER,DEPLOY_TARGET_NONE],
configFunction:_configure.configureExportIfRequired,
executeFunction:_runExport,
isDeploy:false,
defaultChoice:DEPLOY_TARGET_NONE});};exports.selectWebToolAndExport=selectWebToolAndExport;
//# sourceMappingURL=index.js.map