feat(web): separate build sources and localize time
This commit is contained in:
1 parent
89cd92f7ee
commit
10aa0304e4
9 files changed
+60
-17
No files matched your search
Vendored
+4
-2
@@ -1,6 +1,8 @@
|
||||
declare const __WEBDROP_BUILD_INFO__: {
|
||||
readonly frontendVersion: string;
|
||||
readonly commit: string;
|
||||
readonly tag: string;
|
||||
readonly frontendCommit: string;
|
||||
readonly frontendTag: string;
|
||||
readonly backendCommit: string;
|
||||
readonly backendTag: string;
|
||||
readonly builtAt: string;
|
||||
};
|
||||
@@ -99,10 +99,9 @@ export function Home() {
|
||||
</main>
|
||||
|
||||
<aside className={styles.buildInfo} aria-label="构建信息">
|
||||
<span>前端 v{buildInfo.frontendVersion}</span>
|
||||
<span>tag {buildInfo.tag && buildInfo.tag !== 'unknown' ? buildInfo.tag : '未标记'}</span>
|
||||
<span>commit {buildInfo.commit}</span>
|
||||
<time dateTime={buildInfo.builtAt}>{buildInfo.builtAt} UTC</time>
|
||||
<span>前端 v{buildInfo.frontendVersion} · tag {buildInfo.frontendTag || '未标记'} · commit {buildInfo.frontendCommit}</span>
|
||||
<span>后端 tag {buildInfo.backendTag || '未标记'} · commit {buildInfo.backendCommit}</span>
|
||||
<time dateTime={buildInfo.builtAt}>构建时间 {buildInfo.builtAtShanghai}</time>
|
||||
</aside>
|
||||
|
||||
{createOpen ? <CreateSheet onClose={() => setCreateOpen(false)} onCreated={open} /> : null}
|
||||
|
||||
@@ -1 +1,37 @@
|
||||
export const buildInfo = __WEBDROP_BUILD_INFO__;
|
||||
const shanghaiTime = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
});
|
||||
|
||||
function shortCommit(commit: string): string {
|
||||
return commit === 'unknown' ? commit : commit.slice(0, 7);
|
||||
}
|
||||
|
||||
function knownTag(tag: string): string {
|
||||
return tag === 'unknown' ? '' : tag;
|
||||
}
|
||||
|
||||
function formatShanghai(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) return '未知';
|
||||
|
||||
const parts = Object.fromEntries(shanghaiTime.formatToParts(date).map(({ type, value }) => [type, value]));
|
||||
return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
|
||||
}
|
||||
|
||||
const source = __WEBDROP_BUILD_INFO__;
|
||||
|
||||
export const buildInfo = {
|
||||
frontendVersion: source.frontendVersion,
|
||||
frontendCommit: shortCommit(source.frontendCommit),
|
||||
frontendTag: knownTag(source.frontendTag),
|
||||
backendCommit: shortCommit(source.backendCommit),
|
||||
backendTag: knownTag(source.backendTag),
|
||||
builtAt: source.builtAt,
|
||||
builtAtShanghai: formatShanghai(source.builtAt),
|
||||
};
|
||||
+4
-2
@@ -17,8 +17,10 @@ function gitValue(...args: string[]): string {
|
||||
|
||||
const buildInfo = {
|
||||
frontendVersion: webPackage.version,
|
||||
commit: process.env.WEBDROP_BUILD_COMMIT ?? gitValue('rev-parse', '--short=12', 'HEAD'),
|
||||
tag: process.env.WEBDROP_BUILD_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'),
|
||||
frontendCommit: process.env.WEBDROP_FRONTEND_COMMIT ?? gitValue('rev-parse', 'HEAD'),
|
||||
frontendTag: process.env.WEBDROP_FRONTEND_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'),
|
||||
backendCommit: process.env.WEBDROP_BACKEND_COMMIT ?? gitValue('rev-parse', 'HEAD'),
|
||||
backendTag: process.env.WEBDROP_BACKEND_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'),
|
||||
builtAt: process.env.WEBDROP_BUILD_TIME ?? new Date().toISOString(),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user