2017-06-28 18:45:41 +08:00
|
|
|
var chalk = require('chalk')
|
|
|
|
var semver = require('semver')
|
2017-07-06 15:25:09 +08:00
|
|
|
var packageConfig = require('../../package.json')
|
2017-06-28 18:45:41 +08:00
|
|
|
var shell = require('shelljs')
|
|
|
|
function exec (cmd) {
|
|
|
|
return require('child_process').execSync(cmd).toString().trim()
|
|
|
|
}
|
|
|
|
|
|
|
|
var versionRequirements = [
|
|
|
|
{
|
|
|
|
name: 'node',
|
|
|
|
currentVersion: semver.clean(process.version),
|
|
|
|
versionRequirement: packageConfig.engines.node
|
2017-06-29 02:26:07 +08:00
|
|
|
}
|
2017-06-28 18:45:41 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
if (shell.which('npm')) {
|
|
|
|
versionRequirements.push({
|
|
|
|
name: 'npm',
|
|
|
|
currentVersion: exec('npm --version'),
|
|
|
|
versionRequirement: packageConfig.engines.npm
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function () {
|
|
|
|
var warnings = []
|
|
|
|
for (var i = 0; i < versionRequirements.length; i++) {
|
|
|
|
var mod = versionRequirements[i]
|
|
|
|
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
|
|
|
|
warnings.push(mod.name + ': ' +
|
|
|
|
chalk.red(mod.currentVersion) + ' should be ' +
|
|
|
|
chalk.green(mod.versionRequirement)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (warnings.length) {
|
|
|
|
console.log('')
|
|
|
|
console.log(chalk.yellow('To use this template, you must update following to modules:'))
|
|
|
|
console.log()
|
|
|
|
for (var i = 0; i < warnings.length; i++) {
|
|
|
|
var warning = warnings[i]
|
|
|
|
console.log(' ' + warning)
|
|
|
|
}
|
|
|
|
console.log()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|