Skip to content

Commit

Permalink
feat: add link to GitHub with current app version text in account menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Jun 30, 2024
1 parent 6c8460e commit be726bc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
11 changes: 11 additions & 0 deletions components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
import type { DropdownItem } from "#ui/types";
const { signOut, user } = useAuth();
const {
public: { appVersion },
} = useRuntimeConfig();
const toast = useToast();
Expand Down Expand Up @@ -89,6 +92,14 @@ const items = computed((): DropdownItem[][] => [
label: user.value?.name ?? "",
},
],
[
{
label: `Luonto ${appVersion}`,
icon: "i-ph-github-logo-bold",
href: "https://github.com/SegaraRai/luonto",
target: "_blank",
},
],
[
{
label: "サインアウト",
Expand Down
35 changes: 30 additions & 5 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import path from "node:path";
import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { env } from "node:process";
import { fileURLToPath } from "node:url";
import { createNitroSWPreset } from "./nitroSWPreset";

function fromProjectDir(path: string): string {
return fileURLToPath(new URL(path, import.meta.url));
}

function getAppVersion(): string {
if (env.NODE_ENV === "development" || env.NODE_ENV === "test") {
return "[dev]";
}

const pkg = JSON.parse(readFileSync(fromProjectDir("package.json"), "utf-8"));

const { stdout } = spawnSync("git", ["rev-parse", "--short", "HEAD"], {
encoding: "utf-8",
});

const pkgVersion = pkg.version;
const commitHash = stdout.trim();

return `v${pkgVersion} (${commitHash})`;
}

const nitro =
process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test"
env.NODE_ENV === "development" || env.NODE_ENV === "test"
? {}
: {
...createNitroSWPreset({
swEntry: path.resolve(__dirname, "swEntry.ts"),
prerenderEntry: path.resolve(__dirname, "prerenderEntry.ts"),
swEntry: fromProjectDir("swEntry.ts"),
prerenderEntry: fromProjectDir("prerenderEntry.ts"),
fallbackBase: "loading.html",
fallbackFiles: ["index.html", "200.html", "404.html"],
}),
Expand Down Expand Up @@ -36,10 +60,11 @@ export default defineNuxtConfig({
authJs: {
baseUrl: "https://service-worker",
},
appVersion: getAppVersion(),
},
},
alias: {
cookie: path.resolve(__dirname, "node_modules/cookie"),
cookie: fromProjectDir("node_modules/cookie"),
},
ui: {
safelistColors: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "luonto",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
Expand Down

0 comments on commit be726bc

Please sign in to comment.