UNPKG

1.23 kBPlain TextView Raw
1import analizePkg from "./analize-pkg";
2import { log, logFilename } from "./console";
3import { BUILT, ERROR, WRITING, WRITTEN } from "./events";
4import pkgToConfigs from "./pkg-to-configs";
5import rollItUp from "./roll-it-up";
6import { BundlibOptions } from "./types";
7
8// import { version } from "../package.json";
9// version has to be hardcoded due to issue #7
10// https://github.com/manferlo81/bundlib/issues/7
11const version = 0.4;
12
13const 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
57export default bundlib;