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