@@ -7,6 +7,33 @@ process.title = 'angular-cli';
7
7
const resolve = require ( 'resolve' ) ;
8
8
const packageJson = require ( '../package.json' ) ;
9
9
const Version = require ( '../upgrade/version' ) . Version ;
10
+ const yellow = require ( 'chalk' ) . yellow ;
11
+ const SemVer = require ( 'semver' ) . SemVer ;
12
+ const fs = require ( 'fs' ) ;
13
+ const path = require ( 'path' ) ;
14
+
15
+
16
+ function _fromPackageJson ( cwd ) {
17
+ cwd = cwd || process . cwd ( ) ;
18
+
19
+ do {
20
+ const packageJsonPath = path . join ( cwd , 'node_modules/angular-cli/package.json' ) ;
21
+ if ( fs . existsSync ( packageJsonPath ) ) {
22
+ const content = fs . readFileSync ( packageJsonPath , 'utf-8' ) ;
23
+ if ( content ) {
24
+ const json = JSON . parse ( content ) ;
25
+ if ( json [ 'version' ] ) {
26
+ return new SemVer ( json [ 'version' ] ) ;
27
+ }
28
+ }
29
+ }
30
+
31
+ // Check the parent.
32
+ cwd = path . dirname ( cwd ) ;
33
+ } while ( cwd != path . dirname ( cwd ) ) ;
34
+
35
+ return null ;
36
+ }
10
37
11
38
12
39
resolve ( 'angular-cli' , { basedir : process . cwd ( ) } ,
@@ -22,6 +49,25 @@ resolve('angular-cli', { basedir: process.cwd() },
22
49
// Verify that package's version.
23
50
Version . assertPostWebpackVersion ( ) ;
24
51
52
+ // This was run from a global, check local version.
53
+ const globalVersion = new SemVer ( packageJson [ 'version' ] ) ;
54
+ let localVersion ;
55
+ let shouldWarn = false ;
56
+
57
+ try {
58
+ localVersion = _fromPackageJson ( ) ;
59
+ shouldWarn = localVersion && globalVersion . compare ( localVersion ) < 0 ;
60
+ } catch ( e ) {
61
+ console . error ( e ) ;
62
+ shouldWarn = true ;
63
+ }
64
+
65
+ if ( shouldWarn ) {
66
+ // eslint-disable no-console
67
+ console . log ( yellow ( `Your global Angular CLI version (${ globalVersion } ) is greater than `
68
+ + `your local version (${ localVersion } ). The local Angular CLI version is used.` ) ) ;
69
+ }
70
+
25
71
// No error implies a projectLocalCli, which will load whatever
26
72
// version of ng-cli you have installed in a local package.json
27
73
cli = require ( projectLocalCli ) ;
@@ -36,7 +82,6 @@ resolve('angular-cli', { basedir: process.cwd() },
36
82
inputStream : process . stdin ,
37
83
outputStream : process . stdout
38
84
} ) . then ( function ( result ) {
39
- var exitCode = typeof result === 'object' ? result . exitCode : result ;
40
- process . exit ( exitCode ) ;
85
+ process . exit ( typeof result === 'object' ? result . exitCode : result ) ;
41
86
} ) ;
42
87
} ) ;
0 commit comments