refactor: consolidate single-source routing and protocol helpers

This commit is contained in:
Cita
2026-03-22 21:27:09 +08:00
parent 96e7614835
commit 9290e51ecc
64 changed files with 3571 additions and 2681 deletions
+20 -2
View File
@@ -1,14 +1,22 @@
import { cpSync, existsSync, mkdirSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { cpSync, existsSync, mkdirSync, rmSync, statSync } from 'node:fs';
import { basename, dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
function resolveRepoRoot(): string {
return resolve(dirname(fileURLToPath(import.meta.url)), '../..');
}
function shouldCopySharedArtifact(sourcePath: string): boolean {
if (statSync(sourcePath).isDirectory()) return true;
const filename = basename(sourcePath);
return filename.endsWith('.js') || filename.endsWith('.d.ts');
}
export function copyRuntimeDbGeneratedAssets(repoRoot: string = resolveRepoRoot()): void {
const sourceDir = resolve(repoRoot, 'src/server/db/generated');
const targetDir = resolve(repoRoot, 'dist/server/db/generated');
const sharedSourceDir = resolve(repoRoot, 'src/shared');
const sharedTargetDir = resolve(repoRoot, 'dist/shared');
if (!existsSync(sourceDir)) {
throw new Error(`Runtime DB generated assets directory does not exist: ${sourceDir}`);
@@ -16,6 +24,16 @@ export function copyRuntimeDbGeneratedAssets(repoRoot: string = resolveRepoRoot(
mkdirSync(dirname(targetDir), { recursive: true });
cpSync(sourceDir, targetDir, { recursive: true, force: true });
if (existsSync(sharedSourceDir)) {
rmSync(sharedTargetDir, { recursive: true, force: true });
mkdirSync(dirname(sharedTargetDir), { recursive: true });
cpSync(sharedSourceDir, sharedTargetDir, {
recursive: true,
force: true,
filter: (sourcePath) => shouldCopySharedArtifact(sourcePath),
});
}
}
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {