"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ansi_colors_1=require("ansi-colors"),fs_1=require("fs"),inquirer=require("inquirer"),path_1=require("path"),rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),utils_1=require("../../../../lib/utils");function default_1(e){var t=utils_1.getRuntime();if(!t.workspaceRoot)throw Error("请在 NgCortex 工程目录中操作！");var i=e.params||{},n=e.options||{};Promise.resolve().then(function(){if(t.portalRoot||t.frontendRoot)return Promise.resolve();var r=[{type:"list",message:"请选择项目:",name:"cwd",choices:[]}];if(fs_1.readdirSync(t.workspaceRoot+"/frontends").forEach(function(e){r[0].choices.push({name:e,value:t.workspaceRoot+"/frontends/"+e})}),0===r[0].choices.length)throw new Error("暂无项目可操作");return inquirer.prompt(r).then(function(e){t=utils_1.getRuntime(e.cwd)})}).then(function(){var r;try{r=t.frontendConfig.schematics["@schematics/angular:component"].prefix||t.frontendConfig.schematics["@schematics/angular:directive"].prefix||"lib"}catch(e){r="lib"}var o={name:utils_1.getPascalCase(i.name),alias:utils_1.getPascalCase(i.name),prefix:n.prefix?utils_1.getSeparatorCase(n.prefix):r,fileName:utils_1.getSeparatorCase(i.name),frontendFileName:utils_1.getSeparatorCase(t.frontendName)};rxjs_1.zip(utils_1.src("./**/*",{base:path_1.join(__dirname,"./files")}).pipe(utils_1.transform(function(e){e.path="frontends/"+t.frontendName+"/"+e.path})),utils_1.src("./**/*",{base:path_1.join(__dirname,"./mock-files")}).pipe(utils_1.transform(function(e){e.path="mock/"+t.frontendName+"/"+e.path}))).pipe(operators_1.map(function(e){return[].concat.apply([],e)})).pipe(utils_1.ejs(o)).pipe(utils_1.dest(t.workspaceRoot,{workspaceRoot:t.workspaceRoot,log:!0})).subscribe(function(){var e,r;t.frontendConfig.projects[o.fileName]||(t.frontendConfig.projects[o.fileName]={projectType:"library",root:o.fileName,sourceRoot:o.fileName+"/src",prefix:o.prefix,architect:{build:{builder:"@angular-devkit/build-angular:ng-packagr",options:{tsConfig:o.fileName+"/tsconfig.lib.json",project:o.fileName+"/ng-package.json"},configurations:{production:{tsConfig:o.fileName+"/tsconfig.lib.prod.json"}}},lint:{builder:"@angular-devkit/build-angular:tslint",options:{tsConfig:[o.fileName+"/tsconfig.lib.json"],exclude:["**/node_modules/**"]}}}},e=path_1.join(t.frontendRoot,"angular.json"),r=JSON.stringify(t.frontendConfig,null,"  ")+"\n",fs_1.writeFileSync(e,r),utils_1.changeFileLog(ansi_colors_1.cyan("已更新"),e,t.workspaceRoot))})})}exports.default=default_1;
