mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 19:40:30 +08:00
Merge pull request #523 from toeverything/chore/print-build-info
chore: print build info
This commit is contained in:
@@ -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} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = withTM({
|
const nextConfig = withTM({
|
||||||
productionBrowserSourceMaps: true,
|
productionBrowserSourceMaps: true,
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
swcMinify: false,
|
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;
|
module.exports = nextConfig;
|
||||||
|
|||||||
@@ -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/space-mono';
|
||||||
import '@fontsource/poppins';
|
import '@fontsource/poppins';
|
||||||
|
import '../utils/print-build-info';
|
||||||
|
|
||||||
const ThemeProvider = dynamic(() => import('@/styles/themeProvider'), {
|
const ThemeProvider = dynamic(() => import('@/styles/themeProvider'), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
|
|||||||
@@ -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 {};
|
||||||
Reference in New Issue
Block a user