build.ts 1.2 KB

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