"use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},__assign.apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{s(n.next(e))}catch(e){o(e)}}function c(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,c)}s((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0;var fs=require("fs-extra"),path=require("path"),inquire=require("inquirer"),chalk=require("chalk"),projectPackageJson_template_1=__importDefault(require("../template/projectPackageJson.template")),createComponent_1=__importDefault(require("./createComponent")),createProject=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n,a,o;return __generator(this,(function(i){switch(i.label){case 0:return t=e.rootPath,r=e.projectName,n=path.resolve(t,r),a=(0,projectPackageJson_template_1.default)(e),fs.existsSync(n)?[4,inquire.prompt([{name:"action",type:"list",message:"Target directory ".concat(chalk.cyan(n)," already exists. Pick an action:"),choices:[{name:"Overwrite",value:"overwrite"},{name:"Merge",value:"merge"}]}])]:[3,4];case 1:return(o=i.sent().action)?[3,2]:[2];case 2:return"overwrite"!==o?[3,4]:(console.log("\nRemoving ".concat(chalk.cyan(n),"...")),[4,fs.remove(n)]);case 3:i.sent(),i.label=4;case 4:return[4,fs.ensureDir(n)];case 5:return i.sent(),[4,fs.writeFile("".concat(n,"/package.json"),a)];case 6:return i.sent(),[4,(0,createComponent_1.default)(__assign(__assign({},e),{projectPath:n}))];case 7:return i.sent(),[2]}}))}))};exports.default=createProject;