mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-02 13:23:09 +03:00
Merge pull request #523 from toeverything/chore/print-build-info
chore: print build info
This commit is contained in:
commit
0a57e29f2b
@ -1,10 +1,23 @@
|
||||
const withTM = require('next-transpile-modules')(['@toeverything/pathfinder-logger']);
|
||||
// @ts-check
|
||||
const withTM = require('next-transpile-modules')([
|
||||
'@toeverything/pathfinder-logger',
|
||||
]);
|
||||
|
||||
const { getGitVersion, getCommitHash } = require('./scripts/gitInfo');
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = withTM({
|
||||
productionBrowserSourceMaps: true,
|
||||
reactStrictMode: true,
|
||||
swcMinify: false,
|
||||
publicRuntimeConfig: {
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
PROJECT_NAME: process.env.npm_package_name,
|
||||
BUILD_DATE: new Date().toISOString(),
|
||||
CI: process.env.CI || null,
|
||||
VERSION: getGitVersion(),
|
||||
COMMIT_HASH: getCommitHash(),
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = nextConfig;
|
||||
|
46
packages/app/scripts/gitInfo.js
Normal file
46
packages/app/scripts/gitInfo.js
Normal file
@ -0,0 +1,46 @@
|
||||
// @ts-check
|
||||
|
||||
// import { execSync } from 'child_process'
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const hasGit = () => {
|
||||
try {
|
||||
execSync('git --version');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const getTopLevel = () => execSync('git rev-parse --show-toplevel');
|
||||
const isRepository = () => {
|
||||
try {
|
||||
getTopLevel();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const getGitVersion = () => {
|
||||
if (!hasGit() || !isRepository()) {
|
||||
console.error(
|
||||
"You haven't installed git or it does not exist in your PATH."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
const VERSION = execSync('git describe --always --dirty')
|
||||
.toString()
|
||||
// remove empty line
|
||||
.replace(/[\s\r\n]+$/, '');
|
||||
|
||||
return VERSION;
|
||||
};
|
||||
|
||||
const getCommitHash = (rev = 'HEAD') =>
|
||||
execSync(`git rev-parse --short ${rev}`).toString();
|
||||
|
||||
module.exports = {
|
||||
getGitVersion,
|
||||
getCommitHash,
|
||||
};
|
@ -9,6 +9,7 @@ import { Logger } from '@toeverything/pathfinder-logger';
|
||||
|
||||
import '@fontsource/space-mono';
|
||||
import '@fontsource/poppins';
|
||||
import '../utils/print-build-info';
|
||||
|
||||
const ThemeProvider = dynamic(() => import('@/styles/themeProvider'), {
|
||||
ssr: false,
|
||||
|
43
packages/app/src/utils/print-build-info.ts
Normal file
43
packages/app/src/utils/print-build-info.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import getConfig from 'next/config';
|
||||
|
||||
type Config = {
|
||||
BUILD_DATE: string;
|
||||
NODE_ENV: string;
|
||||
PROJECT_NAME: string;
|
||||
VERSION: string;
|
||||
CI?: string;
|
||||
COMMIT_HASH: string;
|
||||
};
|
||||
|
||||
const nextConfig = getConfig();
|
||||
const publicRuntimeConfig: Config = nextConfig.publicRuntimeConfig;
|
||||
|
||||
const printBuildInfo = () => {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return;
|
||||
}
|
||||
console.group('Build info');
|
||||
console.log('Project:', publicRuntimeConfig.PROJECT_NAME);
|
||||
console.log(
|
||||
'Build date:',
|
||||
publicRuntimeConfig.BUILD_DATE
|
||||
? new Date(publicRuntimeConfig.BUILD_DATE).toLocaleString()
|
||||
: 'Unknown'
|
||||
);
|
||||
console.log(
|
||||
'Environment:',
|
||||
`${publicRuntimeConfig.NODE_ENV}${publicRuntimeConfig.CI ? '(ci)' : ''}`
|
||||
);
|
||||
console.log('Version:', publicRuntimeConfig.VERSION);
|
||||
console.log(
|
||||
'AFFiNE is an open source project, you can view its source code on GitHub!'
|
||||
);
|
||||
console.log(
|
||||
`https://github.com/toeverything/AFFiNE/tree/${publicRuntimeConfig.COMMIT_HASH}`
|
||||
);
|
||||
console.groupEnd();
|
||||
};
|
||||
|
||||
printBuildInfo();
|
||||
|
||||
export {};
|
Loading…
Reference in New Issue
Block a user