"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var fs_1=require("fs"),inquirer=require("inquirer"),path_1=require("path"),utils_1=require("../../../../lib/utils");function default_1(e){var i=utils_1.getRuntime();if(!i.workspaceRoot)throw Error("请在 NgCortex 工程目录中操作！");var s=e.params||{},a=e.options||{};Promise.resolve().then(function(){if(i.portalRoot||i.frontendRoot)return Promise.resolve();var t=[{type:"list",message:"请选择项目:",name:"cwd",choices:[]}];if(t[0].choices.push({name:"portal",value:i.workspaceRoot+"/portal"}),fs_1.readdirSync(i.workspaceRoot+"/frontends").forEach(function(e){t[0].choices.push({name:e,value:i.workspaceRoot+"/frontends/"+e})}),0===t[0].choices.length)throw new Error("暂无项目可操作");return inquirer.prompt(t).then(function(e){i=utils_1.getRuntime(e.cwd)})}).then(function(){if(!i.frontendRoot||i.libraryRoot)return Promise.resolve();var t=[{type:"list",message:"请选择库项目:",name:"cwd",choices:[]}];if(Object.keys(i.frontendConfig.projects).forEach(function(e){t[0].choices.push({name:e,value:i.frontendRoot+"/"+e})}),0===t[0].choices.length)throw new Error("暂无库项目可操作");return inquirer.prompt(t).then(function(e){i=utils_1.getRuntime(e.cwd)})}).then(function(){var e,t,r;if(t=i.portalRoot?(e=process.cwd().split(/[\/\\]+/).join("/"),t=i.portalRoot+"/src",e.slice(0,t.length)===t?e:t):i.libraryRoot+"/src",i.portalRoot){try{r=i.portalConfig.projects.portal.prefix||i.portalConfig.schematics["@schematics/angular:component"].prefix||i.portalConfig.schematics["@schematics/angular:directive"].prefix}catch(e){}r=r||"app"}else{try{r=i.frontendConfig.schematics["@schematics/angular:component"].prefix||i.frontendConfig.schematics["@schematics/angular:directive"].prefix}catch(e){}r=r||"lib"}var o={name:utils_1.getPascalCase(s.name),alias:utils_1.getPascalCase(s.name),selector:a.selector?utils_1.getSeparatorCase(a.selector):r+"-"+utils_1.getSeparatorCase(s.name),fileName:utils_1.getSeparatorCase(s.name),route:utils_1.getSeparatorCase(s.name)};utils_1.src("./**/*",{base:path_1.join(__dirname,"./files")}).pipe(utils_1.ejs(o)).pipe(utils_1.dest(t,{workspaceRoot:i.workspaceRoot,log:!0})).subscribe(function(){return utils_1.exportAndConfigModule(i,o)})})}exports.default=default_1;
