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

build/check-versions.js   A

Complexity

Total Complexity 7
Complexity/F 3.5

Size

Lines of Code 54
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
dl 0
loc 54
rs 10
wmc 7
mnd 2
bc 7
fnc 2
bpm 3.5
cpm 3.5
noi 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
B module.exports 0 28 5
A check-versions.js ➔ exec 0 3 1
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