diff --git a/.eslintignore b/.eslintignore index a7026c0e3..0538e65d3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,3 @@ - src/lib/rlottie/rlottie-wasm.js src/lib/video-preview/libav* src/lib/video-preview/polyfill/* @@ -19,3 +18,5 @@ src/lib/secret-sauce/ playwright.config.ts dist/* + +deploy/update_version.js diff --git a/deploy/update_version.js b/deploy/update_version.js new file mode 100644 index 000000000..81ac7919c --- /dev/null +++ b/deploy/update_version.js @@ -0,0 +1,21 @@ +const path = require('path'); +const fs = require('fs'); + +const ROOT_PATH = `${path.dirname(__filename)}/..`; +const PATCH_VERSION_PATH = `${ROOT_PATH}/.patch-version`; +const PACKAGE_JSON_PATH = `${ROOT_PATH}/package.json`; +const VERSION_TXT_PATH = `${ROOT_PATH}/public/version.txt`; + +// This patch value is used to override the one from package.json +const currentPatch = fs.existsSync(PATCH_VERSION_PATH) ? Number(fs.readFileSync(PATCH_VERSION_PATH, 'utf-8')) : -1; +const packageJsonContent = fs.readFileSync(PACKAGE_JSON_PATH, 'utf-8'); +const currentVersion = JSON.parse(packageJsonContent).version; +const [major, minor] = currentVersion.split('.'); + +const newPatch = currentPatch + 1; +const newVersion = [major, minor, newPatch].join('.'); +const newPackageJsonContent = packageJsonContent.replace(`"version": "${currentVersion}"`, `"version": "${newVersion}"`); + +fs.writeFileSync(PATCH_VERSION_PATH, String(newPatch), 'utf-8'); +fs.writeFileSync(PACKAGE_JSON_PATH, newPackageJsonContent, 'utf-8'); +fs.writeFileSync(VERSION_TXT_PATH, newVersion, 'utf-8'); diff --git a/package.json b/package.json index 8f31523b5..767a99c63 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,14 @@ "description": "", "main": "index.js", "scripts": { - "dev": "cross-env APP_ENV=development APP_VERSION=$(npm run version:print --silent) webpack serve --mode development", + "dev": "cross-env APP_ENV=development webpack serve --mode development", "dev:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack serve --mode development --port 1235", "build:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack --mode development", - "build:staging": "cross-env APP_ENV=staging APP_VERSION=$(npm run version:inc --silent) webpack --mode development && ./deploy/copy_to_dist.sh", - "build:production": "npm i && APP_VERSION=$(npm run version:inc --silent) webpack && ./deploy/copy_to_dist.sh", - "deploy:production": "npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push", - "postversion": "npm run version:update", - "version:print": "echo \"$(node -p -e \"require('./package.json').version.match(/^\\d+\\.\\d+/)[0]\").$(cat .patch-version || echo 0)\"", - "version:update": "npm run version:print --silent > ./public/version.txt", - "version:inc": "echo $((`cat .patch-version || echo -1` + 1)) > .patch-version && npm run version:update && npm run version:print", + "build:staging": "cross-env APP_ENV=staging webpack --mode development && ./deploy/copy_to_dist.sh", + "build:production": "npm i && webpack && ./deploy/copy_to_dist.sh", + "deploy:production": "npm run update_version && npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push", + "postversion": "rm -rf .patch-version && npm run update_version", + "update_version": "node ./deploy/update_version.js", "telegraph:update_changelog": "node ./dev/telegraphChangelog.js", "check": "tsc && stylelint \"**/*.{css,scss}\" && eslint . --ext .ts,.tsx,.js --ignore-pattern src/lib/gramjs", "check:fix": "npm run check -- --fix", diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 5a9561e75..edd9e203e 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -2,6 +2,7 @@ declare const process: NodeJS.Process; declare module '*.module.scss'; +declare const APP_VERSION: string; declare const APP_REVISION: string; declare namespace React { diff --git a/src/api/gramjs/methods/client.ts b/src/api/gramjs/methods/client.ts index 914adeca1..5f524f7e7 100644 --- a/src/api/gramjs/methods/client.ts +++ b/src/api/gramjs/methods/client.ts @@ -15,7 +15,7 @@ import type { } from '../../types'; import { - DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST, APP_VERSION, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_MOV_TYPE, + DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_MOV_TYPE, } from '../../../config'; import { onRequestPhoneNumber, onRequestCode, onRequestPassword, onRequestRegistration, diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index 0dca39235..42c710f0d 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -11,7 +11,7 @@ import { LeftColumnContent, SettingsScreens } from '../../../types'; import { ANIMATION_LEVEL_MAX, ANIMATION_LEVEL_MIN, - APP_NAME, APP_VERSION, + APP_NAME, ARCHIVED_FOLDER_ID, BETA_CHANGELOG_URL, DEBUG, diff --git a/src/config.ts b/src/config.ts index dbd80afde..8171763f0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,6 @@ import type { ApiLimitType } from './global/types'; export const APP_NAME = process.env.APP_NAME || 'Telegram Web A'; -export const APP_VERSION = process.env.APP_VERSION!; export const RELEASE_DATETIME = process.env.RELEASE_DATETIME; export const PRODUCTION_HOSTNAME = 'web.telegram.org'; diff --git a/src/global/actions/ui/messages.ts b/src/global/actions/ui/messages.ts index a3b2fec53..5c1bad8f2 100644 --- a/src/global/actions/ui/messages.ts +++ b/src/global/actions/ui/messages.ts @@ -9,7 +9,6 @@ import type { import { ANIMATION_END_DELAY, - APP_VERSION, RELEASE_DATETIME, FAST_SMOOTH_MAX_DURATION, SERVICE_NOTIFICATIONS_USER_ID, diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index c416995ad..62d4000fb 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -7,7 +7,7 @@ import { MAIN_THREAD_ID } from '../../../api/types'; import type { ActionReturnType, GlobalState } from '../../types'; import { - APP_VERSION, DEBUG, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT, INACTIVE_MARKER, PAGE_TITLE, IS_ELECTRON, + DEBUG, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT, INACTIVE_MARKER, PAGE_TITLE, IS_ELECTRON, } from '../../../config'; import getReadableErrorText from '../../../util/getReadableErrorText'; import { diff --git a/src/index.tsx b/src/index.tsx index eaa2af939..416c1c86a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,7 +13,7 @@ import { IS_MULTITAB_SUPPORTED } from './util/windowEnvironment'; import './global/init'; import { - APP_VERSION, DEBUG, MULTITAB_LOCALSTORAGE_KEY, STRICTERDOM_ENABLED, + DEBUG, MULTITAB_LOCALSTORAGE_KEY, STRICTERDOM_ENABLED, } from './config'; import { establishMultitabRole, subscribeToMasterChange } from './util/establishMultitabRole'; import { requestGlobal, subscribeToMultitabBroadcastChannel } from './util/multitab'; diff --git a/src/util/multitab.ts b/src/util/multitab.ts index 509dcaee9..7875264e2 100644 --- a/src/util/multitab.ts +++ b/src/util/multitab.ts @@ -7,7 +7,7 @@ import type { ApiInitialArgs } from '../api/types'; import type { GlobalState } from '../global/types'; import { IS_MULTITAB_SUPPORTED } from './windowEnvironment'; -import { APP_VERSION, DATA_BROADCAST_CHANNEL_NAME, MULTITAB_LOCALSTORAGE_KEY } from '../config'; +import { DATA_BROADCAST_CHANNEL_NAME, MULTITAB_LOCALSTORAGE_KEY } from '../config'; import { deepMerge } from './deepMerge'; import { selectTabState } from '../global/selectors'; import { diff --git a/src/util/websync.ts b/src/util/websync.ts index ee2891968..9caad4688 100644 --- a/src/util/websync.ts +++ b/src/util/websync.ts @@ -1,5 +1,5 @@ import { - APP_VERSION, DEBUG, IS_MOCKED_CLIENT, IS_ELECTRON, + DEBUG, IS_MOCKED_CLIENT, IS_ELECTRON, } from '../config'; import { getGlobal } from '../global'; import { hasStoredSession } from './sessions'; diff --git a/webpack.config.ts b/webpack.config.ts index f355816d7..6cbd585a0 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -193,7 +193,6 @@ export default function createConfig( APP_MOCKED_CLIENT, // eslint-disable-next-line no-null/no-null APP_NAME: null, - APP_VERSION: appVersion, IS_ELECTRON: false, APP_TITLE, RELEASE_DATETIME: Date.now(), @@ -203,6 +202,7 @@ export default function createConfig( TEST_SESSION: null, }), new DefinePlugin({ + APP_VERSION: JSON.stringify(appVersion), APP_REVISION: DefinePlugin.runtimeValue(() => { const { branch, commit } = getGitMetadata(); const shouldDisplayCommit = APP_ENV === 'staging' || !branch || branch === 'HEAD';