2018-06-07 14:59:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
* Author: lengleng (wangiegie@gmail.com)
|
|
|
|
*/
|
|
|
|
|
2018-03-04 13:49:35 +08:00
|
|
|
'use strict'
|
|
|
|
const chalk = require('chalk')
|
|
|
|
const semver = require('semver')
|
|
|
|
const packageConfig = require('../package.json')
|
|
|
|
const shell = require('shelljs')
|
|
|
|
|
|
|
|
function exec(cmd) {
|
2017-12-14 09:24:24 +08:00
|
|
|
return require('child_process').execSync(cmd).toString().trim()
|
2017-11-02 14:41:37 +08:00
|
|
|
}
|
|
|
|
|
2018-03-04 13:49:35 +08:00
|
|
|
const versionRequirements = [
|
2017-12-14 09:24:24 +08:00
|
|
|
{
|
|
|
|
name: 'node',
|
|
|
|
currentVersion: semver.clean(process.version),
|
|
|
|
versionRequirement: packageConfig.engines.node
|
2018-03-04 13:49:35 +08:00
|
|
|
}
|
2017-11-02 14:41:37 +08:00
|
|
|
]
|
|
|
|
|
2017-12-14 09:24:24 +08:00
|
|
|
if (shell.which('npm')) {
|
|
|
|
versionRequirements.push({
|
|
|
|
name: 'npm',
|
|
|
|
currentVersion: exec('npm --version'),
|
|
|
|
versionRequirement: packageConfig.engines.npm
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:41:37 +08:00
|
|
|
module.exports = function () {
|
2018-03-04 13:49:35 +08:00
|
|
|
const warnings = []
|
|
|
|
|
|
|
|
for (let i = 0; i < versionRequirements.length; i++) {
|
|
|
|
const mod = versionRequirements[i]
|
|
|
|
|
2017-12-14 09:24:24 +08:00
|
|
|
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
|
|
|
|
warnings.push(mod.name + ': ' +
|
|
|
|
chalk.red(mod.currentVersion) + ' should be ' +
|
|
|
|
chalk.green(mod.versionRequirement)
|
|
|
|
)
|
2017-11-02 14:41:37 +08:00
|
|
|
}
|
2017-12-14 09:24:24 +08:00
|
|
|
}
|
2017-11-02 14:41:37 +08:00
|
|
|
|
2017-12-14 09:24:24 +08:00
|
|
|
if (warnings.length) {
|
|
|
|
console.log('')
|
|
|
|
console.log(chalk.yellow('To use this template, you must update following to modules:'))
|
|
|
|
console.log()
|
2018-03-04 13:49:35 +08:00
|
|
|
|
|
|
|
for (let i = 0; i < warnings.length; i++) {
|
|
|
|
const warning = warnings[i]
|
2017-12-14 09:24:24 +08:00
|
|
|
console.log(' ' + warning)
|
2017-11-02 14:41:37 +08:00
|
|
|
}
|
2018-03-04 13:49:35 +08:00
|
|
|
|
2017-12-14 09:24:24 +08:00
|
|
|
console.log()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2018-06-07 14:59:05 +08:00
|
|
|
}
|