-
Notifications
You must be signed in to change notification settings - Fork 4
/
common-function.js
52 lines (43 loc) · 1.36 KB
/
common-function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Common function for generation
*/
var generators = require('yeoman-generator');
var lodash = require('lodash');
var json = require('fs');
module.exports = {
getArgsInArray: function (args) {
var argsArray = [];
if (args.length > 0) {
var argumentsInString = "" + args;
argsArray = argumentsInString.split('/');
}
else {
console.log("Please specify the name of your component in camel case. Eg: MyFirstItem");
}
return argsArray;
},
getPathAndArgs: function (argsArray, haveToCreateFolder) {
var path = "";
var argsInKebab = "";
var pathArgs = [];
var length= argsArray.length;
if(!haveToCreateFolder) length--;
this.componentName = argsArray[argsArray.length - 1];
for (var i = 0; i < length; i++) {
var addAPlus = "";
if (argsArray[i].indexOf("+") > -1) {
addAPlus = "+";
}
if (i == 0) {
path = addAPlus + lodash.kebabCase(argsArray[i]);
}
else {
path = path + '/' + addAPlus + lodash.kebabCase(argsArray[i]);
}
}
argsInKebab = lodash.kebabCase(argsArray[argsArray.length - 1]);
pathArgs.push(path);
pathArgs.push(argsInKebab);
return pathArgs;
}
};