build.ts 700 B

123456789101112131415161718192021222324252627
  1. export const getBuildConfig = () => {
  2. if (typeof process === "undefined") {
  3. throw Error(
  4. "[Server Config] you are importing a nodejs-only module outside of nodejs",
  5. );
  6. }
  7. const COMMIT_ID: string = (() => {
  8. try {
  9. const childProcess = require("child_process");
  10. return childProcess
  11. .execSync('git log -1 --format="%at000" --date=unix')
  12. .toString()
  13. .trim();
  14. } catch (e) {
  15. console.error("[Build Config] No git or not from git repo.");
  16. return "unknown";
  17. }
  18. })();
  19. return {
  20. commitId: COMMIT_ID,
  21. buildMode: process.env.BUILD_MODE ?? "standalone",
  22. };
  23. };
  24. export type BuildConfig = ReturnType<typeof getBuildConfig>;