Skip to content

Commit cdc5d67

Browse files
committed
get app version via npm script
1 parent 62c38a5 commit cdc5d67

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules
66

77
# Ignore built ts files
88
dist
9+
src/version.ts
910

1011
# consignments
11-
files/*
12+
files/*

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "node ./dist/server.js",
8+
"predev": "npm run version",
89
"dev": "ts-node-dev ./src/server.ts",
10+
"prebuild": "npm run version",
911
"build": "tsc",
1012
"lint": "eslint --ignore-path .gitignore . --ext .ts",
1113
"lint:fix": "npm run lint -- --fix",
12-
"test": "jest --verbose"
14+
"test": "jest --verbose",
15+
"version": "echo 'export const APP_VERSION = \"'$npm_package_version'\"' > src/version.ts"
1316
},
1417
"author": "",
1518
"license": "MIT",

src/controllers/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import path from "path";
99
import logger from "../logger";
1010
import { genHashFromFile, setDir } from "../util";
1111
import { APP_DIR } from "../vars";
12+
import { APP_VERSION } from "../version";
1213

13-
const VERSION = process.env.npm_package_version;
1414
const TMP_DIR = "tmp";
1515
const CONSIGNMENTS_DIR = "consignments";
1616
const MEDIA_DIR = "media";
@@ -355,7 +355,7 @@ export const loadApiEndpoints = (app: Application): void => {
355355
middleware,
356356
async (_req: Request, res: Response) => {
357357
return res.status(200).send({
358-
version: VERSION,
358+
version: APP_VERSION,
359359
uptime: Math.trunc(process.uptime()),
360360
});
361361
}

0 commit comments

Comments
 (0)