|
5 | 5 | // Due to an obscure Mac bug, do not start this title with any symbol.
|
6 | 6 | process.title = 'ng';
|
7 | 7 |
|
8 |
| -const isWarningEnabled = require('../utilities/config').isWarningEnabled; |
9 |
| -const Version = require('../upgrade/version').Version; |
| 8 | +var red = require('chalk').red; |
10 | 9 |
|
11 |
| -const fs = require('fs'); |
12 |
| -const findUp = require('../utilities/find-up').findUp; |
13 |
| -const packageJson = require('../package.json'); |
14 |
| -const path = require('path'); |
15 |
| -const resolve = require('resolve'); |
16 |
| -const stripIndents = require('common-tags').stripIndents; |
17 |
| -const yellow = require('chalk').yellow; |
18 |
| -const SemVer = require('semver').SemVer; |
19 |
| -const semver = require('semver'); |
20 |
| -const events = require('events'); |
21 |
| - |
22 |
| - |
23 |
| -function _fromPackageJson(cwd) { |
24 |
| - cwd = cwd || process.cwd(); |
25 |
| - |
26 |
| - do { |
27 |
| - const packageJsonPath = path.join(cwd, 'node_modules/@angular/cli/package.json'); |
28 |
| - if (fs.existsSync(packageJsonPath)) { |
29 |
| - const content = fs.readFileSync(packageJsonPath, 'utf-8'); |
30 |
| - if (content) { |
31 |
| - const json = JSON.parse(content); |
32 |
| - if (json['version']) { |
33 |
| - return new SemVer(json['version']); |
34 |
| - } |
35 |
| - } |
36 |
| - } |
37 |
| - |
38 |
| - // Check the parent. |
39 |
| - cwd = path.dirname(cwd); |
40 |
| - } while (cwd != path.dirname(cwd)); |
41 |
| - |
42 |
| - return null; |
43 |
| -} |
44 |
| - |
45 |
| - |
46 |
| -// Check if we need to profile this CLI run. |
47 |
| -let profiler = null; |
48 |
| -if (process.env['NG_CLI_PROFILING']) { |
49 |
| - profiler = require('v8-profiler'); |
50 |
| - profiler.startProfiling(); |
51 |
| - function exitHandler(options, err) { |
52 |
| - if (options.cleanup) { |
53 |
| - const cpuProfile = profiler.stopProfiling(); |
54 |
| - fs.writeFileSync(path.resolve(process.cwd(), process.env.NG_CLI_PROFILING) + '.cpuprofile', |
55 |
| - JSON.stringify(cpuProfile)); |
56 |
| - } |
57 |
| - |
58 |
| - if (options.exit) { |
59 |
| - process.exit(); |
60 |
| - } |
61 |
| - } |
62 |
| - |
63 |
| - process.on('exit', exitHandler.bind(null, { cleanup: true })); |
64 |
| - process.on('SIGINT', exitHandler.bind(null, { exit: true })); |
65 |
| - process.on('uncaughtException', exitHandler.bind(null, { exit: true })); |
66 |
| -} |
67 |
| - |
68 |
| - |
69 |
| -// Show the warnings/errors due to package and version deprecation. |
70 |
| -const version = new SemVer(process.version); |
71 |
| -if (version.compare(new SemVer('8.9.0')) < 0 && isWarningEnabled('nodeDeprecation')) { |
72 |
| - process.stderr.write(yellow(stripIndents` |
73 |
| - You are running version ${version.version} of Node, which is not supported by Angular CLI v6. |
74 |
| - The official Node version that is supported is 8.9 and greater. |
75 |
| -
|
76 |
| - Please visit https://nodejs.org/en/ to find instructions on how to update Node. |
77 |
| - `)); |
| 10 | +var version = process.version.substr(1).split('.'); |
| 11 | +if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) { |
| 12 | + process.stderr.write(red( |
| 13 | + 'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' + |
| 14 | + 'The official Node.js version that is supported is 8.9 and greater.\n\n' + |
| 15 | + 'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n' |
| 16 | + )); |
78 | 17 |
|
79 | 18 | process.exit(3);
|
80 | 19 | }
|
81 | 20 |
|
82 |
| -resolve('@angular/cli', { basedir: process.cwd() }, |
83 |
| - function (error, projectLocalCli) { |
84 |
| - var cli; |
85 |
| - if (error) { |
86 |
| - // If there is an error, resolve could not find the ng-cli |
87 |
| - // library from a package.json. Instead, include it from a relative |
88 |
| - // path to this script file (which is likely a globally installed |
89 |
| - // npm package). Most common cause for hitting this is `ng new` |
90 |
| - cli = require('../lib/cli'); |
91 |
| - } else { |
92 |
| - // This was run from a global, check local version. |
93 |
| - const globalVersion = new SemVer(packageJson['version']); |
94 |
| - let localVersion; |
95 |
| - let shouldWarn = false; |
96 |
| - |
97 |
| - try { |
98 |
| - localVersion = _fromPackageJson(); |
99 |
| - shouldWarn = localVersion && globalVersion.compare(localVersion) > 0; |
100 |
| - } catch (e) { |
101 |
| - // eslint-disable-next-line no-console |
102 |
| - console.error(e); |
103 |
| - shouldWarn = true; |
104 |
| - } |
105 |
| - |
106 |
| - if (shouldWarn && isWarningEnabled('versionMismatch')) { |
107 |
| - let warning = yellow(stripIndents` |
108 |
| - Your global Angular CLI version (${globalVersion}) is greater than your local |
109 |
| - version (${localVersion}). The local Angular CLI version is used. |
110 |
| -
|
111 |
| - To disable this warning use "ng set --global warnings.versionMismatch=false". |
112 |
| - `); |
113 |
| - // Don't show warning colorised on `ng completion` |
114 |
| - if (process.argv[2] !== 'completion') { |
115 |
| - // eslint-disable-next-line no-console |
116 |
| - console.log(warning); |
117 |
| - } else { |
118 |
| - // eslint-disable-next-line no-console |
119 |
| - console.error(warning); |
120 |
| - process.exit(1); |
121 |
| - } |
122 |
| - } |
123 |
| - |
124 |
| - // No error implies a projectLocalCli, which will load whatever |
125 |
| - // version of ng-cli you have installed in a local package.json |
126 |
| - cli = require(projectLocalCli); |
127 |
| - } |
128 |
| - |
129 |
| - if ('default' in cli) { |
130 |
| - cli = cli['default']; |
131 |
| - } |
132 |
| - |
133 |
| - let standardInput; |
134 |
| - try { |
135 |
| - standardInput = process.stdin; |
136 |
| - } catch (e) { |
137 |
| - delete process.stdin; |
138 |
| - process.stdin = new events.EventEmitter(); |
139 |
| - standardInput = process.stdin; |
140 |
| - } |
141 |
| - |
142 |
| - cli({ |
143 |
| - cliArgs: process.argv.slice(2), |
144 |
| - inputStream: standardInput, |
145 |
| - outputStream: process.stdout |
146 |
| - }).then(function (exitCode) { |
147 |
| - process.exit(exitCode); |
148 |
| - }).catch(function(err) { |
149 |
| - console.log('Unknown error: ' + err.toString()); |
150 |
| - process.exit(127); |
151 |
| - }); |
152 |
| - }); |
| 21 | +require('../lib/init'); |
0 commit comments