Completed
Push — master ( 0c3f35...f9ae8d )
by Thomas
03:26
created

module.exports   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 5
rs 9.4285
1
'use strict'
2
3
const inquirer = require('inquirer')
4
inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'))
5
const Kits = require('../kits/Kits')
6
const Kit = require('../kits/Kit')
7
8
module.exports = function (kit, slug) {
9
  var questions = []
10
11
  if (!kit || !kit.length) {
12
    questions.push({
13
      type: 'autocomplete',
14
      name: 'kit',
15
      message: 'starter kit:',
16
      source: function (answers, input) {
17
        return new Promise(function(resolve) {
18
          Kits.list(function (list) {
19
            resolve(input && input.length ? list.filter(function(value){
20
              return value.indexOf(input) >= 0
21
            }) : list)
22
          })
23
        })
24
      },
25
      default: 'basic'
26
    })
27
  }
28
29
  // Slug is set
30
  if (!slug || !slug.length) {
31
    questions.push({
32
      type: 'input',
33
      name: 'slug',
34
      message: 'module name:',
35
      validate: function (value) {
36
        if (value.match(/^([a-z0-9-]+\/)?[a-z0-9-]+$/)) {
37
          return true
38
        }
39
40
        return 'Module name should only contain lowercase letters, numbers and dashes.'
41
      }
42
    })
43
  }
44
45
  // Need to ask for slug
46
  inquirer.prompt(questions).then(function (answers) {
47
    Kit.create(answers.kit || kit, answers.slug || slug)
48
  })
49
}
50