"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function a(e){try{u(o.next(e))}catch(e){s(e)}}function i(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,i)}u((o=o.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,o,n,s,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,o&&(n=2&s[0]?o.return:s[0]?o.throw||((n=o.return)&&n.call(o),0):o.next)&&!(n=n.call(o,s[1])).done)return n;switch(o=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){a.label=s[1];break}if(6===s[0]&&a.label<n[1]){a.label=n[1],n=s;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(s);break}n[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],o=0}finally{r=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}};exports.__esModule=!0;var express=require("express"),open=require("open"),chalk=require("chalk"),serverIndex=require("serve-index"),bodyParser=require("body-parser"),fs=require("fs-extra"),fileUpload=require("express-fileupload"),cors=require("cors"),path=require("path"),getModuleInfo=require("./util").getModuleInfo,_a=require("./route"),getComponentList=_a.getComponentList,createComponent=_a.createComponent,deleteComponent=_a.deleteComponent,serverComponent=_a.serverComponent,compileComponent=_a.compileComponent,uploadSource=_a.uploadSource,getPreviewComList=_a.getPreviewComList,guiPath=path.resolve(__dirname,"../../lib/operateGui"),paths=require("../../utils/paths");exports.default=function(){return __awaiter(void 0,void 0,void 0,(function(){var e,t;return __generator(this,(function(r){switch(r.label){case 0:return[4,getModuleInfo()];case 1:return e=r.sent().staticPaths,[4,fs.ensureDir(paths.userSourceDir)];case 2:return r.sent(),(t=express()).use(cors()),t.use(bodyParser.urlencoded({extended:!0})),t.use(bodyParser.json()),t.use(bodyParser.raw()),t.use(express.static(guiPath)),t.use(fileUpload()),t.use("/",(function(e,t,r){if("GET"!==e.method&&"HEAD"!==e.method)return r();serverIndex(guiPath,{icons:!0})(e,t,r)})),e.forEach((function(e){t.use("/static",express.static(e))})),t.use("/static",express.static(paths.userSourceDir)),t.post("/v2/comList",getComponentList),t.post("/v2/create",createComponent),t.post("/v2/delete",deleteComponent),t.post("/v2/server",serverComponent),t.post("/v2/compile/:id",compileComponent),t.post("/v2/upload",uploadSource),t.listen(9e3),open("http://localhost:9000"),console.log("".concat(chalk.blue("success")," gui has opened at http://localhost:9000")),[2]}}))}))};