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 es5ImportStatement = function es5ImportStatement(module) {
return 'var ' + (0, _template.localModuleName)(module) + ' = require(\'./' + module + '\');';
};
var es5NamedExportStatement = function es5NamedExportStatement(module) {
return 'exports.' + (0, _template.localModuleName)(module) + ' = require(\'./' + module + '\');';
};
var es5ExportStatement = function es5ExportStatement(modules) {
if (modules.length === 0) return '';
return 'module.exports = ' + (0, _template.moduleArray)(modules) + ';';
};
var es5ImportStatements = function es5ImportStatements(modules) {
return modules.map(es5ImportStatement).join('\n');
};
var es5NamedExports = function es5NamedExports(modules) {
return modules.map(es5NamedExportStatement).join('\n');
};
exports.default = function (modules, options) {
var useNamedExports = options.namedExports;
var arrayExports = [(0, _template.headerComment)(), es5ImportStatements(modules), es5ExportStatement(modules), (0, _template.footerComment)(), ''];
var namedExports = [(0, _template.headerComment)(), es5NamedExports(modules), (0, _template.footerComment)(), ''];
var templateArray = useNamedExports ? namedExports : arrayExports;
return templateArray.join('\n');
};
module.exports = exports['default'];