The best way to control Claude Code, Codex and more from any computer or phone

main
ts 32 lines 1.2 KB
Raw
1 // Mirrors `@cloudflare/vite-plugin`'s `playground/custom-build-app`: the
2 // user's `buildApp` drives the builds (the Worker environment twice, as some
3 // plugins do). Each step is also appended to `build-app.log` for the test.
4 import assert from "node:assert";
5 import * as fs from "node:fs";
6 import * as path from "node:path";
7 import type { ViteBuilder } from "vite";
8
9 const record = (step: string) =>
10 fs.appendFileSync(path.join(import.meta.dirname, "build-app.log"), `${step}\n`);
11
12 export default {
13 builder: {
14 async buildApp(builder: ViteBuilder) {
15 const workerEnvironment = builder.environments.ssr;
16 const clientEnvironment = builder.environments.client;
17
18 assert(workerEnvironment, `No "ssr" environment`);
19 assert(clientEnvironment, `No "client" environment`);
20
21 builder.config.logger.info("__before-build__");
22 record("__before-build__");
23 await builder.build(workerEnvironment);
24 // Some plugins build the Worker environment twice so we do that here to test this scenario
25 await builder.build(workerEnvironment);
26 builder.config.logger.info("__after-build__");
27 record("__after-build__");
28
29 await builder.build(clientEnvironment);
30 },
31 },
32 };