build.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { DEFAULT_INPUT_TEMPLATE } from "../constant";
  2. export const getBuildConfig = () => {
  3. if (typeof process === "undefined") {
  4. throw Error(
  5. "[Server Config] you are importing a nodejs-only module outside of nodejs",
  6. );
  7. }
  8. const buildMode = process.env.BUILD_MODE ?? "standalone";
  9. const isApp = !!process.env.BUILD_APP;
  10. const version = "v2.16.1"; // Fixed version for web-only build
  11. const commitInfo = (() => {
  12. try {
  13. const childProcess = require("child_process");
  14. const commitDate: string = childProcess
  15. .execSync('git log -1 --format="%at000" --date=unix')
  16. .toString()
  17. .trim();
  18. const commitHash: string = childProcess
  19. .execSync('git log --pretty=format:"%H" -n 1')
  20. .toString()
  21. .trim();
  22. return { commitDate, commitHash };
  23. } catch (e) {
  24. console.error("[Build Config] No git or not from git repo.");
  25. return {
  26. commitDate: "unknown",
  27. commitHash: "unknown",
  28. };
  29. }
  30. })();
  31. return {
  32. version,
  33. ...commitInfo,
  34. buildMode,
  35. isApp,
  36. template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE,
  37. };
  38. };
  39. export type BuildConfig = ReturnType<typeof getBuildConfig>;