Change the index file format to use "export ... from" (fixes #3)

This commit is contained in:
Gajus Kuizinas
2016-01-29 09:40:35 +00:00
parent 832044c9fd
commit 69825b59c6
14 changed files with 35 additions and 68 deletions
+43
View File
@@ -0,0 +1,43 @@
import _ from 'lodash';
let buildExportBlock,
safeVariableName;
safeVariableName = (fileName) => {
let indexOfDot;
indexOfDot = fileName.indexOf('.');
if (indexOfDot === -1) {
return fileName;
} else {
return fileName.slice(0, indexOfDot);
}
};
buildExportBlock = (files) => {
let importBlock;
importBlock = _.map(files, (fileName) => {
return 'export ' + safeVariableName(fileName) + ' from \'./' + fileName + '\';';
});
importBlock = importBlock.join('\n');
return importBlock;
};
export default (filePaths) => {
let code,
sortedFilePaths;
code = '\'create index\';\n\n';
if (filePaths.length) {
sortedFilePaths = filePaths.sort();
code += buildExportBlock(sortedFilePaths) + '\n\n';
}
return code;
};