Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
feat: check node.js and npm required versions
Browse files Browse the repository at this point in the history
  • Loading branch information
allanfreitas committed Sep 3, 2016
1 parent 25d2edd commit 954f3e8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"randomstring": "^1.1.3",
"rimraf": "^2.5.0",
"shelljs": "^0.5.3",
"yargs": "^3.31.0"
"yargs": "^3.31.0",
"semver": "^5.3.0"
},
"devDependencies": {},
"repository": {
Expand Down
48 changes: 48 additions & 0 deletions src/Commands/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

/**
* adonis-cli
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const colors = require('colors')
const execSync = require('child_process').execSync
const semver = require('semver')

const requiredNodeVersion = '>=4.0.0'
const requiredNpmVersion = '>=3.0.0'

module.exports = function (argv) {
const nodejsVersion = process.version.replace('v', '')
const npmVersion = execSync('npm -v', {input: 'string', 'encoding': 'utf-8'})

console.log('-----------AdonisJS requirements check--------------')
console.log(`${colors.green('AdonisJS needs Node.JS >= 4.0.0 and npm >= 3.0.0\n')}`)
console.log(`${colors.green('verifying node.js and npm current installed versions...')}`)

console.log('\nYour current Node.JS version: ' + colors.yellow(nodejsVersion))
console.log('Your current npm version: ' + colors.yellow(npmVersion))

if (!semver.satisfies(nodejsVersion, requiredNodeVersion)) {
console.log(`${colors.red('\nYour current Node.js version does not met AdonisJS requirements.')}`)
console.log(`${colors.red('Please update your Node.JS version before continue.')}`)
return
}

if (!semver.satisfies(npmVersion, requiredNpmVersion)) {
console.log(`${colors.red('\nYour Current npm version does not met AdonisJS requirements.')}`)
console.log(`${colors.red('Please update your npm version with this command: ')}`)
console.log(`${colors.yellow('npm install -g npm')}`)
return
}

if (!semver.satisfies(nodejsVersion, requiredNodeVersion) || !semver.satisfies(npmVersion, requiredNpmVersion)) {
return false
}

return true
}
3 changes: 2 additions & 1 deletion src/Commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

module.exports = {
new: require('./new'),
fix: require('./fix')
fix: require('./fix'),
check: require('./check')
}

0 comments on commit 954f3e8

Please sign in to comment.