indexr
Version:
Automated dynamic indexes for your ES6+ source code.
43 lines (29 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _template = require('./template');
var es6ImportStatement = function es6ImportStatement(module) {
return 'import ' + (0, _template.localModuleName)(module) + ' from \'./' + module + '\';';
};
var es6NamedExportStatement = function es6NamedExportStatement(module) {
return 'export { default as ' + (0, _template.localModuleName)(module) + ' } from \'./' + module + '\';';
};
var es6ExportStatement = function es6ExportStatement(modules) {
if (modules.length === 0) return '';
return 'export default ' + (0, _template.moduleArray)(modules) + ';';
};
var es6ImportStatements = function es6ImportStatements(modules) {
return modules.map(es6ImportStatement).join('\n');
};
var es6NamedExports = function es6NamedExports(modules) {
return modules.map(es6NamedExportStatement).join('\n');
};
exports.default = function (modules, options) {
var useNamedExports = options.namedExports;
var arrayExports = [(0, _template.headerComment)(), es6ImportStatements(modules), es6ExportStatement(modules), (0, _template.footerComment)(), ''];
var namedExports = [(0, _template.headerComment)(), es6NamedExports(modules), (0, _template.footerComment)(), ''];
var templateArray = useNamedExports ? namedExports : arrayExports;
return templateArray.join('\n');
};
module.exports = exports['default'];