|
1 | 1 | import { field, logger } from "@coder/logger";
|
2 | 2 | import { ServerMessage, SharedProcessActive } from "@coder/protocol/src/proto";
|
3 |
| -import { ChildProcess, fork, ForkOptions, spawn } from "child_process"; |
| 3 | +import { ChildProcess, fork, ForkOptions } from "child_process"; |
4 | 4 | import { randomFillSync } from "crypto";
|
5 | 5 | import * as fs from "fs";
|
6 | 6 | import * as fse from "fs-extra";
|
@@ -29,6 +29,7 @@ commander.version(process.env.VERSION || "development")
|
29 | 29 | .option("-N, --no-auth", "Start without requiring authentication.", undefined)
|
30 | 30 | .option("-H, --allow-http", "Allow http connections.", false)
|
31 | 31 | .option("-P, --password <value>", "Specify a password for authentication.")
|
| 32 | + .option("--install-extension <value>", "Install an extension by its ID.") |
32 | 33 | .option("--bootstrap-fork <name>", "Used for development. Never set.")
|
33 | 34 | .option("--extra-args <args>", "Used for development. Never set.")
|
34 | 35 | .arguments("Specify working directory.")
|
@@ -61,6 +62,8 @@ const bold = (text: string | number): string | number => {
|
61 | 62 | readonly cert?: string;
|
62 | 63 | readonly certKey?: string;
|
63 | 64 |
|
| 65 | + readonly installExtension?: string; |
| 66 | + |
64 | 67 | readonly bootstrapFork?: string;
|
65 | 68 | readonly extraArgs?: string;
|
66 | 69 | };
|
@@ -112,11 +115,11 @@ const bold = (text: string | number): string | number => {
|
112 | 115 | process.exit(1);
|
113 | 116 | }
|
114 | 117 |
|
115 |
| - ((options.extraArgs ? JSON.parse(options.extraArgs) : []) as string[]).forEach((arg, i) => { |
116 |
| - // [0] contains the binary running the script (`node` for example) and |
117 |
| - // [1] contains the script name, so the arguments come after that. |
118 |
| - process.argv[i + 2] = arg; |
119 |
| - }); |
| 118 | + process.argv = [ |
| 119 | + process.argv[0], |
| 120 | + process.argv[1], |
| 121 | + ...(options.extraArgs ? JSON.parse(options.extraArgs) : []), |
| 122 | + ]; |
120 | 123 |
|
121 | 124 | return requireModule(modulePath, builtInExtensionsDir);
|
122 | 125 | }
|
@@ -162,6 +165,26 @@ const bold = (text: string | number): string | number => {
|
162 | 165 | logger.warn('"--data-dir" is deprecated. Use "--user-data-dir" instead.');
|
163 | 166 | }
|
164 | 167 |
|
| 168 | + if (options.installExtension) { |
| 169 | + const fork = forkModule("vs/code/node/cli", [ |
| 170 | + "--user-data-dir", dataDir, |
| 171 | + "--builtin-extensions-dir", builtInExtensionsDir, |
| 172 | + "--extensions-dir", extensionsDir, |
| 173 | + "--install-extension", options.installExtension, |
| 174 | + ], { |
| 175 | + env: { |
| 176 | + VSCODE_ALLOW_IO: "true", |
| 177 | + VSCODE_LOGS: process.env.VSCODE_LOGS, |
| 178 | + }, |
| 179 | + }, dataDir); |
| 180 | + |
| 181 | + fork.stdout.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.info(l))); |
| 182 | + fork.stderr.on("data", (d: Buffer) => d.toString().split("\n").forEach((l) => logger.error(l))); |
| 183 | + fork.on("exit", () => process.exit()); |
| 184 | + |
| 185 | + return; |
| 186 | + } |
| 187 | + |
165 | 188 | // TODO: fill in appropriate doc url
|
166 | 189 | logger.info("Additional documentation: http://github.com/codercom/code-server");
|
167 | 190 | logger.info("Initializing", field("data-dir", dataDir), field("extensions-dir", extensionsDir), field("working-dir", workingDir), field("log-dir", logDir));
|
|
0 commit comments