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.
- package/README.md +3 -0
- package/index-cli.js +56 -0
- package/index.js +14 -0
- package/lib/ansi.js +116 -0
- package/lib/combos.js +75 -0
- package/lib/completer.js +52 -0
- package/lib/interpolate.js +266 -0
- package/lib/keypress.js +243 -0
- package/lib/placeholder.js +63 -0
- package/lib/prompt.js +485 -0
- package/lib/prompts/autocomplete.js +113 -0
- package/lib/prompts/basicauth.js +41 -0
- package/lib/prompts/confirm.js +13 -0
- package/lib/prompts/editable.js +136 -0
- package/lib/prompts/form.js +196 -0
- package/lib/prompts/index.js +28 -0
- package/lib/prompts/input.js +55 -0
- package/lib/prompts/invisible.js +11 -0
- package/lib/prompts/list.js +36 -0
- package/lib/prompts/multiselect.js +11 -0
- package/lib/prompts/numeral.js +1 -0
- package/lib/prompts/password.js +18 -0
- package/lib/prompts/quiz.js +37 -0
- package/lib/prompts/scale.js +237 -0
- package/lib/prompts/select.js +139 -0
- package/lib/prompts/snippet.js +185 -0
- package/lib/prompts/sort.js +37 -0
- package/lib/prompts/survey.js +163 -0
- package/lib/prompts/text.js +1 -0
- package/lib/prompts/toggle.js +109 -0
- package/lib/render.js +33 -0
- package/lib/roles.js +46 -0
- package/lib/state.js +69 -0
- package/lib/styles.js +144 -0
- package/lib/symbols.js +66 -0
- package/lib/theme.js +11 -0
- package/lib/timer.js +38 -0
- package/lib/types/array.js +658 -0
- package/lib/types/auth.js +29 -0
- package/lib/types/boolean.js +88 -0
- package/lib/types/index.js +7 -0
- package/lib/types/number.js +86 -0
- package/lib/types/string.js +185 -0
- package/lib/utils.js +268 -0
- package/package.json +45 -0
- package/src/app/channels/.gitkeep +0 -0
- package/src/app/components/.gitkeep +0 -0
- package/src/app/traits/.gitkeep +0 -0
- package/src/spyne-file-prompt.js +63 -0
- package/src/spyne-template-prompts.js +171 -0
- package/src/templates/generate-file-string.js +131 -0
- package/src/templates/generate-prompt-input-fields.js +256 -0
- package/src/templates/generate-prompt-input-object.js +46 -0
- package/src/templates/generate-prompt-output.js +109 -0
- package/src/ui.js +16 -0
- package/src/utils/color-utils.js +36 -0
- package/src/utils/error-logger.js +15 -0
- package/src/utils/file-utils.js +69 -0
- package/tests/generate-file-prompt.test.js +47 -0
- package/tests/generate-file-string.test.js +68 -0
- package/tests/generate-prompt-input-fields-methods.test.js +178 -0
- package/tests/generate-prompt-input-fields.test.js +181 -0
- package/tests/generate-prompt-input-object.test.js +41 -0
- package/tests/generate-prompt-output.test.js +60 -0
- package/tests/index.test.js +13 -0
- package/tests/mocks/answers.js +33 -0
- package/tests/mocks/answers.json +33 -0
- package/tests/mocks/enquirer-data.js +411 -0
- package/tests/mocks/enquirer-data.json +409 -0
- package/tests/utils/file-utils.test.js +70 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import enquirer from 'enquirer';
|
|
2
|
+
const {prompt, Select} = enquirer;
|
|
3
|
+
|
|
4
|
+
import {Data} from './spyne-template-prompts.js';
|
|
5
|
+
const {promptInputHash} = Data;
|
|
6
|
+
import GeneratePromptInputObject from './templates/generate-prompt-input-object.js';
|
|
7
|
+
import GenerateFileString from './templates/generate-file-string.js';
|
|
8
|
+
import {onSaveSpyneFileToDir} from './utils/file-utils.js';
|
|
9
|
+
import {generatePromptOutput} from './templates/generate-prompt-output.js';
|
|
10
|
+
|
|
11
|
+
export default class SpyneFilePrompt {
|
|
12
|
+
|
|
13
|
+
constructor(props) {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static getFilePromptPropertiesObj(fileType) {
|
|
18
|
+
return promptInputHash[fileType];
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getFilePrompt(fileType) {
|
|
23
|
+
const mapInputTypesToPrompObj = (inputType) => {
|
|
24
|
+
return new GeneratePromptInputObject(inputType,
|
|
25
|
+
fileType).getPrompObject();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const filePropsObj = SpyneFilePrompt.getFilePromptPropertiesObj(fileType);
|
|
29
|
+
const {props} = filePropsObj;
|
|
30
|
+
return props.map(mapInputTypesToPrompObj);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getSelectPromptObj() {
|
|
34
|
+
const promptGen = new GeneratePromptInputObject('selectFileType');
|
|
35
|
+
return promptGen.getPrompObject();
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
saveFileAndSendOutput(answers) {
|
|
40
|
+
const {fileType, fileName, fileDirectory} = answers;
|
|
41
|
+
const {fileString} = new GenerateFileString(fileType, answers);
|
|
42
|
+
const savedProps = onSaveSpyneFileToDir(fileString, fileName, fileDirectory);
|
|
43
|
+
const msgOutput = generatePromptOutput(answers, savedProps, fileString);
|
|
44
|
+
console.log(msgOutput);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async startPrompt() {
|
|
48
|
+
const selectPromptObj = this.getSelectPromptObj();
|
|
49
|
+
//console.log('select prompt obj is ',selectPromptObj);
|
|
50
|
+
const selectPrompt = new Select(selectPromptObj);
|
|
51
|
+
const onSelectComplete = async (fileType) => {
|
|
52
|
+
const filePromptArr = SpyneFilePrompt.getFilePrompt(fileType);
|
|
53
|
+
//console.log("promp arr is ",filePromptArr);
|
|
54
|
+
const filePrompt = await prompt(filePromptArr);
|
|
55
|
+
const answersObj = Object.assign({}, filePrompt, {fileType});
|
|
56
|
+
this.saveFileAndSendOutput(answersObj);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
selectPrompt.run().then(onSelectComplete);
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
const Data = {
|
|
2
|
+
"debug": true,
|
|
3
|
+
"appPath": "./src/app/",
|
|
4
|
+
"init": {
|
|
5
|
+
"promptName": "fileType",
|
|
6
|
+
"type": "Select",
|
|
7
|
+
"message": "Select a file type",
|
|
8
|
+
"choices": [
|
|
9
|
+
"ViewStream",
|
|
10
|
+
"Channel",
|
|
11
|
+
"SpyneTrait",
|
|
12
|
+
"DomElement"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"inputTypesArr": [
|
|
16
|
+
"selectFileType",
|
|
17
|
+
"fileName",
|
|
18
|
+
"className",
|
|
19
|
+
"fileDirectory",
|
|
20
|
+
"methodPrefix",
|
|
21
|
+
"channelName",
|
|
22
|
+
"replayLastPayload"
|
|
23
|
+
],
|
|
24
|
+
"fileTypesArr": [
|
|
25
|
+
"ViewStream",
|
|
26
|
+
"DomElement",
|
|
27
|
+
"Channel",
|
|
28
|
+
"SpyneTrait"
|
|
29
|
+
],
|
|
30
|
+
"fieldTypesArr": [
|
|
31
|
+
"type",
|
|
32
|
+
"name",
|
|
33
|
+
"format",
|
|
34
|
+
"result",
|
|
35
|
+
"resultFileName",
|
|
36
|
+
"message",
|
|
37
|
+
"choices",
|
|
38
|
+
"initial",
|
|
39
|
+
"hint",
|
|
40
|
+
"validate"
|
|
41
|
+
],
|
|
42
|
+
"promptTypes": [
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
"inputType" : "selectFileType",
|
|
46
|
+
"type" : "Select",
|
|
47
|
+
"fields" : [
|
|
48
|
+
"name",
|
|
49
|
+
"message",
|
|
50
|
+
"choices",
|
|
51
|
+
"result"
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
"inputType": "fileName",
|
|
58
|
+
"fields": [
|
|
59
|
+
"name",
|
|
60
|
+
"format",
|
|
61
|
+
"result",
|
|
62
|
+
"initial",
|
|
63
|
+
"message",
|
|
64
|
+
"validate"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"inputType": "className",
|
|
69
|
+
"fields": [
|
|
70
|
+
"name",
|
|
71
|
+
"format",
|
|
72
|
+
"result",
|
|
73
|
+
"initial",
|
|
74
|
+
"message"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"inputType": "fileDirectory",
|
|
79
|
+
"fields": [
|
|
80
|
+
"name",
|
|
81
|
+
"format",
|
|
82
|
+
"result",
|
|
83
|
+
"initial",
|
|
84
|
+
"message",
|
|
85
|
+
"validate"
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"inputType": "channelName",
|
|
90
|
+
"fields": [
|
|
91
|
+
"name",
|
|
92
|
+
"format",
|
|
93
|
+
"result",
|
|
94
|
+
"initial",
|
|
95
|
+
"message"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"inputType": "methodPrefix",
|
|
100
|
+
"fields": [
|
|
101
|
+
"name",
|
|
102
|
+
"format",
|
|
103
|
+
"result",
|
|
104
|
+
"initial",
|
|
105
|
+
"message"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"inputType": "replayLastPayload",
|
|
110
|
+
"type" : "Confirm",
|
|
111
|
+
"fields": [
|
|
112
|
+
"name",
|
|
113
|
+
"format",
|
|
114
|
+
"result",
|
|
115
|
+
"message"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"promptProperties": {
|
|
120
|
+
"fileName": [],
|
|
121
|
+
"className": [],
|
|
122
|
+
"fileDirectory": [],
|
|
123
|
+
"methodPrefix": [],
|
|
124
|
+
"channelName": [],
|
|
125
|
+
"replayLastPayload": []
|
|
126
|
+
},
|
|
127
|
+
"promptInputHash": {
|
|
128
|
+
"ViewStream": {
|
|
129
|
+
"path": "components/",
|
|
130
|
+
"props": [
|
|
131
|
+
"fileName",
|
|
132
|
+
"className",
|
|
133
|
+
"fileDirectory"
|
|
134
|
+
],
|
|
135
|
+
"promptArr": []
|
|
136
|
+
},
|
|
137
|
+
"DomElement": {
|
|
138
|
+
"path": "components/",
|
|
139
|
+
"props": [
|
|
140
|
+
"fileName",
|
|
141
|
+
"className",
|
|
142
|
+
"fileDirectory"
|
|
143
|
+
],
|
|
144
|
+
"promptArr": []
|
|
145
|
+
},
|
|
146
|
+
"Channel": {
|
|
147
|
+
"path": "channels/",
|
|
148
|
+
"props": [
|
|
149
|
+
"fileName",
|
|
150
|
+
"className",
|
|
151
|
+
"channelName",
|
|
152
|
+
"replayLastPayload",
|
|
153
|
+
"fileDirectory"
|
|
154
|
+
],
|
|
155
|
+
"promptArr": []
|
|
156
|
+
},
|
|
157
|
+
"SpyneTrait": {
|
|
158
|
+
"path": "traits/",
|
|
159
|
+
"props": [
|
|
160
|
+
"fileName",
|
|
161
|
+
"className",
|
|
162
|
+
"methodPrefix",
|
|
163
|
+
"fileDirectory"
|
|
164
|
+
],
|
|
165
|
+
"promptArr": []
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
export {Data}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const _viewStreamTemplate = (props)=> {
|
|
2
|
+
return `import {ViewStream} from 'spyne';
|
|
3
|
+
|
|
4
|
+
export class ${props.className} extends ViewStream {
|
|
5
|
+
|
|
6
|
+
constructor(props={}) {
|
|
7
|
+
|
|
8
|
+
super(props);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
addActionListeners() {
|
|
12
|
+
// return nexted array(s)
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
broadcastEvents() {
|
|
17
|
+
// return nexted array(s)
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onRendered() {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const _domElementTemplate = (props) => {
|
|
31
|
+
return `import {DomElement} from 'spyne';
|
|
32
|
+
|
|
33
|
+
export class ${props.className} extends DomElement {
|
|
34
|
+
|
|
35
|
+
constructor(props={}) {
|
|
36
|
+
|
|
37
|
+
super(props);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const _channelTemplate = (props)=> {
|
|
47
|
+
return `import {Subject} from 'rxjs';
|
|
48
|
+
import {Channel} from 'spyne';
|
|
49
|
+
|
|
50
|
+
export class ${props.className} extends Channel{
|
|
51
|
+
|
|
52
|
+
constructor(name, props={}) {
|
|
53
|
+
name="${props.channelName}";
|
|
54
|
+
props.sendCachedPayload = ${props.replayLastPayload};
|
|
55
|
+
|
|
56
|
+
super(name, props);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onRegistered(){
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
addRegisteredActions() {
|
|
64
|
+
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onViewStreamInfo(obj) {
|
|
69
|
+
let data = obj.props();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const _spyneTraitTemplate = (props)=>{
|
|
78
|
+
return `import {SpyneTrait} from 'spyne';
|
|
79
|
+
|
|
80
|
+
export class ${props.className} extends SpyneTrait {
|
|
81
|
+
|
|
82
|
+
constructor(context){
|
|
83
|
+
let traitPrefix = "${props.methodPrefix}";
|
|
84
|
+
|
|
85
|
+
super(context, traitPrefix);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static ${props.methodPrefix}HelloWorld(){
|
|
89
|
+
return "Hello World";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export default class GenerateFileString {
|
|
101
|
+
|
|
102
|
+
constructor(fileTypeName, fileProps) {
|
|
103
|
+
this._fileTypeName = fileTypeName;
|
|
104
|
+
this._fileProps = fileProps;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get fileString(){
|
|
108
|
+
|
|
109
|
+
const methodFn = GenerateFileString.getFileTemplate(this._fileTypeName)
|
|
110
|
+
this._fileStr = methodFn(this._fileProps);
|
|
111
|
+
return this._fileStr;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
static getFileTemplate(str){
|
|
116
|
+
|
|
117
|
+
const fileTypeHashObj = {
|
|
118
|
+
ViewStream: _viewStreamTemplate,
|
|
119
|
+
DomElement: _domElementTemplate,
|
|
120
|
+
Channel: _channelTemplate,
|
|
121
|
+
SpyneTrait: _spyneTraitTemplate
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return fileTypeHashObj[str];
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {Data} from '../spyne-template-prompts.js';
|
|
2
|
+
import ErrorLogger from '../utils/error-logger.js';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
appPath,
|
|
6
|
+
promptInputHash,
|
|
7
|
+
inputTypesArr,
|
|
8
|
+
fileTypesArr,
|
|
9
|
+
fieldTypesArr,
|
|
10
|
+
} = Data;
|
|
11
|
+
|
|
12
|
+
import enquirer from 'enquirer';
|
|
13
|
+
const {prompt, Select} = enquirer;
|
|
14
|
+
|
|
15
|
+
import c from 'ansi-colors';
|
|
16
|
+
import R from 'ramda';
|
|
17
|
+
import {getLocalFileDirectory, validateFileDirectory} from '../utils/file-utils.js';
|
|
18
|
+
import changeCase from 'change-case';
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
camelCase,
|
|
22
|
+
capitalCase,
|
|
23
|
+
constantCase,
|
|
24
|
+
dotCase,
|
|
25
|
+
headerCase,
|
|
26
|
+
noCase,
|
|
27
|
+
paramCase,
|
|
28
|
+
pascalCase,
|
|
29
|
+
pathCase,
|
|
30
|
+
sentenceCase,
|
|
31
|
+
snakeCase,
|
|
32
|
+
} = changeCase;
|
|
33
|
+
|
|
34
|
+
const validateFieldFn = R.curry((arr, type, value) => {
|
|
35
|
+
const isValid = arr.indexOf(value) >= 0;
|
|
36
|
+
if (isValid) {
|
|
37
|
+
return value;
|
|
38
|
+
} else if (_inputType !== 'selectFileType') {
|
|
39
|
+
ErrorLogger.log(`value, ${value}, for ${type} is not valid`,
|
|
40
|
+
'validateProps');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const isInitSelect = () => _inputType === 'selectFileType';
|
|
46
|
+
|
|
47
|
+
const validateInputType = validateFieldFn(inputTypesArr, 'inputType');
|
|
48
|
+
const validateFileType = validateFieldFn(fileTypesArr, 'fileType') ||
|
|
49
|
+
isInitSelect();
|
|
50
|
+
const validateFieldType = validateFieldFn(fieldTypesArr, 'fieldType');
|
|
51
|
+
const messageColor = c.blueBright;
|
|
52
|
+
const answerColor = c.greenBright;
|
|
53
|
+
|
|
54
|
+
const messageMapColor = (m) => c.blueBright(m);
|
|
55
|
+
const choicesMapColor = (choice) => {
|
|
56
|
+
return c.greenBright(choice)
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const choicesResultParseFileName = (choice) => {
|
|
61
|
+
const fileNameIsValid = validteJsSuffix(choice);
|
|
62
|
+
choice = fileNameIsValid === true ? choice : choice+".js";
|
|
63
|
+
return c.unstyle(c.greenBright(choice))
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const choicesResultParse = (choice, args) => {
|
|
67
|
+
return c.unstyle(c.greenBright(choice))
|
|
68
|
+
};
|
|
69
|
+
const validatorLength = value => String(value).length > 3;
|
|
70
|
+
|
|
71
|
+
let _inputType;
|
|
72
|
+
let _fileType;
|
|
73
|
+
let _fieldType;
|
|
74
|
+
let _type = 'input';
|
|
75
|
+
let _name;
|
|
76
|
+
let _message;
|
|
77
|
+
let _format;
|
|
78
|
+
let _result;
|
|
79
|
+
let _initial;
|
|
80
|
+
let _hint;
|
|
81
|
+
let _validateMethod;
|
|
82
|
+
let _options;
|
|
83
|
+
|
|
84
|
+
let _field;
|
|
85
|
+
|
|
86
|
+
const generateName = () => {
|
|
87
|
+
return 'thename';
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const pathProp = (arr) => R.path(arr);
|
|
91
|
+
|
|
92
|
+
const dataProp = (prop) => pathProp(['enquirer', 'answers', prop]);
|
|
93
|
+
|
|
94
|
+
const toPascalCase = (str) => {
|
|
95
|
+
const fileNoSuffix = String(str).replace(/^(.*)(.js)$/, '$1');
|
|
96
|
+
return pascalCase(fileNoSuffix);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const toConstantCase = (data) => {
|
|
100
|
+
let classNameStr = dataProp('className')(data);
|
|
101
|
+
if (String(classNameStr).toLowerCase().indexOf('channel') !== 0) {
|
|
102
|
+
classNameStr = 'Channel' + classNameStr;
|
|
103
|
+
}
|
|
104
|
+
return constantCase(classNameStr);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const generateMethodPrefix = (data) => {
|
|
108
|
+
let classNameAnswer = dataProp('className')(data);
|
|
109
|
+
const classNameSentence = sentenceCase(classNameAnswer);
|
|
110
|
+
const classNameArr = String(classNameSentence).split(' ');
|
|
111
|
+
const len = classNameArr.length >= 2 ? 2 : 1;
|
|
112
|
+
const splitArr = R.slice(0, len, classNameArr);
|
|
113
|
+
return `${camelCase(splitArr.join('-'))}$`;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const generateInitialFileName = () => {
|
|
117
|
+
const initialFileNameHash = {
|
|
118
|
+
ViewStream: 'my-ui-el-view.js',
|
|
119
|
+
DomElement: 'my-dom-element.js',
|
|
120
|
+
Channel: 'channel-custom.js',
|
|
121
|
+
SpyneTrait: 'my-custom-trait.js',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return initialFileNameHash[_fileType];
|
|
125
|
+
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const validteJsSuffix = (value) => {
|
|
129
|
+
const isValid = /(.*)(.js)/.test(value);
|
|
130
|
+
return isValid || 'file needs to end in .js';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const generateValidatorFn = () => {
|
|
134
|
+
const inputTypeHash = {
|
|
135
|
+
fileName: validteJsSuffix,
|
|
136
|
+
fileDirectory: validateFileDirectory,
|
|
137
|
+
|
|
138
|
+
};
|
|
139
|
+
const fn = inputTypeHash[_inputType];
|
|
140
|
+
return fn;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const generateInitial = () => {
|
|
144
|
+
const inputTypeHash = {
|
|
145
|
+
|
|
146
|
+
fileName: generateInitialFileName(),
|
|
147
|
+
className: R.compose(toPascalCase, dataProp('fileName')),
|
|
148
|
+
fileDirectory: getLocalFileDirectory(_fileType),
|
|
149
|
+
methodPrefix: generateMethodPrefix,
|
|
150
|
+
channelName: toConstantCase,
|
|
151
|
+
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const fn = inputTypeHash[_inputType];
|
|
155
|
+
|
|
156
|
+
return fn;
|
|
157
|
+
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const generateChoices = () => {
|
|
161
|
+
const inputTypeHash = {
|
|
162
|
+
selectFileType: fileTypesArr.map(choicesMapColor),
|
|
163
|
+
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const fn = inputTypeHash[_inputType];
|
|
167
|
+
return fn;
|
|
168
|
+
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const generateMesage = () => {
|
|
172
|
+
|
|
173
|
+
const defaultMsgFn = messageColor(`Enter the ${_fileType} file name`);
|
|
174
|
+
|
|
175
|
+
const inputTypeHash = {
|
|
176
|
+
selectFileType: messageColor(`Select file type`),
|
|
177
|
+
fileName: defaultMsgFn,
|
|
178
|
+
className: messageColor(`Enter the ${_fileType} class name`),
|
|
179
|
+
fileDirectory: messageColor(`Enter where you would like to save the ${_fileType} file`),
|
|
180
|
+
methodPrefix: messageColor(`Enter the string to be prepended to all trait methods`),
|
|
181
|
+
channelName: (d) => messageColor(R.compose(R.concat('Enter the channel name for '), R.path(['answers', 'className']))(d)),
|
|
182
|
+
replayLastPayload: messageColor(`This property determines if new subscribers receive the previous payload`),
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const fn = inputTypeHash[_inputType];
|
|
186
|
+
return fn;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const getType = () => 'input';
|
|
190
|
+
const getName = () => _inputType;
|
|
191
|
+
const getFormatFn = () => choicesMapColor;
|
|
192
|
+
const getResultFn = () => choicesResultParse;
|
|
193
|
+
const getResultFileNameFn = () => choicesResultParseFileName;
|
|
194
|
+
const getInitial = () => 'initial options';
|
|
195
|
+
const getHint = () => 'custom hint';
|
|
196
|
+
const getMessage = () => generateMesage();
|
|
197
|
+
const getValidattionFn = () => generateValidatorFn();
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
export default class PromptInputField {
|
|
202
|
+
|
|
203
|
+
constructor(inputType, fileType, fieldType, options = {}) {
|
|
204
|
+
_inputType = validateInputType(inputType);
|
|
205
|
+
_fileType = validateFileType(fileType);
|
|
206
|
+
_fieldType = validateFieldType(fieldType);
|
|
207
|
+
_options = options;
|
|
208
|
+
//console.log('intput type is ', {_inputType, _fileType, _fieldType, inputTypesArr})
|
|
209
|
+
this.generateField();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
generateField() {
|
|
215
|
+
|
|
216
|
+
const checkForCustomFileNameResult = ()=>{
|
|
217
|
+
const isFileNameInput = _inputType === 'fileName';
|
|
218
|
+
const isResultMethodType = _fieldType === 'result';
|
|
219
|
+
const isCustomFileNameResult = isFileNameInput && isResultMethodType;
|
|
220
|
+
_fieldType = isCustomFileNameResult ? "resultFileName" : _fieldType;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
const fieldMethodHash = {
|
|
226
|
+
type: getType,
|
|
227
|
+
name: getName,
|
|
228
|
+
format: getFormatFn,
|
|
229
|
+
result: getResultFn,
|
|
230
|
+
resultFileName: getResultFileNameFn,
|
|
231
|
+
message: getMessage,
|
|
232
|
+
initial: generateInitial,
|
|
233
|
+
hint: getHint,
|
|
234
|
+
choices: generateChoices,
|
|
235
|
+
validate: getValidattionFn,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
//checkForCustomFileNameResult();
|
|
239
|
+
|
|
240
|
+
const fieldMethod = fieldMethodHash[_fieldType];
|
|
241
|
+
_field = fieldMethod();
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
get field() {
|
|
246
|
+
return _field;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {Data} from '../spyne-template-prompts.js';
|
|
2
|
+
const {promptTypes} = Data;
|
|
3
|
+
import PromptInputField from './generate-prompt-input-fields.js';
|
|
4
|
+
|
|
5
|
+
import enquirer from 'enquirer';
|
|
6
|
+
const {prompt} = enquirer;
|
|
7
|
+
import R from 'ramda';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import color from 'ansi-colors';
|
|
10
|
+
|
|
11
|
+
let _inputType;
|
|
12
|
+
let _fileType;
|
|
13
|
+
let _type = "input";
|
|
14
|
+
let _promptObjSettings;
|
|
15
|
+
let _promptObj;
|
|
16
|
+
|
|
17
|
+
export default class GeneratePromptInputObject{
|
|
18
|
+
|
|
19
|
+
constructor(inputType, fileType, props={}) {
|
|
20
|
+
_inputType = inputType;
|
|
21
|
+
_fileType = fileType;
|
|
22
|
+
_promptObjSettings = GeneratePromptInputObject.getPromptObjSettings();
|
|
23
|
+
//console.log("PROMPT SETTINGS ",{_promptObjSettings,_inputType, promptTypes})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getPrompObject() {
|
|
27
|
+
const {fields, type} = _promptObjSettings;
|
|
28
|
+
|
|
29
|
+
const fieldsObj = {};
|
|
30
|
+
fieldsObj['type'] = type || 'input';
|
|
31
|
+
|
|
32
|
+
const reducer = (acc={}, key)=>{
|
|
33
|
+
acc[key]= new PromptInputField(_inputType, _fileType, key).field;
|
|
34
|
+
return acc;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return _promptObjSettings.fields.reduce(reducer, fieldsObj);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static getPromptObjSettings(){
|
|
41
|
+
return R.compose(R.head, R.filter(R.propEq('inputType', _inputType)))(promptTypes);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|