-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
43 lines (37 loc) · 1.06 KB
/
helpers.js
File metadata and controls
43 lines (37 loc) · 1.06 KB
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
const fs = require('fs');
const lineReader = require('line-reader');
/**
* @param {String} name
*
* Transfrom my-comp -> MyComp
* or my-comp.dialog -> MyCompDialog
*/
const getComponentNameFromDirName = name => {
if (name.includes('-') || name.includes('.')) {
const stringArr = name.split(/-|\./)
return stringArr.map(part => `${part.charAt(0).toUpperCase()}${part.substr(1)}`).join('');
}
return `${name.charAt(0).toUpperCase()}${name.substr(1)}`;
}
function writeToParent(dir) {
let exportFilesString = '';
const exportedFiles = [dir];
lineReader.eachLine('../index.js', (line, last) => {
const dir = line.split('./')[1];
const formattedDir = dir.replace("';", '');
exportedFiles.push(formattedDir);
if (last) {
exportedFiles.sort();
exportedFiles.forEach(item => {
exportFilesString += `export * from './${item}';\n`;
});
fs.writeFile('../index.js', exportFilesString, (err) => {
if (err) { throw err }
});
}
});
}
module.exports = {
getComponentNameFromDirName,
writeToParent
};