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

var _now=require("./now");
var _ftp=require("./ftp");
var _common=require("../common");





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

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){return new Promise(function(resolve,reject){
switch(deployType){
case DEPLOY_TARGET_FTP:
(0,_ftp.deployToFtp)(c,platform).then(resolve).catch(reject);
return;
case DEPLOY_TARGET_NOW:
(0,_now.deployToNow)(c,platform).then(resolve).catch(reject);
return;
case DEPLOY_TARGET_NONE:
resolve();
return;
default:
reject(new Error("Deploy Type not supported "+deployType));}

});};

var selectWebToolAndDeploy=function selectWebToolAndDeploy(c,platform){var argv,deployType,targetConfig,opts,_ref,selectedDeployTarget;return _regenerator.default.async(function selectWebToolAndDeploy$(_context){while(1){switch(_context.prev=_context.next){case 0:
argv=(0,_minimist.default)(c.process.argv.slice(2));
deployType=argv.t;
targetConfig=c.buildConfig.platforms[platform];if(!(

deployType||targetConfig&&targetConfig.deploy&&targetConfig.deploy.type)){_context.next=5;break;}return _context.abrupt("return",
_runDeployment(c,platform,deployType||targetConfig.deploy.type));case 5:

opts=(0,_prompt.generateOptions)([DEPLOY_TARGET_FTP,DEPLOY_TARGET_NOW,DEPLOY_TARGET_NONE]);_context.next=8;return _regenerator.default.awrap(

_inquirer.default.prompt({
name:'selectedDeployTarget',
type:'list',
choices:opts.keysAsArray,
message:"Which type of deploy option would you like to use for "+_chalk.default.white(platform)+" deployment?"}));case 8:_ref=_context.sent;selectedDeployTarget=_ref.selectedDeployTarget;


(0,_common.logInfo)("Setting your appconfig for "+_chalk.default.white(platform)+" to include deploy type: "+_chalk.default.white(selectedDeployTarget)+" at "+_chalk.default.white(c.paths.appConfig.config));return _context.abrupt("return",
_runDeployment(c,platform,selectedDeployTarget));case 12:case"end":return _context.stop();}}});};exports.selectWebToolAndDeploy=selectWebToolAndDeploy;