1 | import { EventEmitter } from "events";
|
2 | import { OutputOptions, rollup } from "rollup";
|
3 | import { BUILDING, BUILT, WRITING, WRITTEN } from "./events";
|
4 | import oneByOne from "./one-by-one";
|
5 | import { BuildEventEmitter, BuldFunction } from "./types";
|
6 |
|
7 | const build: BuldFunction = async (configs) => {
|
8 |
|
9 | const result: BuildEventEmitter = new EventEmitter();
|
10 |
|
11 | setImmediate(() => {
|
12 |
|
13 | result.emit(BUILDING);
|
14 |
|
15 | oneByOne(configs, async (config, next, index) => {
|
16 |
|
17 | const output = config.output as OutputOptions;
|
18 | const filename = output.file as string;
|
19 |
|
20 | result.emit(WRITING, filename);
|
21 |
|
22 | const buildResult = await rollup(config);
|
23 | await buildResult.write(output);
|
24 |
|
25 | result.emit(WRITTEN, filename);
|
26 |
|
27 | next();
|
28 |
|
29 | if (index + 1 >= configs.length) {
|
30 | result.emit(BUILT);
|
31 | }
|
32 |
|
33 | });
|
34 |
|
35 | });
|
36 |
|
37 | return result;
|
38 |
|
39 | };
|
40 |
|
41 | export default build;
|