-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathconstants.ts
48 lines (43 loc) · 1.54 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { logger } from "@coder/logger"
import type { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"
import * as os from "os"
import * as path from "path"
export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles {
let pkg = {}
try {
pkg = require(relativePath)
} catch (error: any) {
logger.warn(error.message)
}
return pkg
}
export const rootPath = path.resolve(__dirname, "../..")
export const vsRootPath = path.join(rootPath, "lib/vscode")
const PACKAGE_JSON = "package.json"
const pkg = getPackageJson(`${rootPath}/${PACKAGE_JSON}`)
const codePkg = getPackageJson(`${vsRootPath}/${PACKAGE_JSON}`) || { version: "0.0.0" }
export const version = pkg.version || "development"
export const commit = pkg.commit || "development"
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, "with Code", codeVersion].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,
})
}