"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var child_process_1=require("child_process"),path_1=require("path"),js_beautify_1=require("js-beautify"),utils_1=require("../../lib/utils"),operators_1=require("rxjs/operators");function default_1(e){var t,r=e.params||{},s=e.options||{},i=utils_1.getEnvironment(),o=i.workspaceRoot,a=i.frontendRoot,n=i.angularJSON,e=i.libraryRoot,i=i.libraryName;if(!o)throw Error("请在 NgCortex 工程目录中操作！");if(!a)throw new Error("请在前端项目目录中操作！");n.projects=n.projects||{},t=r.name?utils_1.getSeparatorCase(r.name):e?i:n.defaultProject;e=n.projects[t];if(!e)throw new Error("编译项目不存在！");if("library"===e.projectType){try{child_process_1.execSync("ng build "+t,{cwd:a,stdio:"inherit"})}catch(e){process.exit()}var i=path_1.join(a,e.architect.build.options.project),n=require(i),p=path_1.join(path_1.dirname(i),n.dest);utils_1.src("./*.min.js",{base:path_1.join(p,"bundles")}).pipe(operators_1.mergeMap(function(e){return utils_1.src([p,path_1.join(p,"**/*")],{read:!1}).pipe(utils_1.clean()).pipe(operators_1.map(function(){return e}))})).pipe(utils_1.transform(function(e){e.basename=t+".js",e.content=Buffer.from(utils_1.removeComments(e.content.toString("utf8")))})).pipe(utils_1.dest(path_1.dirname(p))).subscribe()}else{try{var u="ng build --prod";s.baseHref&&(u+=" --base-href="+s.baseHref),child_process_1.execSync(u,{stdio:"inherit"})}catch(e){process.exit()}e=path_1.join(a,e.architect.build.options.outputPath);utils_1.src("./**.*",{base:e}).pipe(utils_1.transform(function(e){var t;".js"!==e.extname&&".html"!==e.extname||(t=utils_1.removeComments(e.content.toString("utf8")),".html"===e.extname&&(t=js_beautify_1.html_beautify(t,{indent_size:2,preserve_newlines:!1})),s.baseHref&&"/"!==s.baseHref&&(t=t.replace(/(?<!\.)\/assets(?![A-Za-z])/g,"./assets")),e.content=Buffer.from(t))})).pipe(utils_1.dest(e)).subscribe()}}exports.default=default_1;
