fix: make build script typecheck
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import { copyFile } from "node:fs/promises";
|
import { copyFile } from "node:fs/promises";
|
||||||
|
import { readdirSync } from "node:fs";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
|
||||||
type BuildStep = {
|
type BuildStep = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -23,9 +25,16 @@ const steps: BuildStep[] = [
|
|||||||
|
|
||||||
const startedAt = performance.now();
|
const startedAt = performance.now();
|
||||||
|
|
||||||
try {
|
main().catch((error: unknown) => {
|
||||||
const appEntries = Array.from(new Bun.Glob("*.ts").scanSync("./static"))
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
.map((file) => `./static/${file}`)
|
console.error(`ts build failed: ${message}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const appEntries = readdirSync("./static", { withFileTypes: true })
|
||||||
|
.filter((entry) => entry.isFile() && entry.name.endsWith(".ts"))
|
||||||
|
.map((entry) => `./static/${entry.name}`)
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
steps.push({
|
steps.push({
|
||||||
@@ -46,15 +55,14 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const step of steps) {
|
for (const step of steps) {
|
||||||
const result = Bun.spawnSync(step.command, {
|
const result = spawnSync(step.command[0], step.command.slice(1), {
|
||||||
stdout: "pipe",
|
stdio: "pipe",
|
||||||
stderr: "pipe",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.exitCode !== 0) {
|
if (result.status !== 0) {
|
||||||
const detail = summarizeFailure(result.stderr, result.stdout);
|
const detail = summarizeFailure(result.stderr, result.stdout);
|
||||||
console.error(`ts build failed at ${step.name}${detail === "" ? "" : `: ${detail}`}`);
|
console.error(`ts build failed at ${step.name}${detail === "" ? "" : `: ${detail}`}`);
|
||||||
process.exit(result.exitCode);
|
process.exit(result.status ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,10 +73,6 @@ try {
|
|||||||
const elapsedMs = Math.round(performance.now() - startedAt);
|
const elapsedMs = Math.round(performance.now() - startedAt);
|
||||||
|
|
||||||
console.log(`ts build ok (${totalEntries} entries, ${elapsedMs}ms)`);
|
console.log(`ts build ok (${totalEntries} entries, ${elapsedMs}ms)`);
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
|
||||||
console.error(`ts build failed: ${message}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function summarizeFailure(stderr: Uint8Array, stdout: Uint8Array): string {
|
function summarizeFailure(stderr: Uint8Array, stdout: Uint8Array): string {
|
||||||
@@ -82,5 +86,5 @@ function summarizeFailure(stderr: Uint8Array, stdout: Uint8Array): string {
|
|||||||
.map((line) => line.trim())
|
.map((line) => line.trim())
|
||||||
.filter((line) => line !== "");
|
.filter((line) => line !== "");
|
||||||
|
|
||||||
return lines.at(-1) ?? "";
|
return lines[lines.length - 1] ?? "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user