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 _chalk=_interopRequireDefault(require("chalk"));
var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _now=require("./now");
var _ftp=require("./ftp");
var _common=require("../common");





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

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){return new Promise(function(resolve,reject){
var argv=require('minimist')(c.process.argv.slice(2));
var deployType=argv.t;
var targetConfig=c.buildConfig.platforms[platform];

if(deployType||targetConfig&&targetConfig.deploy&&targetConfig.deploy.type){
_runDeployment(c,platform,deployType||targetConfig.deploy.type).
then(resolve).catch(reject);
}else{
var opts=(0,_prompt.generateOptions)([DEPLOY_TARGET_FTP,DEPLOY_TARGET_NOW,DEPLOY_TARGET_NONE]);
(0,_prompt.askQuestion)("Which type of deploy option would you like to use for "+_chalk.default.white(platform)+" deployment:\n"+opts.asString).
then(function(v){return opts.pick(v);}).
then(function(selectedDeployTarget){
(0,_prompt.finishQuestion)();
(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));
_runDeployment(c,platform,selectedDeployTarget).then(resolve).catch(reject);
}).
catch(function(e){return reject(e);});
}
});};exports.selectWebToolAndDeploy=selectWebToolAndDeploy;