@@ -7,6 +7,33 @@ process.title = 'angular-cli';
77const resolve = require ( 'resolve' ) ;
88const packageJson = require ( '../package.json' ) ;
99const 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+ }
1037
1138
1239resolve ( 'angular-cli' , { basedir : process . cwd ( ) } ,
@@ -22,6 +49,25 @@ resolve('angular-cli', { basedir: process.cwd() },
2249 // Verify that package's version.
2350 Version . assertPostWebpackVersion ( ) ;
2451
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+
2571 // No error implies a projectLocalCli, which will load whatever
2672 // version of ng-cli you have installed in a local package.json
2773 cli = require ( projectLocalCli ) ;
@@ -36,7 +82,6 @@ resolve('angular-cli', { basedir: process.cwd() },
3682 inputStream : process . stdin ,
3783 outputStream : process . stdout
3884 } ) . 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 ) ;
4186 } ) ;
4287 } ) ;
0 commit comments