build.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. const {
  32. OAUTH_AUTHORIZE_ENDPOINT,
  33. OAUTH_CLIENT_ID,
  34. OAUTH_REDIRECT_URI,
  35. OAUTH_CLIENT_SECRET,
  36. OAUTH_USERINFO,
  37. BASE_PATH,
  38. } = process.env;
  39. let authorizeUrl = "";
  40. if (OAUTH_AUTHORIZE_ENDPOINT && OAUTH_CLIENT_ID && OAUTH_REDIRECT_URI) {
  41. authorizeUrl = `${OAUTH_AUTHORIZE_ENDPOINT}?client_id=${OAUTH_CLIENT_ID}&response_type=token&scope=userinfo&redirect_uri=${encodeURIComponent(
  42. OAUTH_REDIRECT_URI,
  43. )}`;
  44. }
  45. return {
  46. version,
  47. ...commitInfo,
  48. buildMode,
  49. isApp,
  50. authorizeUrl,
  51. baseApi: BASE_PATH,
  52. };
  53. };
  54. export type BuildConfig = ReturnType<typeof getBuildConfig>;