var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.PIPES=void 0;var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _shelljs=_interopRequireDefault(require("shelljs"));
var _chalk=_interopRequireDefault(require("chalk"));
var _common=require("../common");

















var _prompt=require("../systemTools/prompt");
var _constants=require("../constants");
var _exec=require("../systemTools/exec");
var _buildHooks=require("../projectTools/buildHooks");
var _app=_interopRequireWildcard(require("./app"));
var _templateTools=require("../templateTools");

var LIST='list';
var ADD='add';
var REMOVE='remove';
var APPLY='apply';

var PIPES={
ADD_BEFORE:'add:before',
ADD_AFTER:'add:after'};exports.PIPES=PIPES;






var run=function run(c){
(0,_common.logTask)('run');

switch(c.subCommand){
case LIST:
return _templateList(c);
case ADD:
return _templateAdd(c);
case APPLY:
return _templateApply(c);

default:
return Promise.reject("cli:template Command "+c.command+" not supported");}

};





var _templateList=function _templateList(c){return new Promise(function(resolve,reject){
(0,_common.logTask)('_templateList');
(0,_templateTools.listTemplates)(c).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};

var _templateAdd=function _templateAdd(c){return new Promise(function(resolve,reject){
(0,_common.logTask)('_templateAdd');

var opts=(0,_templateTools.getTemplateOptions)(c);

(0,_prompt.askQuestion)("Pick which template to install : \n"+opts.asString).
then(function(v){return opts.pick(v);}).
then(function(){return(0,_templateTools.addTemplate)(c,opts);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};

var _templateApply=function _templateApply(c){return new Promise(function(resolve,reject){
(0,_common.logTask)("_templateApply:"+c.program.template);

if(c.program.template){
(0,_templateTools.applyTemplate)(c,c.program.template).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
}else{
var opts=(0,_templateTools.getInstalledTemplateOptions)(c);

(0,_prompt.askQuestion)("Pick which template to apply "+_chalk.default.yellow('(NOTE: your project content will be overriden!)')+": \n"+opts.asString).
then(function(v){return opts.pick(v);}).
then(function(v){
(0,_prompt.finishQuestion)();
return Promise.resolve();
}).
then(function(){return(0,_templateTools.applyTemplate)(c,opts.selectedOption);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
}
});};var _default=



run;exports.default=_default;