2017-12-14 16:07:10 +08:00
|
|
|
'use strict'
|
|
|
|
const chalk = require('chalk')
|
|
|
|
const semver = require('semver')
|
|
|
|
const packageConfig = require('../package.json')
|
|
|
|
const shell = require('shelljs')
|
|
|
|
|
2017-06-26 13:38:24 +08:00
|
|
|
function exec (cmd) {
|
|
|
|
return require('child_process').execSync(cmd).toString().trim()
|
|
|
|
}
|
|
|
|
|
2017-12-14 16:07:10 +08:00
|
|
|
const versionRequirements = [
|
2017-06-26 13:38:24 +08:00
|
|
|
{
|
|
|
|
name: 'node',
|
|
|
|
currentVersion: semver.clean(process.version),
|
|
|
|
versionRequirement: packageConfig.engines.node
|
2017-12-14 16:07:10 +08:00
|
|
|
}
|
2017-06-26 13:38:24 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
if (shell.which('npm')) {
|
|
|
|
versionRequirements.push({
|
|
|
|
name: 'npm',
|
|
|
|
currentVersion: exec('npm --version'),
|
|
|
|
versionRequirement: packageConfig.engines.npm
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function () {
|
2017-12-14 16:07:10 +08:00
|
|
|
const warnings = []
|
|
|
|
|
|
|
|
for (let i = 0; i < versionRequirements.length; i++) {
|
|
|
|
const mod = versionRequirements[i]
|
|
|
|
|
2017-06-26 13:38:24 +08:00
|
|
|
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()
|
2017-12-14 16:07:10 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < warnings.length; i++) {
|
|
|
|
const warning = warnings[i]
|
2017-06-26 13:38:24 +08:00
|
|
|
console.log(' ' + warning)
|
|
|
|
}
|
2017-12-14 16:07:10 +08:00
|
|
|
|
2017-06-26 13:38:24 +08:00
|
|
|
console.log()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|