"use strict";var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function c(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}u((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};exports.__esModule=!0,exports.compileComponet=void 0;var componentComplieService_1=__importDefault(require("../services/componentComplieService")),util_1=require("./util"),getComRootDirByName_1=__importDefault(require("../utils/getComRootDirByName")),selectCom_1=__importDefault(require("../prompts/selectCom")),inquirer=require("inquirer"),chalk=require("chalk"),posix=require("path").posix;exports.default=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var r,n,o,i,a,c;return __generator(this,(function(u){switch(u.label){case 0:return r=process.cwd(),n=(0,util_1.checkCurrentIsCanvasCom)(r),[4,(0,util_1.checkIsCanvasProject)(r)];case 1:return o=u.sent(),e?[4,(0,getComRootDirByName_1.default)(e)]:[3,4];case 2:return(i=u.sent())?[4,(0,exports.compileComponet)(i,t)]:[2];case 3:return u.sent(),[3,7];case 4:return n?[4,(0,exports.compileComponet)(r)]:[3,6];case 5:return u.sent(),[3,7];case 6:o.length>0&&(a=[],o.forEach((function(e){var t=require(posix.join(e)).canvas,r=t.name,n=t.cn_name;a.push({name:r,cn_name:n})})),c=(0,selectCom_1.default)(a),inquirer.prompt(c).then((function(e){return __awaiter(void 0,void 0,void 0,(function(){var t;return __generator(this,(function(r){switch(r.label){case 0:return t=e.com,[4,batchCompileComponents(t)];case 1:return r.sent(),[2]}}))}))}))),u.label=7;case 7:return[2]}}))}))};var compileComponet=function(e,t){return __awaiter(void 0,void 0,void 0,(function(){var r,n;return __generator(this,(function(o){switch(o.label){case 0:return r=require(posix.join("".concat(e,"/package.json"))).canvas,n=r.cn_name,t=t||function(){console.log("".concat(chalk.blue("success"),"  组件").concat(n,"已构建完成"))},[4,(0,componentComplieService_1.default)(e,t)];case 1:return o.sent(),[2]}}))}))};exports.compileComponet=compileComponet;var batchCompileComponents=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r;return __generator(this,(function(n){switch(n.label){case 0:t=0,n.label=1;case 1:return t<e.length?[4,(0,getComRootDirByName_1.default)(e[t])]:[3,6];case 2:return r=n.sent(),r?[4,(0,exports.compileComponet)(r)]:[3,4];case 3:n.sent(),n.label=4;case 4:n.label=5;case 5:return t++,[3,1];case 6:return[2]}}))}))};