From d00e470b55327489b49d770144b7cfdb24045be6 Mon Sep 17 00:00:00 2001 From: sct Date: Sun, 27 Dec 2020 17:22:21 +0000 Subject: [PATCH] fix: use new commit tag file for app version as well --- server/routes/index.ts | 16 ++-------------- server/utils/appVersion.ts | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/server/routes/index.ts b/server/routes/index.ts index cd8c23a6b..29466bd70 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -1,5 +1,4 @@ import { Router } from 'express'; -import path from 'path'; import user from './user'; import authRoutes from './auth'; import { checkUser, isAuthenticated } from '../middleware/auth'; @@ -14,18 +13,7 @@ import tvRoutes from './tv'; import mediaRoutes from './media'; import personRoutes from './person'; import collectionRoutes from './collection'; -import { getAppVersion } from '../utils/appVersion'; -import { existsSync } from 'fs'; -import logger from '../logger'; - -const COMMIT_TAG_PATH = path.join(__dirname, '../../committag.json'); -let commitTag = 'local'; - -if (existsSync(COMMIT_TAG_PATH)) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - commitTag = require(COMMIT_TAG_PATH).commitTag; - logger.info(`Commit Tag: ${commitTag}`); -} +import { getAppVersion, getCommitTag } from '../utils/appVersion'; const router = Router(); @@ -34,7 +22,7 @@ router.use(checkUser); router.get('/status', (req, res) => { return res.status(200).json({ version: getAppVersion(), - commitTag, + commitTag: getCommitTag(), }); }); diff --git a/server/utils/appVersion.ts b/server/utils/appVersion.ts index ef9f35c3b..923d47089 100644 --- a/server/utils/appVersion.ts +++ b/server/utils/appVersion.ts @@ -1,3 +1,20 @@ +import { existsSync } from 'fs'; +import path from 'path'; +import logger from '../logger'; + +const COMMIT_TAG_PATH = path.join(__dirname, '../../committag.json'); +let commitTag = 'local'; + +if (existsSync(COMMIT_TAG_PATH)) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + commitTag = require(COMMIT_TAG_PATH).commitTag; + logger.info(`Commit Tag: ${commitTag}`); +} + +export const getCommitTag = (): string => { + return commitTag; +}; + export const getAppVersion = (): string => { // eslint-disable-next-line @typescript-eslint/no-var-requires const { version } = require('../../package.json'); @@ -5,7 +22,7 @@ export const getAppVersion = (): string => { let finalVersion = version; if (version === '0.1.0') { - finalVersion = `develop-${process.env.COMMIT_TAG ?? 'local'}`; + finalVersion = `develop-${getCommitTag()}`; } return finalVersion;