Skip to content

Commit

Permalink
feat: add version at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Sep 25, 2024
1 parent d4a2452 commit 05583ed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<body>
<div id="root"></div>
<script src="/env.js"></script>
<script src="/version.js"></script>
<script type="module">
const matomoUrl = import.meta.env.PROD ? window.ENV.VITE_MATOMO_URL : import.meta.env.VITE_MATOMO_URL;

Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cr-vif/frontend",
"private": true,
"version": "1.0.0",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -10,6 +10,7 @@
"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",
"prepare": "pnpm dsfr && panda codegen",
"dsfr": "copy-dsfr-to-public && pnpm panda-ds",
"icons": "only-include-used-icons",
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/scripts/createEnvFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export const createEnvFile = async () => {
.map(([key, value]) => `${key}: "${value}"`)
.join(",\n");

const version = "0.1.0." + Math.floor(Date.now() / 1000).toString(16);

const contentJs = `window.ENV = { ${values}, VERSION: "${version}" };`;
const contentJs = `window.ENV = { ${values} };`;

await fs.writeFile("./dist/env.js", contentJs);
};
Expand Down
11 changes: 11 additions & 0 deletions packages/frontend/scripts/setVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pjson from '../package.json';
import fs from "node:fs/promises";

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);
}

setVersion();

0 comments on commit 05583ed

Please sign in to comment.