1 | 'use strict';
|
2 |
|
3 | var matched = require('matched');
|
4 |
|
5 | var entry = '\0rollup-plugin-multi-entry:entry-point';
|
6 |
|
7 | function multiEntry() {
|
8 | var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
9 |
|
10 | var include = [];
|
11 | var exclude = [];
|
12 | var exporter = function exporter(path) {
|
13 | return 'export * from ' + JSON.stringify(path) + ';';
|
14 | };
|
15 |
|
16 | function configure(config) {
|
17 | if (typeof config === 'string') {
|
18 | include = [config];
|
19 | } else if (Array.isArray(config)) {
|
20 | include = config;
|
21 | } else {
|
22 | include = config.include || [];
|
23 | exclude = config.exclude || [];
|
24 | if (config.exports === false) {
|
25 | exporter = function exporter(path) {
|
26 | return 'import ' + JSON.stringify(path) + ';';
|
27 | };
|
28 | }
|
29 | }
|
30 | }
|
31 |
|
32 | if (config) {
|
33 | configure(config);
|
34 | }
|
35 |
|
36 | return {
|
37 | options: function options(_options) {
|
38 | if (_options.input && _options.input !== entry) {
|
39 | configure(_options.input);
|
40 | }
|
41 | _options.input = entry;
|
42 | },
|
43 | resolveId: function resolveId(id) {
|
44 | if (id === entry) {
|
45 | return entry;
|
46 | }
|
47 | },
|
48 | load: function load(id) {
|
49 | if (id === entry) {
|
50 | if (!include.length) {
|
51 | return Promise.resolve('');
|
52 | }
|
53 | var patterns = include.concat(exclude.map(function (pattern) {
|
54 | return '!' + pattern;
|
55 | }));
|
56 | return matched.promise(patterns, { realpath: true }).then(function (paths) {
|
57 | return paths.map(exporter).join('\n');
|
58 | });
|
59 | }
|
60 | }
|
61 | };
|
62 | }
|
63 |
|
64 | module.exports = multiEntry;
|