UNPKG

4.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * @license
5 * Copyright Google Inc. All Rights Reserved.
6 *
7 * Use of this source code is governed by an MIT-style license that can be
8 * found in the LICENSE file at https://angular.io/license
9 */
10const node_1 = require("@angular-devkit/core/node");
11const util_1 = require("util");
12const command_runner_1 = require("../../models/command-runner");
13const color_1 = require("../../utilities/color");
14const config_1 = require("../../utilities/config");
15const log_file_1 = require("../../utilities/log-file");
16const project_1 = require("../../utilities/project");
17const debugEnv = process.env['NG_DEBUG'];
18const isDebug = debugEnv !== undefined &&
19 debugEnv !== '0' &&
20 debugEnv.toLowerCase() !== 'false';
21// tslint:disable: no-console
22async function default_1(options) {
23 // This node version check ensures that the requirements of the project instance of the CLI are met
24 const version = process.versions.node.split('.').map(part => Number(part));
25 if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
26 process.stderr.write(`Node.js version ${process.version} detected.\n` +
27 'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
28 'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n');
29 return 3;
30 }
31 const logger = node_1.createConsoleLogger(isDebug, process.stdout, process.stderr, {
32 info: s => (color_1.supportsColor ? s : color_1.removeColor(s)),
33 debug: s => (color_1.supportsColor ? s : color_1.removeColor(s)),
34 warn: s => (color_1.supportsColor ? color_1.colors.bold.yellow(s) : color_1.removeColor(s)),
35 error: s => (color_1.supportsColor ? color_1.colors.bold.red(s) : color_1.removeColor(s)),
36 fatal: s => (color_1.supportsColor ? color_1.colors.bold.red(s) : color_1.removeColor(s)),
37 });
38 // Redirect console to logger
39 console.log = function () {
40 logger.info(util_1.format.apply(null, arguments));
41 };
42 console.info = function () {
43 logger.info(util_1.format.apply(null, arguments));
44 };
45 console.warn = function () {
46 logger.warn(util_1.format.apply(null, arguments));
47 };
48 console.error = function () {
49 logger.error(util_1.format.apply(null, arguments));
50 };
51 let projectDetails = project_1.getWorkspaceDetails();
52 if (projectDetails === null) {
53 const [, localPath] = config_1.getWorkspaceRaw('local');
54 if (localPath !== null) {
55 logger.fatal(`An invalid configuration file was found ['${localPath}'].` +
56 ' Please delete the file before running the command.');
57 return 1;
58 }
59 projectDetails = { root: process.cwd() };
60 }
61 try {
62 const maybeExitCode = await command_runner_1.runCommand(options.cliArgs, logger, projectDetails);
63 if (typeof maybeExitCode === 'number') {
64 console.assert(Number.isInteger(maybeExitCode));
65 return maybeExitCode;
66 }
67 return 0;
68 }
69 catch (err) {
70 if (err instanceof Error) {
71 try {
72 const logPath = log_file_1.writeErrorToLogFile(err);
73 logger.fatal(`An unhandled exception occurred: ${err.message}\n` +
74 `See "${logPath}" for further details.`);
75 }
76 catch (e) {
77 logger.fatal(`An unhandled exception occurred: ${err.message}\n` +
78 `Fatal error writing debug log file: ${e.message}`);
79 if (err.stack) {
80 logger.fatal(err.stack);
81 }
82 }
83 return 127;
84 }
85 else if (typeof err === 'string') {
86 logger.fatal(err);
87 }
88 else if (typeof err === 'number') {
89 // Log nothing.
90 }
91 else {
92 logger.fatal('An unexpected error occurred: ' + JSON.stringify(err));
93 }
94 if (options.testing) {
95 // tslint:disable-next-line: no-debugger
96 debugger;
97 throw err;
98 }
99 return 1;
100 }
101}
102exports.default = default_1;