"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(a,o){function c(t){try{u(r.next(t))}catch(t){o(t)}}function i(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(c,i)}u((r=r.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){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=e.call(t,c)}catch(t){o=[6,t],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(t){return t&&t.__esModule?t:{default:t}};exports.__esModule=!0;var getCanvasCompaths_1=__importDefault(require("../../utils/getCanvasCompaths")),entry_template_1=__importDefault(require("../../template/entry.template")),getComEntryPath_1=__importDefault(require("../../utils/getComEntryPath")),toHumpName_1=__importDefault(require("../../utils/toHumpName")),path=require("path").posix,fs=require("fs-extra"),paths=require("../../utils/paths"),createEntry=function(t,e){return void 0===t&&(t=9e3),__awaiter(void 0,void 0,void 0,(function(){var n,r,a,o,c,i,u,s,l,f,p,h,m,_,y,d,v,b,g,w,E,C,k,x;return __generator(this,(function(D){switch(D.label){case 0:return n=process.cwd(),r=[],a=[],[4,fs.ensureDir(paths.ComEntryDir)];case 1:return D.sent(),[4,(0,getCanvasCompaths_1.default)(n)];case 2:o=D.sent(),c="".concat(paths.ComEntryDir,"/entry-").concat(t,".js"),i="",u=0,D.label=3;case 3:return u<o.length?(s=o[u],l=require(s),f=l.name,p=l.canvas,h=void 0===p?{}:p,e.includes(f)?(m=path.parse(s).dir,_=h.icon,y=h.framework,[4,(0,getComEntryPath_1.default)(m)]):[3,5]):[3,6];case 4:d=D.sent(),v=path.join("".concat(m,"/").concat(_)),b=(0,toHumpName_1.default)(f),g="import ".concat(b,"Entry from '").concat(d,"'"),w="import ".concat(b,"Package from '").concat(s,"'"),E=_?"import ".concat(b,"Icon from '").concat(v,"'"):"",C=_?"'".concat(f,"Icon': ").concat(b,"Icon,"):"",k=y&&"react"===y?"hot(".concat(b,"Entry)"):"".concat(b,"Entry"),i="\n                  ".concat(i,"\n                  '").concat(f,"Entry': ").concat(k,",\n                  '").concat(f,"Package':").concat(b,"Package,\n                  ").concat(C,"\n                  "),r.push(m),a.push({comEntry:g,comPackageJson:w,comIcon:E}),D.label=5;case 5:return u++,[3,3];case 6:return x=(0,entry_template_1.default)(a,i),fs.writeFileSync(c,x),[2,{entryFile:c,comInfos:r}]}}))}))};exports.default=createEntry;