feat: Show the build date on the loading banner of unreleased builds (#2659)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Vite plugin: writes the date of the build into the card.
|
||||
*/
|
||||
|
||||
// Strict length requirement: See below.
|
||||
export const BUILD_DATE_PLACEHOLDER = '__BUILD_DATE_SENTINEL___';
|
||||
|
||||
/**
|
||||
* The date cannot be handed to the bundler as a substituted name, because the
|
||||
* build configuration is evaluated once and `vite build --watch` reuses it.
|
||||
* As such, every rebuild would report the time the watcher started rather than
|
||||
* the actual build time. Output is generated afresh for each build, so the date
|
||||
* is written here instead.
|
||||
*
|
||||
* @type {() => import('vite').Plugin}
|
||||
*/
|
||||
export const buildDate = () => ({
|
||||
name: 'build-date',
|
||||
|
||||
renderChunk(code) {
|
||||
if (!code.includes(BUILD_DATE_PLACEHOLDER)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const date = new Date().toISOString();
|
||||
if (date.length !== BUILD_DATE_PLACEHOLDER.length) {
|
||||
this.error(
|
||||
'The build date must be exactly as long as the placeholder it replaces.',
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
code: code.replaceAll(BUILD_DATE_PLACEHOLDER, date),
|
||||
|
||||
// The replacement is exactly as long as what it replaces, so the existing
|
||||
// sourcemap still describes the code.
|
||||
map: null,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -1,6 +1,8 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
import { BUILD_DATE_PLACEHOLDER } from './build-date-plugin.js';
|
||||
|
||||
/**
|
||||
* Asks git something or gives back nothing when it cannot be asked.
|
||||
*/
|
||||
@@ -23,7 +25,11 @@ const getPackageVersion = () =>
|
||||
*
|
||||
* `releaseVersion` is the version being released, which only the release
|
||||
* workflow knows; a build without one reports the version in `package.json`, or
|
||||
* a development build the commit it was made from.
|
||||
* a development build the commit it was made from. Its presence is what makes a
|
||||
* build a released one.
|
||||
*
|
||||
* The build date is a placeholder here, written in for by the `buildDate`
|
||||
* plugin as each build's output is generated.
|
||||
*
|
||||
* The values are JSON so that a bundler can drop them in as written.
|
||||
*/
|
||||
@@ -35,10 +41,11 @@ export const getBuildDefines = ({ dev, releaseVersion }) => {
|
||||
__ADVANCED_CAMERA_CARD_RELEASE_VERSION__: JSON.stringify(
|
||||
releaseVersion ?? (dev ? developmentVersion : getPackageVersion()),
|
||||
),
|
||||
__ADVANCED_CAMERA_CARD_IS_RELEASE_BUILD__: JSON.stringify(!!releaseVersion),
|
||||
__ADVANCED_CAMERA_CARD_GIT_HASH__: JSON.stringify(gitHash),
|
||||
__ADVANCED_CAMERA_CARD_GIT_DATE__: JSON.stringify(
|
||||
askGit('log', '-1', '--format=%cI'),
|
||||
),
|
||||
__ADVANCED_CAMERA_CARD_BUILD_DATE__: JSON.stringify(new Date().toISOString()),
|
||||
__ADVANCED_CAMERA_CARD_BUILD_DATE__: JSON.stringify(BUILD_DATE_PLACEHOLDER),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user