Skip to content

Commit

Permalink
feat: add version hash
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Mar 30, 2024
1 parent 53b8b91 commit 143d646
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
27 changes: 23 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import { execSync } from 'child_process'
import path from 'path'
import { config } from 'dotenv'

import NextBundleAnalyzer from '@next/bundle-analyzer'

// const pkg = require('./package.json')
import pkg from './package.json' assert {type: 'json'}

process.title = 'Shiro (NextJS)'

const env = config().parsed || {}
const isProd = process.env.NODE_ENV === 'production'

let commitHash = ''

try {
commitHash = execSync('git log --pretty=format:"%h" -n1')
.toString()
.trim()
} catch (err) {
console.error('Error getting commit hash', err)
}

/** @type {import('next').NextConfig} */
// eslint-disable-next-line import/no-mutable-exports
let nextConfig = {
logging: {
fetches: {
fullUrl: true,
},
},
env: {
APP_VERSION: pkg.version,
COMMIT_HASH: commitHash,
},
reactStrictMode: true,
productionBrowserSourceMaps: false,
output: 'standalone',
Expand All @@ -21,10 +44,6 @@ let nextConfig = {
experimental: {
serverMinification: true,

// @see https://vercel.com/blog/version-skew-protection
// useDeploymentId: true,
// useDeploymentIdServerActions: true,

webpackBuildWorker: true,
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Shiro",
"name": "Shiroi",
"license": "AGPL-3.0",
"private": false,
"version": "1.0.2",
Expand Down
22 changes: 19 additions & 3 deletions src/components/layout/footer/FooterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { FooterConfig } from './config'

import { IonIosArrowDown } from '~/components/icons/arrow'
import { SubscribeTextButton } from '~/components/modules/subscribe/SubscribeTextButton'
import { FloatPopover } from '~/components/ui/float-popover'
import { MLink } from '~/components/ui/link'
import { clsxm } from '~/lib/helper'
import { getQueryClient } from '~/lib/query-client.server'
import { queries } from '~/queries/definition'
Expand Down Expand Up @@ -114,9 +116,23 @@ const PoweredBy: Component = ({ className }) => {
Mix Space
</StyledLink>
<span className="mx-1">&</span>
<StyledLink href="https://github.com/innei/Shiro" target="_blank">
Shiro
</StyledLink>
<FloatPopover
isDisabled={!process.env.COMMIT_HASH}
type="tooltip"
triggerElement={
<StyledLink href="https://github.com/innei/Shiro" target="_blank">
Shiro
</StyledLink>
}
>
{process.env.COMMIT_HASH && (
<MLink
href={`https://github.com/innei/Shiro/commit/${process.env.COMMIT_HASH}`}
>
开源版本哈希:{process.env.COMMIT_HASH}
</MLink>
)}
</FloatPopover>
.
</span>
)
Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/link/MLink.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { memo, useCallback } from 'react'
import { useRouter } from 'next/navigation'
import type { FC, ReactNode } from 'react'
Expand Down

0 comments on commit 143d646

Please sign in to comment.