Completed
Branch vue-dev (285fcd)
by Seth
41s
created

check-versions.js ➔ exec   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
'use strict'
2
const chalk = require('chalk')
3
const semver = require('semver')
4
const packageConfig = require('../package.json')
5
const shell = require('shelljs')
6
7
function exec (cmd) {
8
  return require('child_process').execSync(cmd).toString().trim()
9
}
10
11
const versionRequirements = [
12
  {
13
    name: 'node',
14
    currentVersion: semver.clean(process.version),
15
    versionRequirement: packageConfig.engines.node
16
  }
17
]
18
19
if (shell.which('npm')) {
20
  versionRequirements.push({
21
    name: 'npm',
22
    currentVersion: exec('npm --version'),
23
    versionRequirement: packageConfig.engines.npm
24
  })
25
}
26
27
module.exports = function () {
28
  const warnings = []
29
30
  for (let i = 0; i < versionRequirements.length; i++) {
31
    const mod = versionRequirements[i]
32
33
    if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34
      warnings.push(mod.name + ': ' +
35
        chalk.red(mod.currentVersion) + ' should be ' +
36
        chalk.green(mod.versionRequirement)
37
      )
38
    }
39
  }
40
41
  if (warnings.length) {
42
    console.log('')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
43
    console.log(chalk.yellow('To use this template, you must update following to modules:'))
44
    console.log()
45
46
    for (let i = 0; i < warnings.length; i++) {
47
      const warning = warnings[i]
48
      console.log('  ' + warning)
49
    }
50
51
    console.log()
52
    process.exit(1)
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
53
  }
54
}
55