Change the index file format to use "export ... from" (fixes #3)
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user