From ecc0487c0259eea47104190a07c9f095616a6fda Mon Sep 17 00:00:00 2001 From: ledouxm Date: Mon, 7 Oct 2024 11:09:02 +0200 Subject: [PATCH] feat: add version display in footer --- packages/frontend/package.json | 6 +- packages/frontend/public/version.js | 1 + packages/frontend/scripts/setVersion.ts | 15 ++-- packages/frontend/src/routes/__root.tsx | 105 ++++++++++++++++++++++-- packages/frontend/vite.config.ts | 1 + 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 packages/frontend/public/version.js diff --git a/packages/frontend/package.json b/packages/frontend/package.json index c7828e88..fd9011c0 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -5,12 +5,12 @@ "type": "module", "scripts": { "dev": "vite", - "build": "pnpm icons && vite build", - "build:only": "vite build", + "build": "pnpm icons && pnpm build:only", + "build:only": "vite build && pnpm version:gen", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "pnpm env:gen && vite preview --host", "env:gen": "vite-node ./scripts/createEnvFile.ts", - "version": "vite-node ./scripts/setVersion.ts", + "version:gen": "vite-node ./scripts/setVersion.ts", "prepare": "pnpm dsfr && panda codegen", "dsfr": "copy-dsfr-to-public && pnpm panda-ds", "icons": "only-include-used-icons", diff --git a/packages/frontend/public/version.js b/packages/frontend/public/version.js new file mode 100644 index 00000000..ebed3dd2 --- /dev/null +++ b/packages/frontend/public/version.js @@ -0,0 +1 @@ +window.APP_VERSION = "0.0.0.dev"; diff --git a/packages/frontend/scripts/setVersion.ts b/packages/frontend/scripts/setVersion.ts index 0942871b..0b5b97c1 100644 --- a/packages/frontend/scripts/setVersion.ts +++ b/packages/frontend/scripts/setVersion.ts @@ -1,11 +1,12 @@ -import pjson from '../package.json'; -import fs from "node:fs/promises"; +import pjson from "../package.json"; +import fs from "node:fs"; const version = pjson.version + "." + Math.floor(Date.now() / 1000).toString(16); -const setVersion = async () => { - const contentJs = `window.APP_VERSION = "${version}";`; - await fs.writeFile("./dist/version.js", contentJs); -} +const setVersion = () => { + console.log("Setting version to", version); + const contentJs = `window.APP_VERSION = "${version}";`; + fs.writeFileSync("./dist/version.js", contentJs); +}; -setVersion(); \ No newline at end of file +setVersion(); diff --git a/packages/frontend/src/routes/__root.tsx b/packages/frontend/src/routes/__root.tsx index 1f9b6c07..96f9787d 100644 --- a/packages/frontend/src/routes/__root.tsx +++ b/packages/frontend/src/routes/__root.tsx @@ -1,17 +1,16 @@ import { ReportSearch } from "#components/ReportSearch.js"; import { css } from "#styled-system/css"; -import { Box, Flex, Stack, styled } from "#styled-system/jsx"; +import { Box, Flex, styled } from "#styled-system/jsx"; import Badge from "@codegouvfr/react-dsfr/Badge"; import Button from "@codegouvfr/react-dsfr/Button"; -import Footer from "@codegouvfr/react-dsfr/Footer"; import Header from "@codegouvfr/react-dsfr/Header/Header"; import MuiDsfrThemeProvider from "@codegouvfr/react-dsfr/mui"; import { createRootRouteWithContext, Outlet, useRouter } from "@tanstack/react-router"; import { useRef, type PropsWithChildren } from "react"; import type { RouterOutputs } from "../api"; import { useIsLoggedIn } from "../contexts/AuthContext"; -import { useIsDesktop } from "../hooks/useIsDesktop"; import { MenuButton } from "../features/menu/MenuButton"; +import { useIsDesktop } from "../hooks/useIsDesktop"; export const Route = createRootRouteWithContext>>()({ beforeLoad: (ctx) => { @@ -135,15 +134,107 @@ const Layout = ({ children }: PropsWithChildren) => { {children} {/* */} -