1+ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2+ !!! !!!
3+ !!! This file is special in that it must be able to execute with wrong Node version !!!
4+ !!! or even when node_modules are missing. !!!
5+ !!! !!!
6+ !!! Do not depend on Node4+ features or presence of npm packages here. !!!
7+ !!! !!!
8+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
9+
10+ 'use strict' ;
11+
112var exec = require ( 'child_process' ) . exec ;
2- var semver = require ( 'semver' ) ;
13+ var checkNodeModules ;
14+ var semver ;
315
4- var checkNodeModules = require ( './npm/check-node-modules.js' ) ;
16+
17+ var issues = [ ] ;
18+
19+ // coarse Node version check
20+ if ( process . version [ 1 ] !== '4' ) {
21+ issues . push ( "Angular 2 build currently requires Node 4. Use nvm to update your node version." ) ;
22+ }
23+
24+ try {
25+ semver = require ( 'semver' ) ;
26+ } catch ( e ) {
27+ issues . push ( "Looks like you are missing some npm dependencies. Run: npm install" ) ;
28+ }
29+
30+ // wrap in try/catch in case someone requires from within that file
31+ try {
32+ checkNodeModules = require ( './npm/check-node-modules.js' ) ;
33+ } catch ( e ) {
34+ issues . push ( "Looks like you are missing some npm dependencies. Run: npm install" ) ;
35+ throw e ;
36+ } finally {
37+ // print warnings and move on, the next steps will likely fail, but hey, we warned them.
38+ printWarning ( issues ) ;
39+ }
540
641
742function checkEnvironment ( reqs ) {
@@ -26,14 +61,20 @@ function checkEnvironment(reqs) {
2661 issues . push ( 'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install' ) ;
2762 }
2863
29- if ( issues . length ) {
30- console . warn ( Array ( 80 ) . join ( '!' ) ) ;
31- console . warn ( 'Your environment is not in a good shape. Following issues were found:' ) ;
32- issues . forEach ( function ( issue ) { console . warn ( ' - ' + issue ) } ) ;
33- console . warn ( Array ( 80 ) . join ( '!' ) ) ;
34- }
64+ printWarning ( issues ) ;
3565 } ) ;
3666}
3767
68+ function printWarning ( issues ) {
69+ if ( ! issues . length ) return ;
70+
71+ console . warn ( '' ) ;
72+ console . warn ( Array ( 110 ) . join ( '!' ) ) ;
73+ console . warn ( '!!! Your environment is not in a good shape. Following issues were found:' ) ;
74+ issues . forEach ( function ( issue ) { console . warn ( '!!! - ' + issue ) } ) ;
75+ console . warn ( Array ( 110 ) . join ( '!' ) ) ;
76+ console . warn ( '' ) ;
77+ }
78+
3879
3980module . exports = checkEnvironment ;
0 commit comments