postbuild-server.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Post-build script for server compilation.
  3. *
  4. * tspc compiles both `src/` and `config/` (which will be migrated to TypeScript),
  5. * so the output directory (`transpiled/`) mirrors the source tree structure
  6. * (e.g. `transpiled/src/`, `transpiled/config/`).
  7. *
  8. * Setting `rootDir: "src"` and `outDir: "dist"` in tsconfig would eliminate this script,
  9. * but that would break once `config/` is included in the compilation.
  10. * Instead, this script extracts only `transpiled/src/` into `dist/` and discards the rest.
  11. */
  12. import { readdirSync, renameSync, rmSync } from 'node:fs';
  13. const TRANSPILED_DIR = 'transpiled';
  14. const DIST_DIR = 'dist';
  15. const SRC_SUBDIR = `${TRANSPILED_DIR}/src`;
  16. // List transpiled contents for debugging
  17. // biome-ignore lint/suspicious/noConsole: This is a build script, console output is expected.
  18. console.log('Listing files under transpiled:');
  19. // biome-ignore lint/suspicious/noConsole: This is a build script, console output is expected.
  20. console.log(readdirSync(TRANSPILED_DIR).join('\n'));
  21. // Remove old dist
  22. rmSync(DIST_DIR, { recursive: true, force: true });
  23. // Move transpiled/src -> dist
  24. renameSync(SRC_SUBDIR, DIST_DIR);
  25. // Remove leftover transpiled directory
  26. rmSync(TRANSPILED_DIR, { recursive: true, force: true });