ChatGPT-Next-Web/app/config/build.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

import tauriConfig from "../../src-tauri/tauri.conf.json";
import { DEFAULT_INPUT_TEMPLATE } from "../constant";
2023-04-10 17:21:34 +00:00
export const getBuildConfig = () => {
if (typeof process === "undefined") {
throw Error(
"[Server Config] you are importing a nodejs-only module outside of nodejs",
);
}
const buildMode = process.env.BUILD_MODE ?? "standalone";
const isApp = !!process.env.BUILD_APP;
2023-06-29 18:35:40 +00:00
const version = "v" + tauriConfig.package.version;
const commitInfo = (() => {
try {
const childProcess = require("child_process");
const commitDate: string = childProcess
.execSync('git log -1 --format="%at000" --date=unix')
.toString()
.trim();
const commitHash: string = childProcess
.execSync('git log --pretty=format:"%H" -n 1')
.toString()
.trim();
return { commitDate, commitHash };
} catch (e) {
console.error("[Build Config] No git or not from git repo.");
return {
commitDate: "unknown",
commitHash: "unknown",
};
}
})();
2023-04-10 17:21:34 +00:00
return {
version,
...commitInfo,
buildMode,
isApp,
template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE,
2023-04-10 17:21:34 +00:00
};
};
export type BuildConfig = ReturnType<typeof getBuildConfig>;