Skip to content

Commit

Permalink
chore: website add more build info
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed May 9, 2024
1 parent 73adedb commit cc5cb6b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .dumi/_utils.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions .dumi/plugin.ts
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/')],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cc5cb6b

Please sign in to comment.