"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&__createBinding(t,e,n);return __setModuleDefault(t,e),t},__awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function c(e){try{u(r.next(e))}catch(e){o(e)}}function i(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,i)}u((r=r.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var n,r,a,o,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;c;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(a=c.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){c.label=o[1];break}if(6===o[0]&&c.label<a[1]){c.label=a[1],a=o;break}if(a&&c.label<a[2]){c.label=a[2],c.ops.push(o);break}a[2]&&c.ops.pop(),c.trys.pop();continue}o=t.call(e,c)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0;var componentPackage_template_1=__importStar(require("../template/componentPackage.template.")),react_1=__importDefault(require("../template/react")),vue_1=__importDefault(require("../template/vue")),config_template_1=__importDefault(require("../template/config.template")),execa=require("execa"),chalk=require("chalk"),path=require("path"),fs=require("fs-extra"),_a=require("../utils/spinner"),logWithSpinner=_a.logWithSpinner,stopSpinner=_a.stopSpinner;exports.default=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,n,r,a,o,c,i,u,l,s,f,p,_,h,d;return __generator(this,(function(m){switch(m.label){case 0:return t=e.projectPath,n=e.comName,r=e.framework,a=e.language,o=e.rootPath,c=e.entry,i=t||o,u=path.resolve(i,n),l="".concat(u,"/static"),s="".concat(u,"/assets"),f="".concat(u,"/canvas.config.js"),p=(0,componentPackage_template_1.default)(e),_=(0,componentPackage_template_1.getEntryFile)(a,c,r),h="react"===r?(0,react_1.default)({projectName:n}):(0,vue_1.default)({projectName:n}),[4,fs.ensureDir(u)];case 1:return m.sent(),[4,fs.ensureDir(l)];case 2:return m.sent(),[4,fs.ensureDir(s)];case 3:return m.sent(),[4,fs.ensureFile(f)];case 4:return m.sent(),[4,fs.writeFile(f,(0,config_template_1.default)())];case 5:return m.sent(),[4,fs.writeFile("".concat(u,"/package.json"),p)];case 6:return m.sent(),[4,fs.writeFile("".concat(u,"/").concat(_),h)];case 7:return m.sent(),d=[],"typescript"===a&&"react"===r&&d.push("@types/".concat(r)),d.forEach((function(e){logWithSpinner("📦  Installing ".concat(chalk.cyan(e),"...")),execa.command("cd ".concat(u," && npm install ").concat(e," --save-dev"),{shell:!0}).then((function(e){var t=(e||{}).stdout;console.log("\n ".concat(t))})).catch((function(e){console.error(chalk.bgRed(" ERROR "),chalk.red(e.message))})).finally((function(){stopSpinner()}))})),[2]}}))}))};