UNPKG

@foal/cli

Version:

CLI tool for FoalTS

53 lines (52 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.connectAngular = connectAngular; 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((0, safe_1.red)(` The directory ${path} does not exist.`)); } return; } if (!fs.exists((0, path_1.join)(path, 'angular.json'))) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log((0, safe_1.red)(` The directory ${path} is not an Angular project (missing angular.json).`)); } return; } if (!fs.exists((0, path_1.join)(path, 'package.json'))) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log((0, 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 => { const config = JSON.parse(content); const projectName = Object.keys(config.projects)[0]; // Proxy configuration config.projects[projectName].architect ||= {}; config.projects[projectName].architect.serve ||= {}; config.projects[projectName].architect.serve.options ||= {}; config.projects[projectName].architect.serve.options.proxyConfig = 'src/proxy.conf.json'; // Output build directory const outputPath = (0, path_1.join)((0, path_1.relative)(path, process.cwd()), 'public') // Make projects generated on Windows build on Unix. .replace(/\\/g, '/'); config.projects[projectName].architect.build ||= {}; config.projects[projectName].architect.build.options ||= {}; config.projects[projectName].architect.build.options.outputPath = outputPath; return JSON.stringify(config, null, 2); }); }