-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
33 lines (27 loc) · 837 Bytes
/
index.ts
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
import path from "path";
import fs from "fs";
import { BuildOptions } from "./src/types";
import Module from "./src/module";
import { getModules } from "./src/module";
import { replaceImports } from "./src/imports";
// Start
function build({ entryFile, outputFolder }: BuildOptions): void {
const graph = createDependencyGraph(entryFile);
const outputCode = bundle(graph);
if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder, { recursive: true });
}
fs.writeFileSync(path.join(outputFolder, "bundle.js"), outputCode, "utf-8");
}
function createDependencyGraph(filePath: string): Module {
return new Module(filePath);
}
function bundle(graph: Module) {
const modules = getModules(graph);
const code = replaceImports(modules);
return code;
}
build({
entryFile: "./inputs/index.js",
outputFolder: "./build"
});