admin-fe/build/check-versions.js
Haelwenn (lanodan) Monnier 57a996e2ab Drop chalk, got stuck to ESM
2022-08-28 16:16:51 +02:00

53 lines
1.2 KiB
JavaScript

'use strict'
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 + ': ' + mod.currentVersion + ' should be ' + mod.versionRequirement)
}
}
if (warnings.length) {
console.log('')
console.log('To use this template, you must update following to modules:')
console.log()
for (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
console.log(' ' + warning)
}
console.log()
process.exit(1)
}
}