From 8358d2aa7c7f8e70a3fe30e406661bafd98f32e2 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 4 Aug 2021 19:51:03 +0800 Subject: [PATCH] chore: add version env --- shared/index.tsx | 7 ++++++- shared/utils/environment.ts | 2 ++ web/src/dev.ts | 3 ++- web/webpack.config.ts | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/shared/index.tsx b/shared/index.tsx index 3a73b5a5..c60db4b8 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -93,5 +93,10 @@ export { datetimeToNow, datetimeFromNow, } from './utils/date-helper'; -export { isBrowser, isNavigator, isDevelopment } from './utils/environment'; +export { + isBrowser, + isNavigator, + isDevelopment, + version, +} from './utils/environment'; export { getTextColorHex } from './utils/string-helper'; diff --git a/shared/utils/environment.ts b/shared/utils/environment.ts index 1e3ee65c..7ec2b17b 100644 --- a/shared/utils/environment.ts +++ b/shared/utils/environment.ts @@ -3,3 +3,5 @@ export const isBrowser = typeof window !== 'undefined'; export const isNavigator = typeof navigator !== 'undefined'; export const isDevelopment = process.env.NODE_ENV === 'development'; + +export const version = process.env.VERSION || '0.0.0'; diff --git a/web/src/dev.ts b/web/src/dev.ts index 5735c6ad..5b70929f 100644 --- a/web/src/dev.ts +++ b/web/src/dev.ts @@ -1,7 +1,8 @@ -import { isDevelopment, request } from 'tailchat-shared'; +import { isDevelopment, request, version } from 'tailchat-shared'; if (isDevelopment === true) { (window as any).DEBUG = { request, + version, }; } diff --git a/web/webpack.config.ts b/web/webpack.config.ts index a3efdcbe..55794b6c 100644 --- a/web/webpack.config.ts +++ b/web/webpack.config.ts @@ -16,6 +16,8 @@ require('dotenv').config(); delete process.env.TS_NODE_PROJECT; // https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/32 require('../build/script/buildPublicTranslation.js'); // 编译前先执行一下构建翻译的脚本 +// eslint-disable-next-line @typescript-eslint/no-var-requires +const packageJson = require('./package.json'); const ROOT_PATH = path.resolve(__dirname, './'); const DIST_PATH = path.resolve(ROOT_PATH, './dist'); @@ -109,6 +111,7 @@ const config: Configuration = { new DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), 'process.env.SERVICE_URL': JSON.stringify(process.env.SERVICE_URL), + 'process.env.VERSION': JSON.stringify(packageJson.version), }), new HtmlWebpackPlugin({ title: 'TailChat',