forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-environment.js
80 lines (61 loc) · 2.75 KB
/
check-environment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! !!!
!!! This file is special in that it must be able to execute with wrong Node version !!!
!!! or even when node_modules are missing. !!!
!!! !!!
!!! Do not depend on Node4+ features or presence of npm packages here. !!!
!!! !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
'use strict';
var exec = require('child_process').exec;
var checkNodeModules;
var semver;
var issues = [];
// coarse Node version check
if (process.version[1] !== '4') {
issues.push("Angular 2 build currently requires Node 4. Use nvm to update your node version.");
}
try {
semver = require('semver');
} catch(e) {
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
}
// wrap in try/catch in case someone requires from within that file
try {
checkNodeModules = require('./npm/check-node-modules.js');
} catch(e) {
issues.push("Looks like you are missing some npm dependencies. Run: npm install");
throw e;
} finally {
// print warnings and move on, the next steps will likely fail, but hey, we warned them.
printWarning(issues);
}
function checkEnvironment(reqs) {
exec('npm --version', function(e, stdout) {
var foundNpmVersion = semver.clean(stdout);
var foundNodeVersion = process.version;
var issues = [];
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
issues.push('You are running unsupported node version. Found: ' + foundNodeVersion +
' Expected: ' + reqs.requiredNodeVersion + '. Use nvm to update your node version.');
}
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
issues.push('You are running unsupported npm version. Found: ' + foundNpmVersion +
' Expected: ' + reqs.requiredNpmVersion + '. Run: npm update -g npm');
}
if (!checkNodeModules()) {
issues.push('Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
}
printWarning(issues);
});
}
function printWarning(issues) {
if (!issues.length) return;
console.warn('');
console.warn(Array(110).join('!'));
console.warn('!!! Your environment is not in a good shape. Following issues were found:');
issues.forEach(function(issue) {console.warn('!!! - ' + issue)});
console.warn(Array(110).join('!'));
console.warn('');
}
module.exports = checkEnvironment;