"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((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:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){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,s])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0,exports.BASE_PATH=exports.isExistDir=exports.getModuleEntry=exports.checkIsCanvasProject=exports.checkCurrentIsCanvasCom=exports.checkExistCom=void 0;var fs=require("fs-extra"),stat=require("fs").promises.stat,inquire=require("inquirer"),chalk=require("chalk"),globby=require("globby"),path=require("path").posix,getCanvasCompaths_1=__importDefault(require("../utils/getCanvasCompaths")),checkExistCom=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var r;return __generator(this,(function(n){switch(n.label){case 0:return fs.existsSync(e)?[4,inquire.prompt([{name:"action",type:"list",message:"Target component ".concat(t," ").concat(chalk.cyan(t)," already exists. Pick an action:"),choices:[{name:"Overwrite",value:"overwrite"},{name:"Merge",value:"merge"}]}])]:[3,4];case 1:return(r=n.sent().action)?[3,2]:[2];case 2:return"overwrite"!==r?[3,4]:(console.log("\nRemoving ".concat(chalk.cyan(t),"...")),[4,fs.remove(e)]);case 3:n.sent(),n.label=4;case 4:return[2]}}))}))};exports.checkExistCom=checkExistCom;var checkCurrentIsCanvasCom=function(e){var t=!1;try{t=!!require(e).canvas}catch(e){}return t};exports.checkCurrentIsCanvasCom=checkCurrentIsCanvasCom;var checkIsCanvasProject=function(e){return __awaiter(void 0,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:return[4,(0,getCanvasCompaths_1.default)(e)];case 1:return[2,t.sent().filter((function(e){return!!require(e).canvas}))]}}))}))};exports.checkIsCanvasProject=checkIsCanvasProject;var getModuleEntry=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var r;return __generator(this,(function(n){switch(n.label){case 0:return(r=t.main)?[2,path.join(e,r)]:[3,1];case 1:return[4,globby(path.join(e,"index.@(js|jsx|ts|tsx)"))];case 2:return[2,n.sent()]}}))}))};function isExistDir(e){return __awaiter(this,void 0,void 0,(function(){var t,r;return __generator(this,(function(n){switch(n.label){case 0:return t=!0,[4,stat(e).catch((function(){t=!1}))];case 1:return(r=n.sent()||{}).isDirectory&&r.isDirectory()||(t=!1),[2,t]}}))}))}exports.getModuleEntry=getModuleEntry,exports.isExistDir=isExistDir,exports.BASE_PATH="http://localhost";