1 | "'use strict";
|
2 |
|
3 | var titleize = require('titleize');
|
4 | var chalk = require('chalk');
|
5 |
|
6 | var utils = require('./utils');
|
7 | var errorHandler = require('./errorHandler');
|
8 | var modulePromptsOptions = require('./promptModuleOptions');
|
9 |
|
10 | var _promptOptions = [];
|
11 | var _log;
|
12 |
|
13 | var promptOptionsApi = {};
|
14 |
|
15 | promptOptionsApi.setup = function(options) {
|
16 | _log = utils.getLogInstance(options);
|
17 |
|
18 | modulePromptsOptions.setup(options);
|
19 | }
|
20 |
|
21 | promptOptionsApi.getNewCommandPromptOptions = function() {
|
22 | _log.debug('');
|
23 | _log.debug('Getting prompt options data');
|
24 |
|
25 | return modulePromptsOptions
|
26 | .getOptions()
|
27 | .then(setPromptOptionsData)
|
28 | .catch(function(err) {
|
29 | errorHandler(err)
|
30 | })
|
31 | }
|
32 |
|
33 | function setPromptOptionsData(moduleList) {
|
34 | _promptOptions.push(getProjectNamePromptOptions());
|
35 | _promptOptions.push(getProjectAuthorPromptOptions());
|
36 | _promptOptions.push(getProjectDescriptionPromptOptions());
|
37 | _promptOptions.push(getIfProjectIsNodejsSite());
|
38 | _promptOptions.push(getCartridgeModulesPromptOptions(moduleList));
|
39 | _promptOptions.push(getUserConfirmCopyPromptOptions());
|
40 |
|
41 | return Promise.resolve(_promptOptions);
|
42 | }
|
43 |
|
44 | function getCartridgeModulesPromptOptions(moduleData) {
|
45 | return {
|
46 | type: 'checkbox',
|
47 | name: 'cartridgeModules',
|
48 | message: 'What modules would you like included?',
|
49 | choices: moduleData,
|
50 | filter: extractModuleNames
|
51 | }
|
52 | }
|
53 |
|
54 | function extractModuleNames(values) {
|
55 | var moduleNames = [];
|
56 |
|
57 | values.forEach(function (value) {
|
58 | var regex = /\s([^\s]+)\s.*/g;
|
59 | var matches = regex.exec(value);
|
60 | moduleNames.push(matches[1]);
|
61 | });
|
62 |
|
63 | return moduleNames;
|
64 | }
|
65 |
|
66 | function getIfProjectIsNodejsSite() {
|
67 | return {
|
68 | type: 'confirm',
|
69 | name: 'isNodejsSite',
|
70 | message: 'Is the project using Node.js server-side? (This will install a blank Node.js server setup)',
|
71 | default: false
|
72 | }
|
73 | }
|
74 |
|
75 | function getProjectNamePromptOptions() {
|
76 | return {
|
77 | type: 'input',
|
78 | name: 'projectName',
|
79 | message: 'What is the project name?',
|
80 | validate: function(value) { return inputNotEmpty(value, 'Project Name'); },
|
81 | }
|
82 | }
|
83 |
|
84 | function getProjectAuthorPromptOptions() {
|
85 | return {
|
86 | type: 'input',
|
87 | name: 'projectAuthor',
|
88 | message: 'Who is the author of the project?',
|
89 | validate: function(value) { return inputNotEmpty(value, 'Author'); },
|
90 | filter: function(value) { return titleize(value); }
|
91 | }
|
92 | }
|
93 |
|
94 | function getProjectDescriptionPromptOptions() {
|
95 | return {
|
96 | type: 'input',
|
97 | name: 'projectDescription',
|
98 | message: 'What is the project description?',
|
99 | default: function () { return ''; }
|
100 | }
|
101 | }
|
102 |
|
103 | function getUserConfirmCopyPromptOptions() {
|
104 | return {
|
105 | type: 'confirm',
|
106 | name: 'isOkToCopyFiles',
|
107 | message: 'Ready to start setup! Press enter to confirm',
|
108 | default: true
|
109 | }
|
110 | }
|
111 |
|
112 | function inputNotEmpty(value, fieldName) {
|
113 | var isValid = (value !== '');
|
114 |
|
115 | return (isValid) ? true : fieldName + ' cannot be empty' ;
|
116 | }
|
117 |
|
118 | module.exports = promptOptionsApi; |
\ | No newline at end of file |