Conditions | 8 |
Paths | 80 |
Total Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 'use strict' |
||
9 | module.exports = function (kit, slug) { |
||
10 | inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')) |
||
11 | var questions = [] |
||
12 | |||
13 | if (!kit && !slug && fs.existsSync('module.json')) { |
||
14 | output.warn('Are you sure you want to create a new module here? There already seems to be one in ' + |
||
15 | 'this directory. Instead, did you mean to type `inc run`?\n') |
||
16 | } |
||
17 | |||
18 | if (!kit || !kit.length) { |
||
19 | questions.push({ |
||
20 | type: 'autocomplete', |
||
21 | name: 'kit', |
||
22 | message: 'starter kit:', |
||
23 | source: function (answers, input) { |
||
24 | return new Promise(function (resolve) { |
||
25 | Kits.list(function (list) { |
||
26 | resolve(input && input.length ? list.filter(function (value) { |
||
27 | return value.indexOf(input) >= 0 |
||
28 | }) : list) |
||
29 | }) |
||
30 | }) |
||
31 | }, |
||
32 | default: 'basic' |
||
33 | }) |
||
34 | } |
||
35 | |||
36 | // Slug is set |
||
37 | if (!slug || !slug.length) { |
||
38 | questions.push({ |
||
39 | type: 'input', |
||
40 | name: 'slug', |
||
41 | message: 'module name:', |
||
42 | validate: function (value) { |
||
43 | if (value.match(/^([a-z0-9-]+\/)?[a-z0-9-]+$/)) { |
||
44 | return true |
||
45 | } |
||
46 | |||
47 | return 'Module name should only contain lowercase letters, numbers and dashes.' |
||
48 | } |
||
49 | }) |
||
50 | } |
||
51 | |||
52 | // Need to ask for slug |
||
53 | inquirer.prompt(questions).then(function (answers) { |
||
54 | Kit.create(answers.kit || kit, answers.slug || slug) |
||
55 | }) |
||
56 | } |
||
57 |