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,109 @@
|
|
|
1
|
+
import R from 'ramda';
|
|
2
|
+
import boxen from 'boxen';
|
|
3
|
+
import colors from 'ansi-colors';
|
|
4
|
+
colors.alias('comment', colors.white);
|
|
5
|
+
colors.alias('snippet', colors.yellow);
|
|
6
|
+
colors.alias('code', colors.yellow);
|
|
7
|
+
colors.alias('files', colors.green);
|
|
8
|
+
|
|
9
|
+
let _answers;
|
|
10
|
+
let _savedProps;
|
|
11
|
+
let _fileStr;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const createChannelRegisterSnippet = () => {
|
|
15
|
+
const {fileName, className, fileDirectory, channelName} = _answers;
|
|
16
|
+
|
|
17
|
+
const filePath = fileDirectory+fileName;
|
|
18
|
+
const importStr = colors.snippet(`import {${className}} from '${filePath}';`);
|
|
19
|
+
|
|
20
|
+
const registerStr = colors.snippet(`SpyneApp.registerChannel(new ${className}());`)
|
|
21
|
+
|
|
22
|
+
const padding = " ";
|
|
23
|
+
const instx = colors.comment(`\n${padding}//ADD THE FOLLOWING SNIPPET TO YOUR SRC index.js FILE`)
|
|
24
|
+
|
|
25
|
+
const registerComment = colors.comment('//REGISTER CHANNEL AFTER SPYNE APP HAS BEEN INITIALIZED')
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const commentLine = colors.comment("/*_______________________________________________________________________________*/\n\n");
|
|
29
|
+
const finalStr = `\n${commentLine}${padding}${importStr}\n\n${padding}${registerComment}\n${padding}${registerStr}\n\n${commentLine}`;
|
|
30
|
+
|
|
31
|
+
//return instx+boxen(finalStr, {padding: 1});
|
|
32
|
+
return instx+finalStr;
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const outputFailedMessage = (e)=>{
|
|
37
|
+
const {fileType} = _answers;
|
|
38
|
+
const {fileDirPath, errorType} = _savedProps;
|
|
39
|
+
const fileDirPathFormatted = colors.files(`"${fileDirPath}"`)
|
|
40
|
+
|
|
41
|
+
// console.log('error is ',{e})
|
|
42
|
+
const defaultFailedInsertHash = {
|
|
43
|
+
"fileAlreadyExists" : ` already exists, and `
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let defaultFailedInsert = defaultFailedInsertHash[errorType] || "";
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
let defaultFailedText = `\n\nFile, ${fileDirPathFormatted},${defaultFailedInsert}is unable to be saved. `
|
|
51
|
+
|
|
52
|
+
let defaultFailedCopyInfo = `\n\nCopy and paste below:\n/*============ begin copy and paste ================*/\n\n${colors.code(_fileStr)}\n/*============ end copy and paste ================*/`
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
let defaultFailedOutput = defaultFailedText+defaultFailedCopyInfo;
|
|
56
|
+
|
|
57
|
+
if (fileType === "Channel"){
|
|
58
|
+
const channelSnippet = createChannelRegisterSnippet();
|
|
59
|
+
defaultFailedOutput = `${channelSnippet}\n${defaultFailedOutput}`;
|
|
60
|
+
}
|
|
61
|
+
return defaultFailedOutput;
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const outputMessage = ()=>{
|
|
67
|
+
const {fileType} = _answers;
|
|
68
|
+
const {fileHasSaved, errorType} = _savedProps;
|
|
69
|
+
|
|
70
|
+
//console.log('error type is ',{errorType, fileHasSaved})
|
|
71
|
+
|
|
72
|
+
let messageOutput = '';
|
|
73
|
+
|
|
74
|
+
const defaultStr = colors.bgBlue(colors.black("File saved successfully."));
|
|
75
|
+
const messageHash = {
|
|
76
|
+
|
|
77
|
+
"ViewStream" : defaultStr,
|
|
78
|
+
"DomElement" : defaultStr,
|
|
79
|
+
"SpyneTrait" : defaultStr,
|
|
80
|
+
"Channel" : `${defaultStr}\n${createChannelRegisterSnippet()}`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (fileHasSaved){
|
|
84
|
+
messageOutput = messageHash[fileType];
|
|
85
|
+
} else {
|
|
86
|
+
|
|
87
|
+
messageOutput = outputFailedMessage();
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
return messageOutput;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const generatePromptOutput = (answers={}, savedProps={}, fileStr='')=>{
|
|
98
|
+
|
|
99
|
+
_answers = answers;
|
|
100
|
+
_savedProps = savedProps;
|
|
101
|
+
_fileStr = fileStr;
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
return outputMessage();
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export {generatePromptOutput}
|
package/src/ui.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import figlet from 'figlet';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
export class SpyneCliUI {
|
|
5
|
+
|
|
6
|
+
constructor() {}
|
|
7
|
+
static title(){
|
|
8
|
+
const figletTxt = figlet.textSync('spyne-cli', {
|
|
9
|
+
horizontalLayout: 'universal smushing'
|
|
10
|
+
})
|
|
11
|
+
const chalkOutput = chalk.blue(figletTxt);
|
|
12
|
+
return console.log(chalkOutput);
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import c from 'ansi-colors';
|
|
2
|
+
|
|
3
|
+
const colorsArr = [c.black, c.cyan, c.red, c.green, c.greenBright, c.yellow, c.yellowBright, c.blue, c.blueBright, c.magenta, c.magentaBright, c.cyan, c.cyanBright, c.white, c.whiteBright, c.gray]
|
|
4
|
+
|
|
5
|
+
const bgColorsArr = [c.bgBlack, c.bgBlackBright, c.bgRed, c.bgRedBright, c.bgGreen,
|
|
6
|
+
c.bgGreenBright, c.bgYellow, c.bgYellowBright, c.bgBlue, c.bgBlueBright, c.bgMagenta, c.bgMagentaBright, c.cyan, c.cyanBright, c.bgWhite, c.bgWhiteBright]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const addColorToStr = (str)=>(cFn)=>cFn(str);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const viewAllColors =(str="File saved successfully.")=>{
|
|
14
|
+
const testColor = (cFn)=>{
|
|
15
|
+
const coloredStr = cFn(str);
|
|
16
|
+
console.log(coloredStr);
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const testBgColors = (bgFn)=>{
|
|
21
|
+
const strToColor = addColorToStr(str);
|
|
22
|
+
const mappedAll = colorsArr.map(strToColor);
|
|
23
|
+
const nestColors = (cFn)=>{
|
|
24
|
+
const nestedColor = bgFn(cFn);
|
|
25
|
+
console.log(nestedColor);
|
|
26
|
+
}
|
|
27
|
+
mappedAll.forEach(nestColors)
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
colorsArr.forEach(testColor)
|
|
32
|
+
bgColorsArr.forEach(testBgColors);
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {viewAllColors}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Data} from '../spyne-template-prompts.js';
|
|
2
|
+
const {debug} = Data;
|
|
3
|
+
|
|
4
|
+
export default class ErrorLogger {
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static log(msg, type='generic'){
|
|
11
|
+
if (debug){
|
|
12
|
+
console.log(`spyne-util warning: type:${type}, msg: ${msg}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
import {Data} from '../spyne-template-prompts.js';
|
|
3
|
+
const {appPath,promptInputHash} = Data;
|
|
4
|
+
import ErrorLogger from '../utils/error-logger.js';
|
|
5
|
+
import stringify from 'json-stringify-safe';
|
|
6
|
+
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import c from 'ansi-colors';
|
|
10
|
+
import R from 'ramda';;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const checkIfFileExists = (fileLoc) => fs.existsSync(fileLoc)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const onSaveSpyneFileToDir = (fileStr, fileName, fileDirectory) =>{
|
|
17
|
+
const fileDirPath = fileDirectory+fileName;
|
|
18
|
+
const fileExists = checkIfFileExists(fileDirPath);
|
|
19
|
+
let fileHasSaved = false;
|
|
20
|
+
let errorType;
|
|
21
|
+
|
|
22
|
+
if (fileExists){
|
|
23
|
+
// console.warn('file already exists');
|
|
24
|
+
const errObj = {fileDirPath}
|
|
25
|
+
errorType = 'fileAlreadyExists';
|
|
26
|
+
|
|
27
|
+
//ErrorLogger.log(JSON.stringify(errObj), errorType);
|
|
28
|
+
|
|
29
|
+
} else {
|
|
30
|
+
try {
|
|
31
|
+
const data = fs.writeFileSync(fileDirPath, fileStr)
|
|
32
|
+
//file written successfully
|
|
33
|
+
fileHasSaved = true;
|
|
34
|
+
|
|
35
|
+
} catch (err) {
|
|
36
|
+
errorType='generic';
|
|
37
|
+
|
|
38
|
+
ErrorLogger.log(err, 'onSaveSpyneFileToDir');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {fileExists, fileHasSaved,fileDirPath, errorType}
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const getLocalFileDirectory = (_fileType)=>{
|
|
49
|
+
let dirPath="";
|
|
50
|
+
const fileTypePath = R.path([_fileType, 'path'])(promptInputHash)
|
|
51
|
+
|
|
52
|
+
try{
|
|
53
|
+
dirPath = fs.existsSync(appPath) ? appPath+fileTypePath : './';
|
|
54
|
+
} catch(e){
|
|
55
|
+
ErrorLogger.log(e, 'getFileDirectory')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return dirPath;
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const validateFileDirectory = (value)=>{
|
|
64
|
+
const isValid = fs.existsSync(value);
|
|
65
|
+
return isValid || 'File directory needs to exist.';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export {getLocalFileDirectory, validateFileDirectory, onSaveSpyneFileToDir}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import SpyneFilePrompt from '../src/spyne-file-prompt.js';
|
|
2
|
+
import chai from 'chai';
|
|
3
|
+
const {expect, assert} = chai;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('should test spyne file prompt', () => {
|
|
8
|
+
|
|
9
|
+
const spyneFilePrompt = new SpyneFilePrompt();
|
|
10
|
+
|
|
11
|
+
it('SpyneFilePrompt should exist', () => {
|
|
12
|
+
expect(SpyneFilePrompt).to.exist;
|
|
13
|
+
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
it('should get the initial select prompt ',()=>{
|
|
18
|
+
|
|
19
|
+
const selectPrompt = spyneFilePrompt.getSelectPromptObj();
|
|
20
|
+
|
|
21
|
+
//console.log('spyne file prompt is ',{selectPrompt})
|
|
22
|
+
|
|
23
|
+
expect(selectPrompt.type).to.equal('Select');
|
|
24
|
+
expect(selectPrompt).to.be.an('object');
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should get file type obj from json data',()=>{
|
|
29
|
+
|
|
30
|
+
const fileType = 'ViewStream';
|
|
31
|
+
const viewStreamObj = SpyneFilePrompt.getFilePromptPropertiesObj(fileType);
|
|
32
|
+
expect(viewStreamObj.props).to.deep.equal([ 'fileName', 'className', 'fileDirectory' ])
|
|
33
|
+
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should get prompt array from file type', ()=>{
|
|
37
|
+
const fileType = 'Channel';
|
|
38
|
+
const promptArr = SpyneFilePrompt.getFilePrompt(fileType);
|
|
39
|
+
|
|
40
|
+
//console.log('prompt arr is ',{promptArr})
|
|
41
|
+
|
|
42
|
+
return true;
|
|
43
|
+
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
const {expect, assert} = chai;
|
|
3
|
+
import GenerateFileString from '../src/templates/generate-file-string.js';
|
|
4
|
+
|
|
5
|
+
describe('should test file string generator', () => {
|
|
6
|
+
|
|
7
|
+
it('file string generator should exist', () => {
|
|
8
|
+
|
|
9
|
+
expect(GenerateFileString).to.exist;
|
|
10
|
+
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should generate string for ViewStream file', ()=>{
|
|
14
|
+
const props = {
|
|
15
|
+
fileName: 'my-viewstream-file.js',
|
|
16
|
+
className: 'MyViewstreamClass'
|
|
17
|
+
}
|
|
18
|
+
const fileStrGen = new GenerateFileString('ViewStream', props);
|
|
19
|
+
const fileString = fileStrGen.fileString;
|
|
20
|
+
const classNameAdded = fileString.indexOf('class MyViewstreamClass ') >= 0;
|
|
21
|
+
// console.log('view stream file str is ',{classNameAdded}, fileString)
|
|
22
|
+
expect(classNameAdded).to.be.true;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should generate string for DomElement file', ()=>{
|
|
26
|
+
const props = {
|
|
27
|
+
fileName: 'my-dom-element-file.js',
|
|
28
|
+
className: 'MyDomElementClass'
|
|
29
|
+
}
|
|
30
|
+
const fileStrGen = new GenerateFileString('DomElement', props);
|
|
31
|
+
const fileString = fileStrGen.fileString;
|
|
32
|
+
const classNameAdded = fileString.indexOf('class MyDomElementClass ') >= 0;
|
|
33
|
+
//console.log('DomElement file str is ',{classNameAdded}, fileString)
|
|
34
|
+
expect(classNameAdded).to.be.true;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
it('should generate string for Channel file', ()=>{
|
|
39
|
+
const props = {
|
|
40
|
+
fileName: 'my-channel-file.js',
|
|
41
|
+
className: 'MyChannelClass',
|
|
42
|
+
channelName: 'MY_CUSTOM_CHANNEL',
|
|
43
|
+
replayLastPayload: true
|
|
44
|
+
}
|
|
45
|
+
const fileStrGen = new GenerateFileString('Channel', props);
|
|
46
|
+
const fileString = fileStrGen.fileString;
|
|
47
|
+
const classNameAdded = fileString.indexOf('class MyChannelClass ') >= 0;
|
|
48
|
+
//console.log('channel file str is ',{classNameAdded}, fileString)
|
|
49
|
+
expect(classNameAdded).to.be.true;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('should generate string for SpyneTrait file', ()=>{
|
|
54
|
+
const props = {
|
|
55
|
+
fileName: 'my-spynetrait-file.js',
|
|
56
|
+
className: 'MySpyneTrait',
|
|
57
|
+
methodPrefix: 'myTrait$'
|
|
58
|
+
}
|
|
59
|
+
const fileStrGen = new GenerateFileString('SpyneTrait', props);
|
|
60
|
+
const fileString = fileStrGen.fileString;
|
|
61
|
+
const classNameAdded = fileString.indexOf('class MySpyneTrait ') >= 0;
|
|
62
|
+
//console.log('channel file str is ',{classNameAdded}, fileString)
|
|
63
|
+
expect(classNameAdded).to.be.true;
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
const {expect, assert} = chai;
|
|
3
|
+
import PromptInputField from '../src/templates/generate-prompt-input-fields.js';
|
|
4
|
+
import changeCase from 'change-case';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
camelCase,
|
|
8
|
+
capitalCase,
|
|
9
|
+
constantCase,
|
|
10
|
+
dotCase,
|
|
11
|
+
headerCase,
|
|
12
|
+
noCase,
|
|
13
|
+
paramCase,
|
|
14
|
+
pascalCase,
|
|
15
|
+
pathCase,
|
|
16
|
+
sentenceCase,
|
|
17
|
+
snakeCase,
|
|
18
|
+
} = changeCase;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
import {MockData} from './mocks/enquirer-data.js';
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
describe('should create all necessary prompt input initial, hint and validate fields', () => {
|
|
26
|
+
|
|
27
|
+
it('PromptInputField should exist', () => {
|
|
28
|
+
expect(PromptInputField).to.exist;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
describe('it should generate all initial values ',()=>{
|
|
33
|
+
|
|
34
|
+
let inputType = "className";
|
|
35
|
+
let fileType = "ViewStream";
|
|
36
|
+
|
|
37
|
+
it('should generate initial file name values ',()=>{
|
|
38
|
+
const fileNameInputType = "fileName"
|
|
39
|
+
let fieldType = "initial";
|
|
40
|
+
|
|
41
|
+
const viewStreamInitialValue = new PromptInputField(fileNameInputType, 'ViewStream', fieldType).field;
|
|
42
|
+
const domElementInitialValue = new PromptInputField(fileNameInputType, 'DomElement', fieldType).field;
|
|
43
|
+
const channelInitialValue = new PromptInputField(fileNameInputType, 'Channel', fieldType).field;
|
|
44
|
+
const spyneTraitInitialValue = new PromptInputField(fileNameInputType, 'SpyneTrait', fieldType).field;
|
|
45
|
+
|
|
46
|
+
const isValidFileName = (str)=>/(.*)(.js)/.test(str)===true;
|
|
47
|
+
|
|
48
|
+
/*console.log('view stream file name is ',{viewStreamInitialValue})
|
|
49
|
+
console.log('dom element file name is ',{domElementInitialValue})
|
|
50
|
+
console.log('channel file name is ',{channelInitialValue})
|
|
51
|
+
console.log('spyne trait file name is ',{spyneTraitInitialValue})
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
expect(isValidFileName(viewStreamInitialValue)).to.be.true;
|
|
56
|
+
expect(isValidFileName(domElementInitialValue)).to.be.true;
|
|
57
|
+
expect(isValidFileName(channelInitialValue)).to.be.true;
|
|
58
|
+
expect(isValidFileName(spyneTraitInitialValue)).to.be.true;
|
|
59
|
+
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
it('should generate initial value for className based on valid filename', ()=>{
|
|
64
|
+
MockData.enquirer.answers.fileName = 'my-viewstream.js';
|
|
65
|
+
|
|
66
|
+
const initialViewStreamClassNameFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
67
|
+
const initialViewStreamClassName = initialViewStreamClassNameFn(MockData);
|
|
68
|
+
|
|
69
|
+
MockData.enquirer.answers.fileName = 'my-dom-element.js';
|
|
70
|
+
const initialDomElementClassNameFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
71
|
+
const initialDomElementClassName = initialDomElementClassNameFn(MockData);
|
|
72
|
+
|
|
73
|
+
MockData.enquirer.answers.fileName = 'channel-custom.js';
|
|
74
|
+
const initialChannelClassNameFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
75
|
+
const initialChannelClassName = initialDomElementClassNameFn(MockData);
|
|
76
|
+
|
|
77
|
+
MockData.enquirer.answers.fileName = 'my-custom-trait.js';
|
|
78
|
+
const initialTraitClassNameFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
79
|
+
const initialTraitClassName = initialTraitClassNameFn(MockData);
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/* console.log('initial class name is ',{initialViewStreamClassName})
|
|
83
|
+
console.log('initial dom element is ',{initialDomElementClassName})
|
|
84
|
+
console.log('initial channel is ',{initialChannelClassName})
|
|
85
|
+
console.log('initial trait is ',{initialTraitClassName})*/
|
|
86
|
+
|
|
87
|
+
expect(initialViewStreamClassName).to.equal('MyViewstream')
|
|
88
|
+
expect(initialDomElementClassName).to.equal('MyDomElement')
|
|
89
|
+
expect(initialChannelClassName).to.equal('ChannelCustom')
|
|
90
|
+
expect(initialTraitClassName).to.equal('MyCustomTrait')
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
it('it should generate initial value for directory based on app path', ()=>{
|
|
97
|
+
let inputType = 'fileDirectory';
|
|
98
|
+
const initialViewStreamFileDir = new PromptInputField(inputType, fileType, 'initial').field;
|
|
99
|
+
const initialDomElementFileDir = new PromptInputField(inputType, 'DomElement', 'initial').field;
|
|
100
|
+
const initialChannelFileDir = new PromptInputField(inputType, 'Channel', 'initial').field;
|
|
101
|
+
const initialSpyneTraitFileDir = new PromptInputField(inputType, 'SpyneTrait', 'initial').field;
|
|
102
|
+
//console.log('viewstream dir ',{initialViewStreamFileDir})
|
|
103
|
+
//console.log('domelement dir ',{initialDomElementFileDir})
|
|
104
|
+
//console.log('channel dir ',{initialChannelFileDir})
|
|
105
|
+
//console.log('spynetrait dir ',{initialSpyneTraitFileDir})
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
//console.log('process ',{initialFileDir})
|
|
110
|
+
expect(initialViewStreamFileDir).to.equal('./src/app/components/')
|
|
111
|
+
expect(initialDomElementFileDir).to.equal('./src/app/components/')
|
|
112
|
+
expect(initialChannelFileDir).to.equal('./src/app/channels/')
|
|
113
|
+
expect(initialSpyneTraitFileDir).to.equal('./src/app/traits/')
|
|
114
|
+
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('it should generate initial value for method prefix', ()=>{
|
|
118
|
+
MockData.enquirer.answers.className = 'MyCustomTrait';
|
|
119
|
+
fileType = "SpyneTrait";
|
|
120
|
+
inputType = "methodPrefix";
|
|
121
|
+
const initialMethodPrefixFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
122
|
+
const initialMethodPrefix = initialMethodPrefixFn(MockData);
|
|
123
|
+
expect(initialMethodPrefix).to.equal('myCustom$')
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('it should generate initial value for channel name', ()=>{
|
|
129
|
+
MockData.enquirer.answers.className = 'ChannelCustom';
|
|
130
|
+
fileType = "Channel";
|
|
131
|
+
inputType = "channelName";
|
|
132
|
+
const initialMethodPrefixFn = new PromptInputField(inputType, fileType, 'initial').field;
|
|
133
|
+
const initialMethodPrefix = initialMethodPrefixFn(MockData);
|
|
134
|
+
|
|
135
|
+
//console.log('channel name is ',initialMethodPrefix);
|
|
136
|
+
expect(initialMethodPrefix).to.equal('CHANNEL_CUSTOM')
|
|
137
|
+
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
describe('it should add proper validator for field',()=>{
|
|
149
|
+
const fieldType = 'validate';
|
|
150
|
+
|
|
151
|
+
it ('should generate validator for fileName ', ()=>{
|
|
152
|
+
const fileNameValidatorFn = new PromptInputField("fileName", "ViewStream", fieldType).field;
|
|
153
|
+
const fileNameValidator = fileNameValidatorFn('my-custom-viewstream.js');
|
|
154
|
+
//console.log('file name validator is ',{fileNameValidator})
|
|
155
|
+
expect(fileNameValidator).to.be.true;
|
|
156
|
+
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it ('should generate validator for file directory', ()=>{
|
|
160
|
+
const fileDirectoryValidatorFn = new PromptInputField("fileDirectory", "ViewStream", fieldType).field;
|
|
161
|
+
const validPath = './src/app/components/'
|
|
162
|
+
const inValidPath = './src/stuff'
|
|
163
|
+
const isValidDir = fileDirectoryValidatorFn(validPath);
|
|
164
|
+
const isInvalidDir = fileDirectoryValidatorFn(inValidPath);
|
|
165
|
+
expect(isValidDir).to.be.true;
|
|
166
|
+
expect(isInvalidDir).to.equal("File directory needs to exist.")
|
|
167
|
+
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
});
|