1 | 'use strict';
|
2 |
|
3 | const Plugin = require('broccoli-plugin');
|
4 | const fs = require('fs');
|
5 | const path = require('path');
|
6 | const glob = require('glob');
|
7 |
|
8 | module.exports = class EntryPoint extends Plugin {
|
9 | constructor(inputNodes, options) {
|
10 | super(inputNodes, {
|
11 | name: options && options.name,
|
12 | annotation: options && options.annotation
|
13 | });
|
14 |
|
15 | this.entryPoint = options && options.entryPoint;
|
16 | }
|
17 |
|
18 | build() {
|
19 | let entryPointJS = this.inputPaths.reduce((lines, inputPath) => {
|
20 | let indexJS = glob.sync('**/index.js', { cwd: inputPath })[0];
|
21 |
|
22 | if (indexJS) {
|
23 | let entryPointModuleName = path.dirname(indexJS);
|
24 | return lines.concat(`import "${entryPointModuleName}";\n`);
|
25 | }
|
26 |
|
27 | return lines;
|
28 | }, '');
|
29 |
|
30 | fs.writeFileSync(path.join(this.outputPath, this.entryPoint), entryPointJS);
|
31 | }
|
32 | };
|