refactor: add getPackageJson fn in constants

This commit is contained in:
Joe Previte 2021-02-08 16:21:30 -07:00
parent 164d11e027
commit 719481e84e
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
3 changed files with 20 additions and 7 deletions

View File

@ -31,6 +31,7 @@
}, },
"main": "out/node/entry.js", "main": "out/node/entry.js",
"devDependencies": { "devDependencies": {
"@schemastore/package": "^0.0.6",
"@types/body-parser": "^1.19.0", "@types/body-parser": "^1.19.0",
"@types/cookie-parser": "^1.4.2", "@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.8", "@types/express": "^4.17.8",
@ -62,8 +63,8 @@
"stylelint": "^13.0.0", "stylelint": "^13.0.0",
"stylelint-config-recommended": "^3.0.0", "stylelint-config-recommended": "^3.0.0",
"ts-node": "^9.0.0", "ts-node": "^9.0.0",
"wtfnode": "^0.8.4", "typescript": "^4.1.3",
"typescript": "^4.1.3" "wtfnode": "^0.8.4"
}, },
"resolutions": { "resolutions": {
"@types/node": "^12.12.7", "@types/node": "^12.12.7",

View File

@ -1,13 +1,20 @@
import { logger } from "@coder/logger" import { logger } from "@coder/logger"
import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"
import * as path from "path" import * as path from "path"
let pkg: { version?: string; commit?: string } = {} export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles {
try { let pkg = {}
pkg = require("../../package.json") try {
} catch (error) { pkg = require(relativePath)
logger.warn(error.message) } catch (error) {
logger.warn(error.message)
}
return pkg
} }
const pkg = getPackageJson("../../package.json")
export const version = pkg.version || "development" export const version = pkg.version || "development"
export const commit = pkg.commit || "development" export const commit = pkg.commit || "development"
export const rootPath = path.resolve(__dirname, "../..") export const rootPath = path.resolve(__dirname, "../..")

View File

@ -980,6 +980,11 @@
"@parcel/utils" "^1.11.0" "@parcel/utils" "^1.11.0"
physical-cpu-count "^2.0.0" physical-cpu-count "^2.0.0"
"@schemastore/package@^0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@schemastore/package/-/package-0.0.6.tgz#9a76713da1c7551293b7e72e4f387f802bfd5d81"
integrity sha512-uNloNHoyHttSSdeuEkkSC+mdxJXMKlcUPOMb//qhQbIQijXg8x54VmAw3jm6GJZQ5DBtIqGBd66zEQCDCChQVA==
"@stylelint/postcss-css-in-js@^0.37.2": "@stylelint/postcss-css-in-js@^0.37.2":
version "0.37.2" version "0.37.2"
resolved "https://registry.yarnpkg.com/@stylelint/postcss-css-in-js/-/postcss-css-in-js-0.37.2.tgz#7e5a84ad181f4234a2480803422a47b8749af3d2" resolved "https://registry.yarnpkg.com/@stylelint/postcss-css-in-js/-/postcss-css-in-js-0.37.2.tgz#7e5a84ad181f4234a2480803422a47b8749af3d2"