build.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import tauriConfig from "../../src-tauri/tauri.conf.json";
  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 = "v" + tauriConfig.package.version;
  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. };
  37. };
  38. export type BuildConfig = ReturnType<typeof getBuildConfig>;