1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | require("symbol-observable");
|
11 |
|
12 |
|
13 | const core_1 = require("@angular-devkit/core");
|
14 | const fs = require("fs");
|
15 | const path = require("path");
|
16 | const semver_1 = require("semver");
|
17 | const stream_1 = require("stream");
|
18 | const color_1 = require("../utilities/color");
|
19 | const config_1 = require("../utilities/config");
|
20 | const packageJson = require('../package.json');
|
21 | function _fromPackageJson(cwd = process.cwd()) {
|
22 | do {
|
23 | const packageJsonPath = path.join(cwd, 'node_modules/@angular/cli/package.json');
|
24 | if (fs.existsSync(packageJsonPath)) {
|
25 | const content = fs.readFileSync(packageJsonPath, 'utf-8');
|
26 | if (content) {
|
27 | const { version } = JSON.parse(content);
|
28 | if (version) {
|
29 | return new semver_1.SemVer(version);
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
34 | cwd = path.dirname(cwd);
|
35 | } while (cwd != path.dirname(cwd));
|
36 | return null;
|
37 | }
|
38 |
|
39 | if (process.env['NG_CLI_PROFILING']) {
|
40 | let profiler;
|
41 | try {
|
42 | profiler = require('v8-profiler-node8');
|
43 | }
|
44 | catch (err) {
|
45 | throw new Error(`Could not require 'v8-profiler-node8'. You must install it separetely with ` +
|
46 | `'npm install v8-profiler-node8 --no-save'.\n\nOriginal error:\n\n${err}`);
|
47 | }
|
48 | profiler.startProfiling();
|
49 | const exitHandler = (options) => {
|
50 | if (options.cleanup) {
|
51 | const cpuProfile = profiler.stopProfiling();
|
52 | fs.writeFileSync(path.resolve(process.cwd(), process.env.NG_CLI_PROFILING || '') + '.cpuprofile', JSON.stringify(cpuProfile));
|
53 | }
|
54 | if (options.exit) {
|
55 | process.exit();
|
56 | }
|
57 | };
|
58 | process.on('exit', () => exitHandler({ cleanup: true }));
|
59 | process.on('SIGINT', () => exitHandler({ exit: true }));
|
60 | process.on('uncaughtException', () => exitHandler({ exit: true }));
|
61 | }
|
62 | (async () => {
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';
|
70 | const disableVersionCheckEnv = process.env['NG_DISABLE_VERSION_CHECK'];
|
71 | |
72 |
|
73 |
|
74 |
|
75 | const disableVersionCheck = disableVersionCheckEnv !== undefined &&
|
76 | disableVersionCheckEnv !== '0' &&
|
77 | disableVersionCheckEnv.toLowerCase() !== 'false';
|
78 | if (disableVersionCheck) {
|
79 | return (await Promise.resolve().then(() => require('./cli'))).default;
|
80 | }
|
81 | let cli;
|
82 | try {
|
83 | const projectLocalCli = require.resolve('@angular/cli', { paths: [process.cwd()] });
|
84 |
|
85 | const globalVersion = new semver_1.SemVer(packageJson['version']);
|
86 | let localVersion;
|
87 | let shouldWarn = false;
|
88 | try {
|
89 | localVersion = _fromPackageJson();
|
90 | shouldWarn = localVersion != null && globalVersion.compare(localVersion) > 0;
|
91 | }
|
92 | catch (e) {
|
93 |
|
94 | console.error(e);
|
95 | shouldWarn = true;
|
96 | }
|
97 | if (shouldWarn && await config_1.isWarningEnabled('versionMismatch')) {
|
98 | const warning = color_1.colors.yellow(core_1.tags.stripIndents `
|
99 | Your global Angular CLI version (${globalVersion}) is greater than your local
|
100 | version (${localVersion}). The local Angular CLI version is used.
|
101 |
|
102 | To disable this warning use "ng config -g cli.warnings.versionMismatch false".
|
103 | `);
|
104 |
|
105 | if (process.argv[2] !== 'completion') {
|
106 |
|
107 | console.error(warning);
|
108 | }
|
109 | else {
|
110 |
|
111 | console.error(warning);
|
112 | process.exit(1);
|
113 | }
|
114 | }
|
115 |
|
116 |
|
117 | cli = await Promise.resolve().then(() => require(projectLocalCli));
|
118 | }
|
119 | catch (_a) {
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | cli = await Promise.resolve().then(() => require('./cli'));
|
125 | }
|
126 | if ('default' in cli) {
|
127 | cli = cli['default'];
|
128 | }
|
129 | return cli;
|
130 | })().then(cli => {
|
131 |
|
132 | let standardInput;
|
133 | try {
|
134 | standardInput = process.stdin;
|
135 | }
|
136 | catch (e) {
|
137 | delete process.stdin;
|
138 | process.stdin = new stream_1.Duplex();
|
139 | standardInput = process.stdin;
|
140 | }
|
141 | return cli({
|
142 | cliArgs: process.argv.slice(2),
|
143 | inputStream: standardInput,
|
144 | outputStream: process.stdout,
|
145 | });
|
146 | }).then((exitCode) => {
|
147 | process.exit(exitCode);
|
148 | })
|
149 | .catch((err) => {
|
150 |
|
151 | console.error('Unknown error: ' + err.toString());
|
152 | process.exit(127);
|
153 | });
|