admin-fe/build/check-versions.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

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