UNPKG

foalts2-cli

Version:

CLI tool for FoalTS

54 lines (53 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.connectAngular = void 0; const path_1 = require("path"); const safe_1 = require("colors/safe"); const file_system_1 = require("../../file-system"); function connectAngular(path) { const fs = new file_system_1.FileSystem(); if (!fs.exists(path)) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log(safe_1.red(` The directory ${path} does not exist.`)); } return; } if (!fs.exists(path_1.join(path, 'angular.json'))) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log(safe_1.red(` The directory ${path} is not an Angular project (missing angular.json).`)); } return; } if (!fs.exists(path_1.join(path, 'package.json'))) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log(safe_1.red(` The directory ${path} is not an Angular project (missing package.json).`)); } return; } fs .cd(path) .copy('angular/proxy.conf.json', 'src/proxy.conf.json') .modify('package.json', content => { const pkg = JSON.parse(content); pkg.scripts.build = 'ng build --prod'; return JSON.stringify(pkg, null, 2); }) .modify('angular.json', content => { var _a, _b, _c, _d, _e; const config = JSON.parse(content); // Proxy configuration (_a = config.projects[config.defaultProject]).architect || (_a.architect = {}); (_b = config.projects[config.defaultProject].architect).serve || (_b.serve = {}); (_c = config.projects[config.defaultProject].architect.serve).options || (_c.options = {}); config.projects[config.defaultProject].architect.serve.options.proxyConfig = 'src/proxy.conf.json'; // Output build directory const outputPath = path_1.join(path_1.relative(path, process.cwd()), 'public') // Make projects generated on Windows build on Unix. .replace(/\\/g, '/'); (_d = config.projects[config.defaultProject].architect).build || (_d.build = {}); (_e = config.projects[config.defaultProject].architect.build).options || (_e.options = {}); config.projects[config.defaultProject].architect.build.options.outputPath = outputPath; return JSON.stringify(config, null, 2); }); } exports.connectAngular = connectAngular;