[Dev] Dynamically update revision when switching branch (#1721)
This commit is contained in:
parent
13ae8c6a7a
commit
d8ec4b97f0
@ -71,5 +71,8 @@
|
||||
},
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"globals": {
|
||||
"APP_REVISION": "readonly"
|
||||
}
|
||||
}
|
||||
|
||||
2
src/@types/global.d.ts
vendored
2
src/@types/global.d.ts
vendored
@ -1,5 +1,7 @@
|
||||
declare const process: NodeJS.Process;
|
||||
|
||||
declare var APP_REVISION: string;
|
||||
|
||||
declare namespace React {
|
||||
interface HTMLAttributes {
|
||||
// Optimization for DOM nodes prepends and inserts
|
||||
|
||||
@ -8,7 +8,7 @@ import { ApiChat } from '../../../api/types';
|
||||
import { GlobalState } from '../../../global/types';
|
||||
|
||||
import {
|
||||
ANIMATION_LEVEL_MAX, APP_NAME, APP_REVISION, APP_VERSION, DEBUG, FEEDBACK_URL,
|
||||
ANIMATION_LEVEL_MAX, APP_NAME, APP_VERSION, DEBUG, FEEDBACK_URL,
|
||||
} from '../../../config';
|
||||
import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment';
|
||||
import buildClassName from '../../../util/buildClassName';
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
export const APP_NAME = process.env.APP_NAME || 'Telegram WebZ';
|
||||
export const APP_VERSION = process.env.APP_VERSION!;
|
||||
export const APP_REVISION = process.env.APP_REVISION;
|
||||
|
||||
export const DEBUG = (
|
||||
process.env.APP_ENV !== 'production' && process.env.APP_ENV !== 'perf' && process.env.APP_ENV !== 'test'
|
||||
|
||||
@ -2,6 +2,7 @@ const path = require('path');
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
const {
|
||||
DefinePlugin,
|
||||
EnvironmentPlugin,
|
||||
ProvidePlugin,
|
||||
} = require('webpack');
|
||||
@ -128,6 +129,12 @@ module.exports = (env = {}, argv = {}) => {
|
||||
TELEGRAM_T_API_HASH: undefined,
|
||||
TEST_SESSION: null,
|
||||
}),
|
||||
new DefinePlugin({
|
||||
APP_REVISION: DefinePlugin.runtimeValue(() => {
|
||||
const { branch, commit } = getGitMetadata();
|
||||
return JSON.stringify((!branch || branch === 'HEAD') ? commit : branch);
|
||||
}, argv.mode === 'development' ? true : []),
|
||||
}),
|
||||
new ProvidePlugin({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
}),
|
||||
@ -153,3 +160,10 @@ module.exports = (env = {}, argv = {}) => {
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
function getGitMetadata() {
|
||||
const gitRevisionPlugin = new GitRevisionPlugin();
|
||||
const branch = process.env.HEAD || gitRevisionPlugin.branch();
|
||||
const commit = gitRevisionPlugin.commithash().substring(0, 7);
|
||||
return { branch, commit };
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user