mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 12:39:49 +08:00
chore: website add more build info
This commit is contained in:
parent
73adedbfab
commit
cc5cb6b33d
58
.dumi/_utils.ts
Normal file
58
.dumi/_utils.ts
Normal 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
15
.dumi/plugin.ts
Normal 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);
|
||||
};
|
@ -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/')],
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user