You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.3 KiB
63 lines
1.3 KiB
5 years ago
|
'use strict'
|
||
|
const chalk = require('chalk')
|
||
|
const semver = require('semver')
|
||
|
const packageConfig = require('../package.json')
|
||
|
const shell = require('shelljs')
|
||
|
|
||
|
function exec(cmd) {
|
||
|
return require('child_process')
|
||
|
.execSync(cmd)
|
||
|
.toString()
|
||
|
.trim()
|
||
|
}
|
||
|
|
||
|
const versionRequirements = [
|
||
|
{
|
||
|
name: 'node',
|
||
|
currentVersion: semver.clean(process.version),
|
||
|
versionRequirement: packageConfig.engines.node
|
||
|
}
|
||
|
]
|
||
|
|
||
|
if (shell.which('npm')) {
|
||
|
versionRequirements.push({
|
||
|
name: 'npm',
|
||
|
currentVersion: exec('npm --version'),
|
||
|
versionRequirement: packageConfig.engines.npm
|
||
|
})
|
||
|
}
|
||
|
|
||
|
module.exports = function() {
|
||
|
const warnings = []
|
||
|
|
||
|
for (let i = 0; i < versionRequirements.length; i++) {
|
||
|
const 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:'
|
||
|
)
|
||
|
)
|
||
|
|
||
|
for (let i = 0; i < warnings.length; i++) {
|
||
|
const warning = warnings[i]
|
||
|
console.log(' ' + warning)
|
||
|
}
|
||
|
|
||
|
process.exit(1)
|
||
|
}
|
||
|
}
|