-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
executable file
·56 lines (51 loc) · 2.01 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import path from "tiny-paths";
import LocalDrive from "localdrive";
import * as rx from "rxjs";
import {capitalize, camelCase, toArray} from "lodash-es";
import {nanoid} from "nanoid";
import {Find, Adapt, Deploy, Query, Resolve} from "./index.js";
import terser from "@rollup/plugin-terser";
const p = Find.fileURLToPath(import.meta.url);
const __dirname = path.dirname(p);
const projectFolder = new LocalDrive(path.resolve(__dirname, "./"));
import {findDownMultiple$} from "./lib/find/index.js";
console.log("This takes roughly 6-7 minutes on my computer.");
findDownMultiple$(projectFolder, "bundle*.js")
.pipe(
rx.concatMap(o => o.flat()),
rx.map(o => o && path.resolve(__dirname, "." + o)),
rx.filter(o => o && !o.includes("node_modules") && o !== path.resolve(__dirname, "bundle.js")),
rx.mergeMap(async o => await import(o)),
rx.filter(o => !!o.default),
rx.map(({default: module, name}) => [module.code, name]),
rx.reduce((acc, [code, name]) => {
// if (name === "deploy") {
// return acc;
// }
acc[name] = code;
return acc;
}, {}),
rx.switchMap(
(codeBook) => {
const entryName = "e" + camelCase(nanoid());
const entry = Object.keys(codeBook).map(o => `export * as ${capitalize(camelCase(o))} from '${o}'`).join(";");
return Deploy.pack(entryName, "./dist/all.min.js", {
plugins: [
Deploy.rollupVirtualPlugin(
{
...codeBook,
[entryName]: entry
}
),
terser(),
Deploy.rollupFromSourcePlugin(projectFolder, {asInput: false, asOutput: true})
]
})
}
)
)
.subscribe(
result => {
console.log("Bundle done. result", result);
}
);