Archived
1
0

Merge branch 'restructure'

This commit is contained in:
Asher
2020-02-18 13:30:26 -06:00
5 changed files with 90 additions and 18 deletions

View File

@ -1,13 +1,13 @@
{
"name": "code-server",
"short_name": "code-server",
"start_url": "../../../..",
"start_url": "{{BASE}}",
"display": "fullscreen",
"background-color": "#fff",
"description": "Run editors on a remote server.",
"icons": [
{
"src": "./code-server.png",
"src": "{{BASE}}/static-{{COMMIT}}/src/browser/media/code-server.png",
"sizes": "384x384",
"type": "image/png"
}

View File

@ -24,7 +24,7 @@ export class MainHttpProvider extends HttpProvider {
switch (route.base) {
case "/static": {
this.ensureMethod(request)
const response = await this.getResource(this.rootPath, route.requestPath)
const response = await this.getReplacedResource(route)
if (!this.isDev) {
response.cache = true
}
@ -75,6 +75,20 @@ export class MainHttpProvider extends HttpProvider {
return this.getErrorRoot(route, "404", "404", "Application not found")
}
/**
* Return a resource with variables replaced where necessary.
*/
protected async getReplacedResource(route: Route): Promise<HttpResponse> {
if (route.requestPath.endsWith("/manifest.json")) {
const response = await this.getUtf8Resource(this.rootPath, route.requestPath)
response.content = response.content
.replace(/{{BASE}}/g, this.base(route))
.replace(/{{COMMIT}}/g, this.options.commit)
return response
}
return this.getResource(this.rootPath, route.requestPath)
}
public async getRoot(route: Route): Promise<HttpResponse> {
const recent = await this.api.recent()
const apps = await this.api.installedApplications()
@ -136,7 +150,7 @@ export class MainHttpProvider extends HttpProvider {
private async getUpdate(): Promise<string> {
if (!this.update.enabled) {
return "Updates are disabled"
return `<div class="block-row"><div class="item"><div class="sub">Updates are disabled</div></div></div>`
}
const humanize = (time: number): string => {

View File

@ -15,6 +15,7 @@ export interface Args extends VsArgs {
readonly cert?: OptionalString
readonly "cert-key"?: string
readonly "disable-updates"?: boolean
readonly "disable-telemetry"?: boolean
readonly help?: boolean
readonly host?: string
readonly json?: boolean
@ -22,6 +23,9 @@ export interface Args extends VsArgs {
readonly port?: number
readonly socket?: string
readonly version?: boolean
readonly "list-extensions"?: boolean
readonly "install-extension"?: string[]
readonly "uninstall-extension"?: string[]
readonly _: string[]
}
@ -68,6 +72,7 @@ const options: Options<Required<Args>> = {
},
"cert-key": { type: "string", path: true, description: "Path to certificate key when using non-generated cert." },
"disable-updates": { type: "boolean", description: "Disable automatic updates." },
"disable-telemetry": { type: "boolean", description: "Disable telemetry." },
host: { type: "string", description: "Host for the HTTP server." },
help: { type: "boolean", short: "h", description: "Show this output." },
json: { type: "boolean" },
@ -82,6 +87,9 @@ const options: Options<Required<Args>> = {
"builtin-extensions-dir": { type: "string", path: true },
"extra-extensions-dir": { type: "string[]", path: true },
"extra-builtin-extensions-dir": { type: "string[]", path: true },
"list-extensions": { type: "boolean" },
"install-extension": { type: "string[]" },
"uninstall-extension": { type: "string[]" },
log: { type: "string" },
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
@ -193,8 +201,13 @@ export const parse = (argv: string[]): Args => {
if (process.env.LOG_LEVEL === "trace" || args.verbose) {
args.verbose = true
args.log = "trace"
} else if (!args.log) {
args.log = process.env.LOG_LEVEL
}
// Ensure this passes down to forked processes.
process.env.LOG_LEVEL = args.log
switch (args.log) {
case "trace":
logger.level = Level.Trace

View File

@ -1,10 +1,13 @@
import { logger } from "@coder/logger"
import { Args, optionDescriptions, parse } from "./cli"
import { field, logger } from "@coder/logger"
import * as cp from "child_process"
import * as path from "path"
import { CliMessage } from "../../lib/vscode/src/vs/server/ipc"
import { ApiHttpProvider } from "./app/api"
import { MainHttpProvider } from "./app/app"
import { LoginHttpProvider } from "./app/login"
import { UpdateHttpProvider } from "./app/update"
import { VscodeHttpProvider } from "./app/vscode"
import { Args, optionDescriptions, parse } from "./cli"
import { AuthType, HttpServer } from "./http"
import { generateCertificate, generatePassword, hash, open } from "./util"
import { ipcMain, wrap } from "./wrapper"
@ -105,6 +108,29 @@ if (args.help) {
console.log(version)
}
process.exit(0)
} else if (args["list-extensions"] || args["install-extension"] || args["uninstall-extension"]) {
process.env.NBIN_BYPASS = "true"
logger.debug("Forking VS Code CLI...")
const vscode = cp.fork(path.resolve(__dirname, "../../lib/vscode/out/vs/server/fork"), [], {
env: {
...process.env,
CODE_SERVER_PARENT_PID: process.pid.toString(),
},
})
vscode.once("message", (message) => {
logger.debug("Got message from VS Code", field("message", message))
if (message.type !== "ready") {
logger.error("Unexpected response waiting for ready response")
process.exit(1)
}
const send: CliMessage = { type: "cli", args }
vscode.send(send)
})
vscode.once("error", (error) => {
logger.error(error.message)
process.exit(1)
})
vscode.on("exit", (code) => process.exit(code || 0))
} else {
wrap(() => main(args))
}