Completed
Push — master ( 3f76fd...7863ed )
by Thomas
30s
created

Kits.list   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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