spyne-cli 0.6.7 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +90 -38
  3. package/index.js +123 -21
  4. package/package.json +24 -6
  5. package/src/cli/args.js +197 -0
  6. package/src/cli/render.js +184 -0
  7. package/src/core/create-app.js +232 -0
  8. package/src/core/generate-module.js +146 -0
  9. package/src/registry.js +174 -0
  10. package/src/spyne-file-prompt.js +77 -30
  11. package/src/templates/generate-prompt-input-fields.js +1 -1
  12. package/src/ui.js +5 -1
  13. package/lib/ansi.js +0 -116
  14. package/lib/combos.js +0 -75
  15. package/lib/completer.js +0 -52
  16. package/lib/interpolate.js +0 -266
  17. package/lib/keypress.js +0 -243
  18. package/lib/placeholder.js +0 -63
  19. package/lib/prompt.js +0 -485
  20. package/lib/prompts/autocomplete.js +0 -113
  21. package/lib/prompts/basicauth.js +0 -41
  22. package/lib/prompts/confirm.js +0 -13
  23. package/lib/prompts/editable.js +0 -136
  24. package/lib/prompts/form.js +0 -196
  25. package/lib/prompts/index.js +0 -28
  26. package/lib/prompts/input.js +0 -55
  27. package/lib/prompts/invisible.js +0 -11
  28. package/lib/prompts/list.js +0 -36
  29. package/lib/prompts/multiselect.js +0 -11
  30. package/lib/prompts/numeral.js +0 -1
  31. package/lib/prompts/password.js +0 -18
  32. package/lib/prompts/quiz.js +0 -37
  33. package/lib/prompts/scale.js +0 -237
  34. package/lib/prompts/select.js +0 -139
  35. package/lib/prompts/snippet.js +0 -185
  36. package/lib/prompts/sort.js +0 -37
  37. package/lib/prompts/survey.js +0 -163
  38. package/lib/prompts/text.js +0 -1
  39. package/lib/prompts/toggle.js +0 -109
  40. package/lib/render.js +0 -33
  41. package/lib/roles.js +0 -46
  42. package/lib/state.js +0 -69
  43. package/lib/styles.js +0 -144
  44. package/lib/symbols.js +0 -66
  45. package/lib/theme.js +0 -11
  46. package/lib/timer.js +0 -38
  47. package/lib/types/array.js +0 -658
  48. package/lib/types/auth.js +0 -29
  49. package/lib/types/boolean.js +0 -88
  50. package/lib/types/index.js +0 -7
  51. package/lib/types/number.js +0 -86
  52. package/lib/types/string.js +0 -185
  53. package/lib/utils.js +0 -268
  54. package/mocha.conf.cjs +0 -16
  55. package/src/app/channels/.gitkeep +0 -0
  56. package/src/app/channels/channel-custom.js +0 -1
  57. package/src/app/components/.gitkeep +0 -0
  58. package/src/app/traits/.gitkeep +0 -0
  59. package/src/hello-world-app-source/README.md +0 -15
  60. package/src/hello-world-app-source/apache-htaccess +0 -20
  61. package/src/hello-world-app-source/karma.conf.js +0 -75
  62. package/src/hello-world-app-source/package.json +0 -50
  63. package/src/hello-world-app-source/src/app/app-view.js +0 -38
  64. package/src/hello-world-app-source/src/app/channels/.gitkeep +0 -0
  65. package/src/hello-world-app-source/src/app/components/.gitkeep +0 -0
  66. package/src/hello-world-app-source/src/app/traits/.gitkeep +0 -0
  67. package/src/hello-world-app-source/src/index.js +0 -16
  68. package/src/hello-world-app-source/src/index.tmpl.html +0 -12
  69. package/src/hello-world-app-source/src/scss/01-vendors/normalize.css +0 -349
  70. package/src/hello-world-app-source/src/scss/02-variables/mixins.scss +0 -0
  71. package/src/hello-world-app-source/src/scss/03-components/.gitkeep +0 -0
  72. package/src/hello-world-app-source/src/scss/main.scss +0 -15
  73. package/src/hello-world-app-source/src/static/data/.gitkeep +0 -0
  74. package/src/hello-world-app-source/src/static/fonts/.gitkeep +0 -0
  75. package/src/hello-world-app-source/src/static/imgs/.gitkeep +0 -0
  76. package/src/hello-world-app-source/src/tests/unit-tests/index.test.js +0 -10
  77. package/src/hello-world-app-source/webpack.config.js +0 -178
  78. package/src/spyne-app-create.js +0 -209
  79. package/src/spyne-app-creator.js +0 -119
  80. package/src/spyne-starter-app-create.js +0 -147
  81. package/tests/create-spyne-app.test.js +0 -63
  82. package/tests/generate-file-prompt.test.js +0 -45
  83. package/tests/generate-file-string.test.js +0 -66
  84. package/tests/generate-prompt-input-fields-methods.test.js +0 -177
  85. package/tests/generate-prompt-input-fields.test.js +0 -179
  86. package/tests/generate-prompt-input-object.test.js +0 -39
  87. package/tests/generate-prompt-output.test.js +0 -58
  88. package/tests/index.test.js +0 -11
  89. package/tests/mocks/answers.js +0 -33
  90. package/tests/mocks/answers.json +0 -33
  91. package/tests/mocks/enquirer-data.js +0 -411
  92. package/tests/mocks/enquirer-data.json +0 -409
  93. package/tests/utils/file-utils.test.js +0 -84
@@ -1,136 +0,0 @@
1
- 'use strict';
2
-
3
- const Select = require('./select');
4
- const Form = require('./form');
5
- const form = Form.prototype;
6
-
7
- class Editable extends Select {
8
- constructor(options) {
9
- super({ ...options, multiple: true });
10
- this.align = [this.options.align, 'left'].find(v => v != null);
11
- this.emptyError = '';
12
- this.values = {};
13
- }
14
-
15
- dispatch(char, key) {
16
- let choice = this.focused;
17
- let parent = choice.parent || {};
18
- if (!choice.editable && !parent.editable) {
19
- if (char === 'a' || char === 'i') return super[char]();
20
- }
21
- return form.dispatch.call(this, char, key);
22
- }
23
-
24
- append(char, key) {
25
- return form.append.call(this, char, key);
26
- }
27
-
28
- delete(char, key) {
29
- return form.delete.call(this, char, key);
30
- }
31
-
32
- space(char) {
33
- return this.focused.editable ? this.append(char) : super.space();
34
- }
35
-
36
- number(char) {
37
- return this.focused.editable ? this.append(char) : super.number(char);
38
- }
39
-
40
- next() {
41
- return this.focused.editable ? form.next.call(this) : super.next();
42
- }
43
-
44
- prev() {
45
- return this.focused.editable ? form.prev.call(this) : super.prev();
46
- }
47
-
48
- async indicator(choice, i) {
49
- let symbol = choice.indicator || '';
50
- let value = choice.editable ? symbol : super.indicator(choice, i);
51
- return await this.resolve(value, this.state, choice, i) || '';
52
- }
53
-
54
- indent(choice) {
55
- return choice.role === 'heading' ? '' : (choice.editable ? ' ' : ' ');
56
- }
57
-
58
- async renderChoice(choice, i) {
59
- choice.indent = '';
60
- if (choice.editable) return form.renderChoice.call(this, choice, i);
61
- return super.renderChoice(choice, i);
62
- }
63
-
64
- error() {
65
- return '';
66
- }
67
-
68
- footer() {
69
- return this.state.error;
70
- }
71
-
72
- async validate() {
73
- let result = true;
74
-
75
- for (let choice of this.choices) {
76
- if (typeof choice.validate !== 'function') {
77
- continue;
78
- }
79
-
80
- if (choice.role === 'heading') {
81
- continue;
82
- }
83
-
84
- let val = choice.parent ? this.value[choice.parent.name] : this.value;
85
-
86
- if (choice.editable) {
87
- val = choice.value === choice.name ? choice.initial || '' : choice.value;
88
- } else if (!this.isDisabled(choice)) {
89
- val = choice.enabled === true;
90
- }
91
-
92
- result = await choice.validate(val, this.state);
93
-
94
- if (result !== true) {
95
- break;
96
- }
97
- }
98
-
99
- if (result !== true) {
100
- this.state.error = typeof result === 'string' ? result : 'Invalid Input';
101
- }
102
-
103
- return result;
104
- }
105
-
106
- submit() {
107
- if (this.focused.newChoice === true) return super.submit();
108
- if (this.choices.some(ch => ch.newChoice)) {
109
- return this.alert();
110
- }
111
-
112
- this.value = {};
113
-
114
- for (let choice of this.choices) {
115
- let val = choice.parent ? this.value[choice.parent.name] : this.value;
116
-
117
- if (choice.role === 'heading') {
118
- this.value[choice.name] = {};
119
- continue;
120
- }
121
-
122
- if (choice.editable) {
123
- val[choice.name] = choice.value === choice.name
124
- ? (choice.initial || '')
125
- : choice.value;
126
-
127
- } else if (!this.isDisabled(choice)) {
128
- val[choice.name] = choice.enabled === true;
129
- }
130
- }
131
-
132
- return this.base.submit.call(this);
133
- }
134
- }
135
-
136
- module.exports = Editable;
@@ -1,196 +0,0 @@
1
- 'use strict';
2
-
3
- const colors = require('ansi-colors');
4
- const SelectPrompt = require('./select');
5
- const placeholder = require('../placeholder');
6
-
7
- class FormPrompt extends SelectPrompt {
8
- constructor(options) {
9
- super({ ...options, multiple: true });
10
- this.type = 'form';
11
- this.initial = this.options.initial;
12
- this.align = [this.options.align, 'right'].find(v => v != null);
13
- this.emptyError = '';
14
- this.values = {};
15
- }
16
-
17
- async reset(first) {
18
- await super.reset();
19
- if (first === true) this._index = this.index;
20
- this.index = this._index;
21
- this.values = {};
22
- this.choices.forEach(choice => choice.reset && choice.reset());
23
- return this.render();
24
- }
25
-
26
- dispatch(char) {
27
- return !!char && this.append(char);
28
- }
29
-
30
- append(char) {
31
- let choice = this.focused;
32
- if (!choice) return this.alert();
33
- let { cursor, input } = choice;
34
- choice.value = choice.input = input.slice(0, cursor) + char + input.slice(cursor);
35
- choice.cursor++;
36
- return this.render();
37
- }
38
-
39
- delete() {
40
- let choice = this.focused;
41
- if (!choice || choice.cursor <= 0) return this.alert();
42
- let { cursor, input } = choice;
43
- choice.value = choice.input = input.slice(0, cursor - 1) + input.slice(cursor);
44
- choice.cursor--;
45
- return this.render();
46
- }
47
-
48
- deleteForward() {
49
- let choice = this.focused;
50
- if (!choice) return this.alert();
51
- let { cursor, input } = choice;
52
- if (input[cursor] === void 0) return this.alert();
53
- let str = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
54
- choice.value = choice.input = str;
55
- return this.render();
56
- }
57
-
58
- right() {
59
- let choice = this.focused;
60
- if (!choice) return this.alert();
61
- if (choice.cursor >= choice.input.length) return this.alert();
62
- choice.cursor++;
63
- return this.render();
64
- }
65
-
66
- left() {
67
- let choice = this.focused;
68
- if (!choice) return this.alert();
69
- if (choice.cursor <= 0) return this.alert();
70
- choice.cursor--;
71
- return this.render();
72
- }
73
-
74
- space(ch, key) {
75
- return this.dispatch(ch, key);
76
- }
77
-
78
- number(ch, key) {
79
- return this.dispatch(ch, key);
80
- }
81
-
82
- next() {
83
- let ch = this.focused;
84
- if (!ch) return this.alert();
85
- let { initial, input } = ch;
86
- if (initial && initial.startsWith(input) && input !== initial) {
87
- ch.value = ch.input = initial;
88
- ch.cursor = ch.value.length;
89
- return this.render();
90
- }
91
- return super.next();
92
- }
93
-
94
- prev() {
95
- let ch = this.focused;
96
- if (!ch) return this.alert();
97
- if (ch.cursor === 0) return super.prev();
98
- ch.value = ch.input = '';
99
- ch.cursor = 0;
100
- return this.render();
101
- }
102
-
103
- separator() {
104
- return '';
105
- }
106
-
107
- format(value) {
108
- return !this.state.submitted ? super.format(value) : '';
109
- }
110
-
111
- pointer() {
112
- return '';
113
- }
114
-
115
- indicator(choice) {
116
- return choice.input ? '⦿' : '⊙';
117
- }
118
-
119
- async choiceSeparator(choice, i) {
120
- let sep = await this.resolve(choice.separator, this.state, choice, i) || ':';
121
- return sep ? ' ' + this.styles.disabled(sep) : '';
122
- }
123
-
124
- async renderChoice(choice, i) {
125
- await this.onChoice(choice, i);
126
-
127
- let { state, styles } = this;
128
- let { cursor, initial = '', name, hint, input = '' } = choice;
129
- let { muted, submitted, primary, danger } = styles;
130
-
131
- let help = hint;
132
- let focused = this.index === i;
133
- let validate = choice.validate || (() => true);
134
- let sep = await this.choiceSeparator(choice, i);
135
- let msg = choice.message;
136
-
137
- if (this.align === 'right') msg = msg.padStart(this.longest + 1, ' ');
138
- if (this.align === 'left') msg = msg.padEnd(this.longest + 1, ' ');
139
-
140
- // re-populate the form values (answers) object
141
- let value = this.values[name] = (input || initial);
142
- let color = input ? 'success' : 'dark';
143
-
144
- if ((await validate.call(choice, value, this.state)) !== true) {
145
- color = 'danger';
146
- }
147
-
148
- let style = styles[color];
149
- let indicator = style(await this.indicator(choice, i)) + (choice.pad || '');
150
-
151
- let indent = this.indent(choice);
152
- let line = () => [indent, indicator, msg + sep, input, help].filter(Boolean).join(' ');
153
-
154
- if (state.submitted) {
155
- msg = colors.unstyle(msg);
156
- input = submitted(input);
157
- help = '';
158
- return line();
159
- }
160
-
161
- if (choice.format) {
162
- input = await choice.format.call(this, input, choice, i);
163
- } else {
164
- let color = this.styles.muted;
165
- let options = { input, initial, pos: cursor, showCursor: focused, color };
166
- input = placeholder(this, options);
167
- }
168
-
169
- if (!this.isValue(input)) {
170
- input = this.styles.muted(this.symbols.ellipsis);
171
- }
172
-
173
- if (choice.result) {
174
- this.values[name] = await choice.result.call(this, value, choice, i);
175
- }
176
-
177
- if (focused) {
178
- msg = primary(msg);
179
- }
180
-
181
- if (choice.error) {
182
- input += (input ? ' ' : '') + danger(choice.error.trim());
183
- } else if (choice.hint) {
184
- input += (input ? ' ' : '') + muted(choice.hint.trim());
185
- }
186
-
187
- return line();
188
- }
189
-
190
- async submit() {
191
- this.value = this.values;
192
- return super.base.submit.call(this);
193
- }
194
- }
195
-
196
- module.exports = FormPrompt;
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- const utils = require('../utils');
4
-
5
- const define = (key, fn) => {
6
- utils.defineExport(exports, key, fn);
7
- utils.defineExport(exports, key.toLowerCase(), fn);
8
- };
9
-
10
- define('AutoComplete', () => require('./autocomplete'));
11
- define('BasicAuth', () => require('./basicauth'));
12
- define('Confirm', () => require('./confirm'));
13
- define('Editable', () => require('./editable'));
14
- define('Form', () => require('./form'));
15
- define('Input', () => require('./input'));
16
- define('Invisible', () => require('./invisible'));
17
- define('List', () => require('./list'));
18
- define('MultiSelect', () => require('./multiselect'));
19
- define('Numeral', () => require('./numeral'));
20
- define('Password', () => require('./password'));
21
- define('Scale', () => require('./scale'));
22
- define('Select', () => require('./select'));
23
- define('Snippet', () => require('./snippet'));
24
- define('Sort', () => require('./sort'));
25
- define('Survey', () => require('./survey'));
26
- define('Text', () => require('./text'));
27
- define('Toggle', () => require('./toggle'));
28
- define('Quiz', () => require('./quiz'));
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- const Prompt = require('../types/string');
4
- const completer = require('../completer');
5
-
6
- class Input extends Prompt {
7
- constructor(options) {
8
- super(options);
9
- let history = this.options.history;
10
- if (history && history.store) {
11
- let initial = history.values || this.initial;
12
- this.autosave = !!history.autosave;
13
- this.store = history.store;
14
- this.data = this.store.get('values') || { past: [], present: initial };
15
- this.initial = this.data.present || this.data.past[this.data.past.length - 1];
16
- }
17
- }
18
-
19
- completion(action) {
20
- if (!this.store) return this.alert();
21
- this.data = completer(action, this.data, this.input);
22
- if (!this.data.present) return this.alert();
23
- this.input = this.data.present;
24
- this.cursor = this.input.length;
25
- return this.render();
26
- }
27
-
28
- altUp() {
29
- return this.completion('prev');
30
- }
31
-
32
- altDown() {
33
- return this.completion('next');
34
- }
35
-
36
- prev() {
37
- this.save();
38
- return super.prev();
39
- }
40
-
41
- save() {
42
- if (!this.store) return;
43
- this.data = completer('save', this.data, this.input);
44
- this.store.set('values', this.data);
45
- }
46
-
47
- submit() {
48
- if (this.store && this.autosave === true) {
49
- this.save();
50
- }
51
- return super.submit();
52
- }
53
- }
54
-
55
- module.exports = Input;
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- const StringPrompt = require('../types/string');
4
-
5
- class InvisiblePrompt extends StringPrompt {
6
- format() {
7
- return '';
8
- }
9
- }
10
-
11
- module.exports = InvisiblePrompt;
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- const StringPrompt = require('../types/string');
4
-
5
- class ListPrompt extends StringPrompt {
6
- constructor(options = {}) {
7
- super(options);
8
- this.sep = this.options.separator || /, */;
9
- this.initial = options.initial || '';
10
- }
11
-
12
- split(input = this.value) {
13
- return input ? String(input).split(this.sep) : [];
14
- }
15
-
16
- format() {
17
- let style = this.state.submitted ? this.styles.primary : val => val;
18
- return this.list.map(style).join(', ');
19
- }
20
-
21
- async submit(value) {
22
- let result = this.state.error || await this.validate(this.list, this.state);
23
- if (result !== true) {
24
- this.state.error = result;
25
- return super.submit();
26
- }
27
- this.value = this.list;
28
- return super.submit();
29
- }
30
-
31
- get list() {
32
- return this.split();
33
- }
34
- }
35
-
36
- module.exports = ListPrompt;
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- const Select = require('./select');
4
-
5
- class MultiSelect extends Select {
6
- constructor(options) {
7
- super({ ...options, multiple: true });
8
- }
9
- }
10
-
11
- module.exports = MultiSelect;
@@ -1 +0,0 @@
1
- module.exports = require('../types/number');
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- const StringPrompt = require('../types/string');
4
-
5
- class PasswordPrompt extends StringPrompt {
6
- constructor(options) {
7
- super(options);
8
- this.cursorShow();
9
- }
10
-
11
- format(input = this.input) {
12
- if (!this.keypressed) return '';
13
- let color = this.state.submitted ? this.styles.primary : this.styles.muted;
14
- return color(this.symbols.asterisk.repeat(input.length));
15
- }
16
- }
17
-
18
- module.exports = PasswordPrompt;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- const SelectPrompt = require('./select');
4
-
5
- class Quiz extends SelectPrompt {
6
- constructor(options) {
7
- super(options);
8
- if (typeof this.options.correctChoice !== 'number' || this.options.correctChoice < 0) {
9
- throw new Error('Please specify the index of the correct answer from the list of choices');
10
- }
11
- }
12
-
13
- async toChoices(value, parent) {
14
- let choices = await super.toChoices(value, parent);
15
- if (choices.length < 2) {
16
- throw new Error('Please give at least two choices to the user');
17
- }
18
- if (this.options.correctChoice > choices.length) {
19
- throw new Error('Please specify the index of the correct answer from the list of choices');
20
- }
21
- return choices;
22
- }
23
-
24
- check(state) {
25
- return state.index === this.options.correctChoice;
26
- }
27
-
28
- async result(selected) {
29
- return {
30
- selectedAnswer: selected,
31
- correctAnswer: this.options.choices[this.options.correctChoice].value,
32
- correct: await this.check(this.state)
33
- };
34
- }
35
- }
36
-
37
- module.exports = Quiz;