chore: website add more build info

This commit is contained in:
wuxh 2024-05-09 13:06:28 +08:00
parent 73adedbfab
commit cc5cb6b33d
No known key found for this signature in database
GPG Key ID: 4E035332466F0370
4 changed files with 75 additions and 1 deletions

58
.dumi/_utils.ts Normal file
View File

@ -0,0 +1,58 @@
import { simpleGit } from 'simple-git';
// @ts-ignore
import envInfo from 'envinfo';
const git = simpleGit({ baseDir: process.cwd() });
const getLatestCommit = () =>
git
.log()
.then(({ latest }) => latest)
.then((res) => res?.hash);
const getEnvInfo = async () => {
const nodeVersion = await envInfo.helpers
.getNodeInfo()
.then((res: any) => (Array.isArray(res) ? res.slice(0, 2).join(' v') : res));
const npmVersion = await envInfo.helpers
.getnpmInfo()
.then((res: any) => (Array.isArray(res) ? res.slice(0, 2).join(' v') : res));
const dumiVersion = await envInfo.helpers.getnpmPackages('dumi').then((res: any) =>
Array.isArray(res)
? Object.entries(res[1])
.map(([key, value]: any) => `${key}@${value?.installed}`)
.join(', ')
: Promise.reject(res),
);
return Promise.allSettled([nodeVersion, npmVersion, dumiVersion]).then((values) =>
values
.reduce<any>((acc, cur) => {
if (cur.status === 'fulfilled') {
acc.push(cur.value);
}
return acc;
}, [])
.join(', '),
);
};
// eslint-disable-next-line import/prefer-default-export
export async function getBuildInfo() {
const info = await Promise.allSettled([
getLatestCommit().then((res) => ({ 'build-hash': res })),
getEnvInfo().then((res) => ({ 'build-env': res })),
]).then((values) =>
values.reduce<any>(
(acc, cur) => (cur.status === 'fulfilled' ? { ...acc, ...cur.value } : acc),
{
'build-time': new Date().toLocaleString('zh-CN', {
timeZone: 'Asia/Shanghai',
hour12: false,
}),
},
),
);
return Object.entries(info).map(([key, value]) => ({ name: key, content: value }));
}

15
.dumi/plugin.ts Normal file
View File

@ -0,0 +1,15 @@
import type { IApi } from 'dumi';
import { getBuildInfo } from './_utils';
let buildInfo: any;
(async () => {
buildInfo = await getBuildInfo();
})();
export default (api: IApi) => {
api.describe({
key: 'antd-website',
});
api.addHTMLMetas(() => buildInfo);
};

View File

@ -7,7 +7,7 @@ import remarkAntd from './.dumi/remarkAntd';
import { version } from './package.json';
export default defineConfig({
plugins: ['dumi-plugin-color-chunk'],
plugins: ['dumi-plugin-color-chunk', './.dumi/plugin'],
conventionRoutes: {
// to avoid generate routes for .dumi/pages/index/components/xx
exclude: [new RegExp('index/components/')],

View File

@ -243,6 +243,7 @@
"dekko": "^0.2.1",
"dumi": "^2.3.2",
"dumi-plugin-color-chunk": "^1.1.0",
"envinfo": "^7.13.0",
"esbuild-loader": "^4.1.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",