This commit is contained in:
Morten Olsen
2023-03-26 22:15:07 +02:00
commit 9b1a067d56
80 changed files with 7889 additions and 0 deletions

40
bin/index.ts Normal file
View File

@@ -0,0 +1,40 @@
import { program } from "commander";
import { build } from "./build";
import { createServer } from "./dev/server";
import { dirname, join, resolve } from "path";
import { mkdir, rm, writeFile } from "fs/promises";
import { existsSync } from "fs";
const dev = program.command("dev");
dev.action(async () => {
const bundler = await build();
const server = createServer(bundler);
server.listen(3000);
});
const bundle = program.command("build");
bundle.action(async () => {
const bundler = await build();
const outputDir = resolve("out");
if (existsSync(outputDir)) {
rm(outputDir, { recursive: true });
}
for (let path of bundler.paths) {
await bundler.get(path)?.data;
}
for (let path of bundler.paths) {
const asset = bundler.get(path);
if (!asset) {
throw new Error(`Asset not found for path: ${path}`);
}
const content = await asset.data;
const target = join(outputDir, path);
const targetDir = dirname(target);
await mkdir(targetDir, { recursive: true });
await writeFile(target, content.content);
console.log(`Wrote ${target}`);
}
process.exit(0);
});
program.parse(process.argv);