feat: add version string functions to constants (#4920)
Introduce helper functions for getting human- and machine-readable version strings from the constants package, and cover it in unit tests. This is a first step to resolving #4874.
This commit is contained in:
@ -17,13 +17,35 @@ export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJso
|
||||
}
|
||||
|
||||
const pkg = getPackageJson("../../package.json")
|
||||
const codePkg = getPackageJson("../../vendor/modules/code-oss-dev/package.json")
|
||||
|
||||
export const pkgName = pkg.name || "code-server"
|
||||
export const version = pkg.version || "development"
|
||||
export const commit = pkg.commit || "development"
|
||||
export const rootPath = path.resolve(__dirname, "../..")
|
||||
export const vsRootPath = path.join(rootPath, "vendor/modules/code-oss-dev")
|
||||
export const codeVersion = codePkg.version || "development"
|
||||
export const tmpdir = path.join(os.tmpdir(), "code-server")
|
||||
export const isDevMode = commit === "development"
|
||||
export const httpProxyUri =
|
||||
process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
|
||||
|
||||
/**
|
||||
* getVersionString returns a human-readable version string suitable
|
||||
* for outputting to the console.
|
||||
*/
|
||||
export function getVersionString(): string {
|
||||
return [version, commit].join(" ")
|
||||
}
|
||||
|
||||
/**
|
||||
* getVersionJsonString returns a machine-readable version string
|
||||
* suitable for outputting to the console.
|
||||
*/
|
||||
export function getVersionJsonString(): string {
|
||||
return JSON.stringify({
|
||||
codeServer: version,
|
||||
commit,
|
||||
vscode: codeVersion,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user