Skip to content

Commit

Permalink
fix: move git info to separate util
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst committed Feb 6, 2024
1 parent 61d9c37 commit 2fe9839
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 2 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { execSync } from "node:child_process";
import { fileURLToPath } from "node:url";

import { defaultLocale, localesMap } from "./config/i18n.config";
import { getGitInfo } from "./utils/get-git-info";

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const baseUrl = process.env.NUXT_PUBLIC_APP_BASE_URL!;

const branchName = execSync("git rev-parse --abbrev-ref HEAD").toString().trimEnd();
const commitHash = execSync("git rev-parse HEAD").toString().trimEnd();
const tag = execSync("git describe --always --tags").toString().trimEnd();
const { branchName, commitHash, tag } = getGitInfo();

export default defineNuxtConfig({
alias: {
Expand Down
25 changes: 25 additions & 0 deletions utils/get-git-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { execSync } from "node:child_process";

import { log } from "@acdh-oeaw/lib";

export function getGitInfo() {
try {
const branchName = execSync("git rev-parse --abbrev-ref HEAD").toString().trimEnd();
const commitHash = execSync("git rev-parse HEAD").toString().trimEnd();
const tag = execSync("git describe --always --tags").toString().trimEnd();

return {
branchName,
commitHash,
tag,
};
} catch (error) {
log.error("Failed to get git info, using fallback values.");

return {
branchName: "development",
commitHash: "",
tag: "",
};
}
}

0 comments on commit 2fe9839

Please sign in to comment.