lib/kits/Kits.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 3

Size

Lines of Code 36
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 9
c 2
b 0
f 0
nc 4
mnd 1
bc 7
fnc 3
dl 0
loc 36
rs 10
bpm 2.3333
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B Kits.list 0 28 2
1
const util = require('../util')
2
3
const Kits = {
4
  cache: []
5
}
6
7
Kits.list = function (callback) {
8
  if (Kits.cache.length) {
9
    callback(Kits.cache)
10
    return
11
  }
12
13
  var stopSpinner = util.output.wait('Loading available starter kits')
14
  util.request('kits/short').end(function (response) {
15
    if (response.error || !response.body) {
16
      stopSpinner(response.error)
17
      process.exit()
18
    }
19
20
    stopSpinner()
21
    var list = response.body.data.sort(function (a, b) {
22
      if (a === 'basic') {
23
        return -1
24
      }
25
      if (b === 'basic') {
26
        return 1
27
      }
28
      return a > b ? 1 : -1
29
    })
30
31
    Kits.cache = list
32
    callback(list)
33
  })
34
}
35
36
module.exports = Kits
37