"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ansi_colors_1=require("ansi-colors"),fs_1=require("fs"),path_1=require("path"),utils_1=require("../../../../lib/utils");function default_1(e){var r,t,s=e.params||{},a=e.options||{},n=utils_1.getEnvironment(),o=n.workspaceRoot,i=n.frontendRoot,l=n.frontendType,u=n.angularJSON,e=n.libraryRoot,c=n.libraryName;if(!o)throw Error("请在 NgCortex 工程目录中操作！");if(!i)throw new Error("请在前端项目目录中操作！");if("frontend"===l)r=path_1.join(i,"src/app");else{if(!e)throw new Error("请在库项目目录中操作！");r=path_1.join(e,"src")}try{t=u.schematics["@schematics/angular:component"].prefix}catch(e){}e=(t=t||("frontend"===l?"app":"lib"))+"-"+utils_1.getSeparatorCase(s.name),e={getPascalCase:utils_1.getPascalCase,getSeparatorCase:utils_1.getSeparatorCase,name:s.name,selector:a.selector?utils_1.getSeparatorCase(a.selector):e};process.chdir(__dirname),utils_1.src("./**/*",{base:"./files"}).pipe(utils_1.ejs(e)).pipe(utils_1.dest(r,{workspaceRoot:o,log:!0})).subscribe(function(e){var r=e.filter(function(e){return".ts"===e.extname}).map(function(e){return e.fullPath});utils_1.appendLibraryExports(n,r),"micro-frontend"===l&&(e=i+"/dev-routing.module.ts",r=(r=fs_1.readFileSync(e,"utf8")).replace(/(?<=export +const +routes *: *NcRoute\[\] += +)\[(.|\n|\r)*\](?= *;* *\n*(.|\n|\r)*@NgModule)/g,function(e){function r(e){for(var r="",t=0;t<e;t++)r+=n;return r}function t(){return r(1)+"{\n"+r(2)+"path: '"+utils_1.getSeparatorCase(s.name)+"',\n"+r(2)+"data: { name: '"+utils_1.getPascalCase(s.name)+"', major: true, reused: true },\n"+r(2)+"loadChildren: () => import('./"+c+"/src/public-api').then(library => library."+utils_1.getPascalCase(s.name)+"Module)\n"+r(1)+"}"}if(/\[( |\n|\r)*\]/.test(e))return n="    ","[\n"+t()+"\n]";var a=e.match(/(?<=\[ *\n+) */),n=a?a[0]:"    ";return e.replace(/,?\n*(?= *]$)/,",\n"+t()+"\n")}),fs_1.writeFileSync(e,r),utils_1.changeFileLog(ansi_colors_1.cyan("已更新"),e,o))})}exports.default=default_1;
