Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c0273c7

Browse files
committed
Support build.ts instead of server.build.prebuild
1 parent fadcb35 commit c0273c7

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

commands/build.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
1+
import { basename, resolve } from "https://deno.land/[email protected]/path/mod.ts";
22
import { findFile } from "../lib/fs.ts";
33
import log, { blue, bold } from "../lib/log.ts";
44
import { build } from "../server/build.ts";
@@ -21,7 +21,17 @@ if (import.meta.main) {
2121
const moduleLoaders = await initModuleLoaders(importMap);
2222
await proxyModules(6060, { importMap, moduleLoaders });
2323

24-
let serverEntry = await findFile(builtinModuleExts.map((ext) => `server.${ext}`));
24+
let [serverEntry, buildScript] = await Promise.all([
25+
findFile(builtinModuleExts.map((ext) => `server.${ext}`)),
26+
findFile(builtinModuleExts.map((ext) => `build.${ext}`)),
27+
]);
28+
29+
if (buildScript) {
30+
log.info(`Running ${blue(basename(buildScript))}...`);
31+
const { default: build } = await import(`file://${resolve(buildScript)}`);
32+
await build();
33+
}
34+
2535
if (serverEntry) {
2636
await import(
2737
`http://localhost:${Deno.env.get("ALEPH_MODULES_PROXY_PORT")}/${basename(serverEntry)}?t=${

commands/dev.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename, relative } from "https://deno.land/[email protected]/path/mod.ts";
1+
import { basename, relative, resolve } from "https://deno.land/[email protected]/path/mod.ts";
22
import mitt, { Emitter } from "https://esm.sh/[email protected]";
33
import { findFile, watchFs } from "../lib/fs.ts";
44
import log, { blue } from "../lib/log.ts";
@@ -130,12 +130,19 @@ if (import.meta.main) {
130130
});
131131

132132
const emitter = createEmitter();
133-
const [denoConfigFile, importMapFile, serverEntry] = await Promise.all([
133+
const [denoConfigFile, importMapFile, serverEntry, buildScript] = await Promise.all([
134134
findFile(["deno.jsonc", "deno.json", "tsconfig.json"]),
135135
findFile(["import_map", "import-map", "importmap", "importMap"].map((v) => `${v}.json`)),
136136
findFile(builtinModuleExts.map((ext) => `server.${ext}`)),
137+
findFile(builtinModuleExts.map((ext) => `build.${ext}`)),
137138
]);
138139

140+
if (buildScript) {
141+
log.info(`Running ${blue(basename(buildScript))}...`);
142+
const { default: build } = await import(`file://${resolve(buildScript)}`);
143+
await build();
144+
}
145+
139146
let ac: AbortController | null = null;
140147
const bs = async () => {
141148
if (Deno.env.get("PREVENT_SERVER_RESTART") === "true") {
@@ -210,14 +217,10 @@ async function bootstrap(signal: AbortSignal, entry: string | undefined, fixedPo
210217
serve();
211218
}
212219

213-
const { devServer, build }: AlephConfig = Reflect.get(globalThis, "__ALEPH_CONFIG") || {};
220+
const { devServer }: AlephConfig = Reflect.get(globalThis, "__ALEPH_CONFIG") || {};
214221
const { port: userPort, hostname, certFile, keyFile, handler } = Reflect.get(globalThis, "__ALEPH_SERVER") || {};
215222
const port = fixedPort || userPort || 8080;
216223

217-
if (typeof build?.preBuild === "function") {
218-
log.info("Pre-build...");
219-
await build.preBuild();
220-
}
221224
if (typeof devServer?.watchFS === "function") {
222225
const { watchFS } = devServer;
223226
const e = createEmitter();

commands/start.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename, join } from "https://deno.land/[email protected]/path/mod.ts";
1+
import { basename, join, resolve } from "https://deno.land/[email protected]/path/mod.ts";
22
import { serve as stdServe, serveTls } from "https://deno.land/[email protected]/http/server.ts";
33
import { findFile } from "../lib/fs.ts";
44
import log, { blue } from "../lib/log.ts";
@@ -24,7 +24,17 @@ if (import.meta.main) {
2424
const moduleLoaders = await initModuleLoaders(importMap);
2525
await proxyModules(6060, { importMap, moduleLoaders, signal: ac.signal });
2626

27-
let serverEntry = await findFile(builtinModuleExts.map((ext) => `server.${ext}`));
27+
let [serverEntry, buildScript] = await Promise.all([
28+
findFile(builtinModuleExts.map((ext) => `server.${ext}`)),
29+
findFile(builtinModuleExts.map((ext) => `build.${ext}`)),
30+
]);
31+
32+
if (buildScript) {
33+
log.info(`Running ${blue(basename(buildScript))}...`);
34+
const { default: build } = await import(`file://${resolve(buildScript)}`);
35+
await build();
36+
}
37+
2838
if (serverEntry) {
2939
await import(
3040
`http://localhost:${Deno.env.get("ALEPH_MODULES_PROXY_PORT")}/${basename(serverEntry)}?t=${

server/build.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export async function build(serverEntry?: string) {
4141
const jsxCofig = await loadJSXConfig(importMap);
4242
const moduleLoaders = await initModuleLoaders(importMap);
4343
const config: AlephConfig | undefined = Reflect.get(globalThis, "__ALEPH_CONFIG");
44-
const preBuild = config?.build?.preBuild;
4544
const platform = config?.build?.platform ?? "deno";
4645
const target = config?.build?.target ?? "es2020";
4746
const outputDir = join(workingDir, config?.build?.outputDir ?? "dist");
@@ -60,11 +59,6 @@ export async function build(serverEntry?: string) {
6059
await Deno.mkdir(outputDir, { recursive: true });
6160
}
6261

63-
if (typeof preBuild === "function") {
64-
log.info("Pre-build...");
65-
await preBuild();
66-
}
67-
6862
// find route files by the `routes` config
6963
let routeFiles: [filename: string, exportNames: string[]][] = [];
7064
if (config?.routes) {

server/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export type BuildPlatform = "deno" | "cloudflare" | "vercel";
1818

1919
/** The build options for `build` command. */
2020
export type BuildOptions = {
21-
/** The Pre-build task. */
22-
preBuild?: () => Promise<void> | void;
2321
/** The supported platform. default is "deno" */
2422
platform?: BuildPlatform;
2523
/** The directory for build output files. default is "dist" */

0 commit comments

Comments
 (0)