2020-10-16 14:45:49 -05:00
|
|
|
import { logger } from "@coder/logger"
|
2021-10-28 13:27:17 -07:00
|
|
|
import type { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"
|
2021-04-21 13:22:11 -07:00
|
|
|
import * as os from "os"
|
2020-10-16 14:45:49 -05:00
|
|
|
import * as path from "path"
|
|
|
|
|
|
2021-02-08 16:21:30 -07:00
|
|
|
export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles {
|
|
|
|
|
let pkg = {}
|
|
|
|
|
try {
|
|
|
|
|
pkg = require(relativePath)
|
2021-09-29 23:14:56 -04:00
|
|
|
} catch (error: any) {
|
2021-02-08 16:21:30 -07:00
|
|
|
logger.warn(error.message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pkg
|
2020-10-16 14:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-09 14:28:52 -07:00
|
|
|
export const rootPath = path.resolve(__dirname, "../..")
|
2022-03-14 21:37:29 -05:00
|
|
|
export const vsRootPath = path.join(rootPath, "lib/vscode")
|
2022-03-09 14:28:52 -07:00
|
|
|
const PACKAGE_JSON = "package.json"
|
|
|
|
|
const pkg = getPackageJson(`${rootPath}/${PACKAGE_JSON}`)
|
|
|
|
|
const codePkg = getPackageJson(`${vsRootPath}/${PACKAGE_JSON}`) || { version: "0.0.0" }
|
2020-10-16 14:45:49 -05:00
|
|
|
export const version = pkg.version || "development"
|
|
|
|
|
export const commit = pkg.commit || "development"
|
2022-02-28 13:55:47 -08:00
|
|
|
export const codeVersion = codePkg.version || "development"
|
2021-04-21 13:22:11 -07:00
|
|
|
export const tmpdir = path.join(os.tmpdir(), "code-server")
|
2021-05-05 10:16:01 -05:00
|
|
|
export const isDevMode = commit === "development"
|
2022-01-03 18:19:21 -06:00
|
|
|
export const httpProxyUri =
|
|
|
|
|
process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
|
2022-02-28 13:55:47 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getVersionString returns a human-readable version string suitable
|
|
|
|
|
* for outputting to the console.
|
|
|
|
|
*/
|
|
|
|
|
export function getVersionString(): string {
|
2022-03-01 12:20:43 -08:00
|
|
|
return [version, commit, "with Code", codeVersion].join(" ")
|
2022-02-28 13:55:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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,
|
|
|
|
|
})
|
|
|
|
|
}
|