1 | import analizePkg from "./analize-pkg";
|
2 | import { log, logFilename } from "./console";
|
3 | import { BUILT, ERROR, WRITING, WRITTEN } from "./events";
|
4 | import pkgToConfigs from "./pkg-to-configs";
|
5 | import rollItUp from "./roll-it-up";
|
6 | import { BundlibOptions } from "./types";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const version = 0.4;
|
12 |
|
13 | const bundlib = async (cwd: string, { dev, watch, silent }: BundlibOptions = {}) => {
|
14 |
|
15 | if (!silent) {
|
16 | log("bundlib v%s\r\n", version);
|
17 | log("> reading package.json...");
|
18 | }
|
19 |
|
20 | const pkg = await analizePkg(cwd);
|
21 |
|
22 | const configs = pkgToConfigs(pkg, dev);
|
23 |
|
24 | const buildProcess = await rollItUp(
|
25 | configs,
|
26 | watch,
|
27 | );
|
28 |
|
29 | if (!silent) {
|
30 |
|
31 | buildProcess.on(WRITING, (filename) => {
|
32 | logFilename(filename, cwd, "building > %s...");
|
33 | });
|
34 |
|
35 | buildProcess.on(WRITTEN, (filename) => {
|
36 | logFilename(filename, cwd, "built > %s");
|
37 | });
|
38 |
|
39 | buildProcess.on(ERROR, (err) => {
|
40 | log(err);
|
41 | });
|
42 |
|
43 | if (watch) {
|
44 |
|
45 | buildProcess.on(BUILT, () => {
|
46 | log("> watching for changes...");
|
47 | });
|
48 |
|
49 | }
|
50 |
|
51 | }
|
52 |
|
53 | return buildProcess;
|
54 |
|
55 | };
|
56 |
|
57 | export default bundlib;
|