spyne-cli 0.3.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 (70) hide show
  1. package/README.md +3 -0
  2. package/index-cli.js +56 -0
  3. package/index.js +14 -0
  4. package/lib/ansi.js +116 -0
  5. package/lib/combos.js +75 -0
  6. package/lib/completer.js +52 -0
  7. package/lib/interpolate.js +266 -0
  8. package/lib/keypress.js +243 -0
  9. package/lib/placeholder.js +63 -0
  10. package/lib/prompt.js +485 -0
  11. package/lib/prompts/autocomplete.js +113 -0
  12. package/lib/prompts/basicauth.js +41 -0
  13. package/lib/prompts/confirm.js +13 -0
  14. package/lib/prompts/editable.js +136 -0
  15. package/lib/prompts/form.js +196 -0
  16. package/lib/prompts/index.js +28 -0
  17. package/lib/prompts/input.js +55 -0
  18. package/lib/prompts/invisible.js +11 -0
  19. package/lib/prompts/list.js +36 -0
  20. package/lib/prompts/multiselect.js +11 -0
  21. package/lib/prompts/numeral.js +1 -0
  22. package/lib/prompts/password.js +18 -0
  23. package/lib/prompts/quiz.js +37 -0
  24. package/lib/prompts/scale.js +237 -0
  25. package/lib/prompts/select.js +139 -0
  26. package/lib/prompts/snippet.js +185 -0
  27. package/lib/prompts/sort.js +37 -0
  28. package/lib/prompts/survey.js +163 -0
  29. package/lib/prompts/text.js +1 -0
  30. package/lib/prompts/toggle.js +109 -0
  31. package/lib/render.js +33 -0
  32. package/lib/roles.js +46 -0
  33. package/lib/state.js +69 -0
  34. package/lib/styles.js +144 -0
  35. package/lib/symbols.js +66 -0
  36. package/lib/theme.js +11 -0
  37. package/lib/timer.js +38 -0
  38. package/lib/types/array.js +658 -0
  39. package/lib/types/auth.js +29 -0
  40. package/lib/types/boolean.js +88 -0
  41. package/lib/types/index.js +7 -0
  42. package/lib/types/number.js +86 -0
  43. package/lib/types/string.js +185 -0
  44. package/lib/utils.js +268 -0
  45. package/package.json +45 -0
  46. package/src/app/channels/.gitkeep +0 -0
  47. package/src/app/components/.gitkeep +0 -0
  48. package/src/app/traits/.gitkeep +0 -0
  49. package/src/spyne-file-prompt.js +63 -0
  50. package/src/spyne-template-prompts.js +171 -0
  51. package/src/templates/generate-file-string.js +131 -0
  52. package/src/templates/generate-prompt-input-fields.js +256 -0
  53. package/src/templates/generate-prompt-input-object.js +46 -0
  54. package/src/templates/generate-prompt-output.js +109 -0
  55. package/src/ui.js +16 -0
  56. package/src/utils/color-utils.js +36 -0
  57. package/src/utils/error-logger.js +15 -0
  58. package/src/utils/file-utils.js +69 -0
  59. package/tests/generate-file-prompt.test.js +47 -0
  60. package/tests/generate-file-string.test.js +68 -0
  61. package/tests/generate-prompt-input-fields-methods.test.js +178 -0
  62. package/tests/generate-prompt-input-fields.test.js +181 -0
  63. package/tests/generate-prompt-input-object.test.js +41 -0
  64. package/tests/generate-prompt-output.test.js +60 -0
  65. package/tests/index.test.js +13 -0
  66. package/tests/mocks/answers.js +33 -0
  67. package/tests/mocks/answers.json +33 -0
  68. package/tests/mocks/enquirer-data.js +411 -0
  69. package/tests/mocks/enquirer-data.json +409 -0
  70. package/tests/utils/file-utils.test.js +70 -0
@@ -0,0 +1,181 @@
1
+ import chai from 'chai';
2
+ const {expect, assert} = chai;
3
+ import PromptInputField from '../src/templates/generate-prompt-input-fields.js';
4
+
5
+ import {MockData} from './mocks/enquirer-data.js';
6
+
7
+ const sani = (str)=>{
8
+ const len = String(str).length;
9
+ //String(str).replace(/^(\\.+\d{2}\w)(Enter.*name)(\\.*)$/, "$2")
10
+ return String(str).substr(5, len-10);
11
+ }
12
+
13
+
14
+ describe('should create all necessary prompt input fields', () => {
15
+
16
+ it('PromptInputField should exist', () => {
17
+ expect(PromptInputField).to.exist;
18
+ });
19
+
20
+
21
+
22
+ describe('should generate basic input fields', ()=>{
23
+ let inputType = "fileName";
24
+ let fileType = "ViewStream";
25
+
26
+ it('should generate type field', ()=>{
27
+ const fieldType = 'type';
28
+ const type = new PromptInputField(inputType, fileType, fieldType).field;
29
+ //console.log('type is ',{type})
30
+ expect(type).to.equal('input');
31
+ })
32
+
33
+
34
+ it('should generate name field', ()=>{
35
+ const fieldType = "name";
36
+ const name = new PromptInputField(inputType, fileType, fieldType).field;
37
+ expect(name).to.equal(inputType);
38
+
39
+ })
40
+
41
+ it('should generate input format ',()=>{
42
+ const fieldType = 'format';
43
+ const format = new PromptInputField(inputType, fileType, fieldType).field;
44
+ //console.log('format is ',{format}, format('colored output'))
45
+ expect(format).to.be.an('function');
46
+ })
47
+
48
+ it('should parse input and remove color',()=>{
49
+ const fieldType = 'result';
50
+ const format = new PromptInputField(inputType, fileType, 'format').field;
51
+ const result = new PromptInputField(inputType, fileType, fieldType).field;
52
+ const formatStr = format('foo');
53
+ const parsedFormatStr = result(formatStr);
54
+ //console.log('field is ',{format,result, formatStr, parsedFormatStr})
55
+ expect(parsedFormatStr).to.equal('foo');
56
+
57
+ })
58
+
59
+ it('should generate choices for selectFileType ',()=>{
60
+ const fieldType = 'choices';
61
+ const format = new PromptInputField('selectFileType', 'Channel', fieldType).field;
62
+ const result = new PromptInputField(inputType, fileType, 'result').field;
63
+
64
+ expect(result(format)).to.equal("ViewStream,DomElement,Channel,SpyneTrait");
65
+ })
66
+
67
+ })
68
+
69
+ describe('it should generate input messages for each input and file types ',()=>{
70
+ const fieldType = "message";
71
+
72
+
73
+ it('should generate messages for filename ',()=>{
74
+ const inputType = 'fileName';
75
+
76
+
77
+ const expectedStr = (_fileType)=>`Enter the ${_fileType} file name`
78
+
79
+ const viewsStreamMsg = new PromptInputField(inputType, 'ViewStream', fieldType).field;
80
+ const domElementMsg = new PromptInputField(inputType, 'DomElement', fieldType).field;
81
+ const channelMsg = new PromptInputField(inputType, 'Channel', fieldType).field;
82
+ const spyneTraitMsg = new PromptInputField(inputType, 'SpyneTrait', fieldType).field;
83
+
84
+
85
+ /* console.log('view stream msg is ', sani(viewsStreamMsg))
86
+ console.log('view stream msg is ',{domElementMsg})
87
+ console.log('view stream msg is ',{channelMsg})
88
+ console.log('view stream msg is ',{spyneTraitMsg})
89
+ */
90
+ expect(sani(viewsStreamMsg)).to.equal(expectedStr('ViewStream'))
91
+ expect(sani(domElementMsg)).to.equal(expectedStr('DomElement'))
92
+ expect(sani(channelMsg)).to.equal(expectedStr('Channel'))
93
+ expect(sani(spyneTraitMsg)).to.equal(expectedStr('SpyneTrait'))
94
+ })
95
+
96
+
97
+
98
+
99
+ it('should generate messages for className', ()=>{
100
+ const inputType = 'className';
101
+ const expectedStr = (_fileType)=>`Enter the ${_fileType} class name`
102
+
103
+ const viewsStreamMsg = new PromptInputField(inputType, 'ViewStream', fieldType).field;
104
+ const domElementMsg = new PromptInputField(inputType, 'DomElement', fieldType).field;
105
+ const channelMsg = new PromptInputField(inputType, 'Channel', fieldType).field;
106
+ const spyneTraitMsg = new PromptInputField(inputType, 'SpyneTrait', fieldType).field;
107
+
108
+ /* console.log('view stream msg is ',sani(viewsStreamMsg))
109
+ console.log('view stream msg is ',{domElementMsg})
110
+ console.log('view stream msg is ',{channelMsg})
111
+ console.log('view stream msg is ',{spyneTraitMsg})*/
112
+
113
+ expect(sani(viewsStreamMsg)).to.equal(expectedStr('ViewStream'))
114
+ expect(sani(domElementMsg)).to.equal(expectedStr('DomElement'))
115
+ expect(sani(channelMsg)).to.equal(expectedStr('Channel'))
116
+ expect(sani(spyneTraitMsg)).to.equal(expectedStr('SpyneTrait'))
117
+
118
+ return true;
119
+
120
+ })
121
+
122
+ it('should generate messages for fileDirectory', ()=>{
123
+ const inputType = 'fileDirectory';
124
+ const expectedStr = (_fileType)=>`Enter where you would like to save the ${_fileType} file`
125
+
126
+ const viewsStreamMsg = new PromptInputField(inputType, 'ViewStream', fieldType).field;
127
+ const domElementMsg = new PromptInputField(inputType, 'DomElement', fieldType).field;
128
+ const channelMsg = new PromptInputField(inputType, 'Channel', fieldType).field;
129
+ const spyneTraitMsg = new PromptInputField(inputType, 'SpyneTrait', fieldType).field;
130
+
131
+ /* console.log('view stream msg is ',{viewsStreamMsg})
132
+ console.log('view stream msg is ',{domElementMsg})
133
+ console.log('view stream msg is ',{channelMsg})
134
+ console.log('view stream msg is ',{spyneTraitMsg})*/
135
+
136
+ expect(sani(viewsStreamMsg)).to.equal(expectedStr('ViewStream'))
137
+ expect(sani(domElementMsg)).to.equal(expectedStr('DomElement'))
138
+ expect(sani(channelMsg)).to.equal(expectedStr('Channel'))
139
+ expect(sani(spyneTraitMsg)).to.equal(expectedStr('SpyneTrait'))
140
+
141
+ return true;
142
+
143
+ })
144
+
145
+ it('should generate message for channelName', ()=>{
146
+ MockData.enquirer.answers.className="MyChannel"
147
+ const inputType = 'channelName';
148
+ const expectedStr = `Enter the channel name for MyChannel`
149
+ const channelNameMsgFn = new PromptInputField(inputType, 'SpyneTrait', fieldType).field;
150
+ const channelNameMsg = channelNameMsgFn(MockData.enquirer);
151
+ //console.log('channelNameMsg stream msg is ',{channelNameMsg}, channelNameMsg(MockData))
152
+ expect(sani(channelNameMsg)).to.equal(expectedStr)
153
+ return true;
154
+
155
+ })
156
+
157
+
158
+ it('should generate message for methodPrefix$', ()=>{
159
+ const inputType = 'methodPrefix';
160
+ const expectedStr = `Enter the string to be prepended to all trait methods`
161
+ const spyneTraitMethodPrefix = new PromptInputField(inputType, 'SpyneTrait', fieldType).field;
162
+ //console.log('view stream msg is ',{spyneTraitMethodPrefix})
163
+ expect(sani(spyneTraitMethodPrefix)).to.equal(expectedStr)
164
+
165
+ })
166
+
167
+ it('should generate message for replayLastPayload', ()=>{
168
+ const inputType = 'replayLastPayload';
169
+ const expectedStr = `This property determines if new subscribers receive the previous payload`
170
+ const replayLastPayloadMsg = new PromptInputField(inputType, 'Channel', fieldType).field;
171
+ //console.log('view stream msg is ',{replayLastPayloadMsg})
172
+ expect(sani(replayLastPayloadMsg)).to.equal(expectedStr)
173
+ //return true;
174
+ })
175
+
176
+
177
+
178
+
179
+ })
180
+
181
+ });
@@ -0,0 +1,41 @@
1
+ import chai from 'chai';
2
+ const {expect, assert} = chai;
3
+ import GeneratePromptInputObject from '../src/templates/generate-prompt-input-object.js';
4
+ import {Data} from '../src/spyne-template-prompts.js';
5
+ import {MockData} from './mocks/enquirer-data.js';
6
+ const {promptTypes} = Data;
7
+
8
+ describe('should test prompt input object generator', () => {
9
+
10
+ it('input prompt generator should exist', () => {
11
+ expect(GeneratePromptInputObject).to.exist;
12
+
13
+ });
14
+
15
+
16
+ it('should get initial select file prompt object', ()=>{
17
+ const inputType = 'selectFileType';
18
+ const inputPrompt = new GeneratePromptInputObject(inputType);
19
+ //console.log('input prompt is ',{inputPrompt}, inputPrompt.getPrompObject())
20
+ const prompt = inputPrompt.getPrompObject();
21
+
22
+ expect(prompt).to.be.an('object');
23
+
24
+
25
+ })
26
+
27
+ it('should generate ViewStream fileName input', ()=>{
28
+ const inputType = 'fileName';
29
+ const fileType = 'ViewStream';
30
+
31
+ const inputPrompt = new GeneratePromptInputObject(inputType, fileType);
32
+
33
+
34
+ //console.log('input prompt is ',inputPrompt.getPrompObject());
35
+
36
+ return true;
37
+
38
+ })
39
+
40
+
41
+ });
@@ -0,0 +1,60 @@
1
+ import chai from 'chai';
2
+ const {expect, assert} = chai;
3
+ import {MockData} from './mocks/enquirer-data.js';
4
+ import {AnswersData} from './mocks/answers.js';
5
+ const {answersArr} = AnswersData;
6
+ import {generatePromptOutput} from '../src/templates/generate-prompt-output.js';
7
+ import R from 'ramda';
8
+
9
+ const getAnswersByFileType = (fileType) => R.compose(R.head, R.filter(R.propEq('fileType', fileType)))(answersArr)
10
+
11
+ const defaultStr = `
12
+ import {Subject} from 'rxjs';
13
+ import {Channel, ChannelPayloadFilter} from 'spyne';
14
+
15
+
16
+ export class ChannelCustom extends Channel{
17
+
18
+ constructor(name, props={}) {
19
+ name="CHANNEL_CUSTOM";
20
+ props.replayLastPayload = true;
21
+ super(name, props);
22
+
23
+ }
24
+
25
+ onRegistered(){
26
+
27
+ }
28
+
29
+ addRegisteredActions() {
30
+ return [];
31
+ }
32
+
33
+ onViewStreamInfo(obj) {
34
+ let data = obj.props();
35
+ }
36
+
37
+
38
+
39
+ }
40
+
41
+ `
42
+
43
+
44
+
45
+ describe('should test saving to file', () => {
46
+ it('should save file', () => {
47
+ const answersObj = getAnswersByFileType('Channel');
48
+ const {fileName, fileDirectory} = answersObj;
49
+
50
+ const fileHasSaved = false;
51
+ const fileExists = false;
52
+ const savedProps = {fileHasSaved, fileExists};
53
+
54
+ const msgOutput = generatePromptOutput(answersObj, savedProps, defaultStr);
55
+
56
+ expect(msgOutput).to.be.a('string');
57
+
58
+ });
59
+
60
+ });
@@ -0,0 +1,13 @@
1
+ import chai from 'chai';
2
+ const {expect, assert} = chai;
3
+
4
+ describe('should test cli methods', () => {
5
+
6
+ it('should run cli tests', () => {
7
+
8
+
9
+ return true;
10
+
11
+ });
12
+
13
+ });
@@ -0,0 +1,33 @@
1
+ const AnswersData = {
2
+ "answersArr": [
3
+ {
4
+ "fileName": "my-ui-el-view.js",
5
+ "className": "MyUiElView",
6
+ "fileDirectory": "./src/app/components/",
7
+ "fileType": "ViewStream"
8
+ },
9
+ {
10
+ "fileName": "my-dom-element.js",
11
+ "className": "MyDomElement",
12
+ "fileDirectory": "./src/app/components/",
13
+ "fileType": "DomElement"
14
+ },
15
+ {
16
+ "fileName": "channel-custom.js",
17
+ "className": "ChannelCustom",
18
+ "channelName": "CHANNEL_CUSTOM",
19
+ "replayLastPayload": false,
20
+ "fileDirectory": "./src/app/channels/",
21
+ "fileType": "Channel"
22
+ },
23
+ {
24
+ "fileName": "my-custom-trait.js",
25
+ "className": "MyCustomTrait",
26
+ "methodPrefix": "myCustom$",
27
+ "fileDirectory": "./src/app/traits/",
28
+ "fileType": "SpyneTrait"
29
+ }
30
+ ]
31
+ }
32
+
33
+ export {AnswersData}
@@ -0,0 +1,33 @@
1
+ const AnswersData = {
2
+ "answersArr": [
3
+ {
4
+ "fileName": "my-ui-el-view.js",
5
+ "className": "MyUiElView",
6
+ "fileDirectory": "./src/app/components/",
7
+ "fileType": "ViewStream"
8
+ },
9
+ {
10
+ "fileName": "my-dom-element.js",
11
+ "className": "MyDomElement",
12
+ "fileDirectory": "./src/app/components/",
13
+ "fileType": "DomElement"
14
+ },
15
+ {
16
+ "fileName": "channel-custom.js",
17
+ "className": "ChannelCustom",
18
+ "channelName": "CHANNEL_CUSTOM",
19
+ "replayLastPayload": false,
20
+ "fileDirectory": "./src/app/channels/",
21
+ "fileType": "Channel"
22
+ },
23
+ {
24
+ "fileName": "my-custom-trait.js",
25
+ "className": "MyCustomTrait",
26
+ "methodPrefix": "myCustom$",
27
+ "fileDirectory": "./src/app/traits/",
28
+ "fileType": "SpyneTrait"
29
+ }
30
+ ]
31
+ }
32
+
33
+ export {AnswersData}