提交 | 用户 | age
|
3ac5f2
|
1 |
'use strict' |
J |
2 |
const chalk = require('chalk') |
|
3 |
const semver = require('semver') |
|
4 |
const packageConfig = require('../package.json') |
|
5 |
const shell = require('shelljs') |
|
6 |
|
|
7 |
function exec (cmd) { |
|
8 |
return require('child_process').execSync(cmd).toString().trim() |
|
9 |
} |
|
10 |
|
|
11 |
const versionRequirements = [ |
|
12 |
{ |
|
13 |
name: 'node', |
|
14 |
currentVersion: semver.clean(process.version), |
|
15 |
versionRequirement: packageConfig.engines.node |
|
16 |
} |
|
17 |
] |
|
18 |
|
|
19 |
if (shell.which('npm')) { |
|
20 |
versionRequirements.push({ |
|
21 |
name: 'npm', |
|
22 |
currentVersion: exec('npm --version'), |
|
23 |
versionRequirement: packageConfig.engines.npm |
|
24 |
}) |
|
25 |
} |
|
26 |
|
|
27 |
module.exports = function () { |
|
28 |
const warnings = [] |
|
29 |
|
|
30 |
for (let i = 0; i < versionRequirements.length; i++) { |
|
31 |
const mod = versionRequirements[i] |
|
32 |
|
|
33 |
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { |
|
34 |
warnings.push(mod.name + ': ' + |
|
35 |
chalk.red(mod.currentVersion) + ' should be ' + |
|
36 |
chalk.green(mod.versionRequirement) |
|
37 |
) |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
if (warnings.length) { |
|
42 |
console.log('') |
|
43 |
console.log(chalk.yellow('To use this template, you must update following to modules:')) |
|
44 |
console.log() |
|
45 |
|
|
46 |
for (let i = 0; i < warnings.length; i++) { |
|
47 |
const warning = warnings[i] |
|
48 |
console.log(' ' + warning) |
|
49 |
} |
|
50 |
|
|
51 |
console.log() |
|
52 |
process.exit(1) |
|
53 |
} |
|
54 |
} |