Completed
Push — master ( 854a25...f9c943 )
by Thomas
32s
created

Kits.list   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
3
const util = require('../util')
4
const pkg = require('../../package.json')
5
6
const unirest = require('unirest')
7
8
const Kits = {}
9
10
Kits.list = function (callback) {
11
  var stopSpinner = util.output.wait('Loading available starter kits')
12
  unirest.get('https://api.github.com/search/repositories?q=user:includable-modules+in:name+starter-')
13
    .header('User-Agent', 'includable-cli v' + pkg.version)
14
    .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.items.map(function (item) {
22
        return item.name.replace(/^starter-/, '')
23
      }).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
      callback(list)
34
    })
35
}
36
37
module.exports = Kits
38