Add flags for customizing user data dir and extensions dir (#420)
* Add flags for customizing extensions directory * Update @coder/nbin
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
"build:binary": "ts-node scripts/nbin.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coder/nbin": "^1.0.4",
|
||||
"@coder/nbin": "^1.0.5",
|
||||
"commander": "^2.19.0",
|
||||
"express": "^4.16.4",
|
||||
"express-static-gzip": "^1.1.3",
|
||||
|
@ -21,7 +21,9 @@ commander.version(process.env.VERSION || "development")
|
||||
.description("Run VS Code on a remote server.")
|
||||
.option("--cert <value>")
|
||||
.option("--cert-key <value>")
|
||||
.option("-d, --data-dir <value>", "Customize where user-data is stored.")
|
||||
.option("-e, --extensions-dir <dir>", "Set the root path for extensions.")
|
||||
.option("-d --user-data-dir <dir>", " Specifies the directory that user data is kept in, useful when running as root.")
|
||||
.option("--data-dir <value>", "DEPRECATED: Use '--user-data-dir' instead. Customize where user-data is stored.")
|
||||
.option("-h, --host <value>", "Customize the hostname.", "0.0.0.0")
|
||||
.option("-o, --open", "Open in the browser on startup.", false)
|
||||
.option("-p, --port <number>", "Port to bind on.", 8443)
|
||||
@ -51,6 +53,9 @@ const bold = (text: string | number): string | number => {
|
||||
readonly host: string;
|
||||
readonly port: number;
|
||||
|
||||
readonly userDataDir?: string;
|
||||
readonly extensionsDir?: string;
|
||||
|
||||
readonly dataDir?: string;
|
||||
readonly password?: string;
|
||||
readonly open?: boolean;
|
||||
@ -67,7 +72,8 @@ const bold = (text: string | number): string | number => {
|
||||
const noAuthValue = (commander as any).auth;
|
||||
options.noAuth = !noAuthValue;
|
||||
|
||||
const dataDir = path.resolve(options.dataDir || path.join(dataHome, "code-server"));
|
||||
const dataDir = path.resolve(options.userDataDir || options.dataDir || path.join(dataHome, "code-server"));
|
||||
const extensionsDir = options.extensionsDir ? path.resolve(options.extensionsDir) : path.resolve(dataDir, "extensions");
|
||||
const workingDir = path.resolve(args[0] || process.cwd());
|
||||
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
@ -81,6 +87,7 @@ const bold = (text: string | number): string | number => {
|
||||
await Promise.all([
|
||||
fse.mkdirp(cacheHome),
|
||||
fse.mkdirp(dataDir),
|
||||
fse.mkdirp(extensionsDir),
|
||||
fse.mkdirp(workingDir),
|
||||
]);
|
||||
|
||||
@ -144,10 +151,15 @@ const bold = (text: string | number): string | number => {
|
||||
}
|
||||
|
||||
logger.info(`\u001B[1mcode-server ${process.env.VERSION ? `v${process.env.VERSION}` : "development"}`);
|
||||
|
||||
if (options.dataDir) {
|
||||
logger.warn('"--data-dir" is deprecated. Use "--user-data-dir" instead.');
|
||||
}
|
||||
|
||||
// TODO: fill in appropriate doc url
|
||||
logger.info("Additional documentation: http://github.com/codercom/code-server");
|
||||
logger.info("Initializing", field("data-dir", dataDir), field("working-dir", workingDir), field("log-dir", logDir));
|
||||
const sharedProcess = new SharedProcess(dataDir, builtInExtensionsDir);
|
||||
logger.info("Initializing", field("data-dir", dataDir), field("extensions-dir", extensionsDir), field("working-dir", workingDir), field("log-dir", logDir));
|
||||
const sharedProcess = new SharedProcess(dataDir, extensionsDir, builtInExtensionsDir);
|
||||
const sendSharedProcessReady = (socket: WebSocket): void => {
|
||||
const active = new SharedProcessActive();
|
||||
active.setSocketPath(sharedProcess.socketPath);
|
||||
@ -196,6 +208,7 @@ const bold = (text: string | number): string | number => {
|
||||
}
|
||||
},
|
||||
serverOptions: {
|
||||
extensionsDirectory: extensionsDir,
|
||||
builtInExtensionsDirectory: builtInExtensionsDir,
|
||||
dataDirectory: dataDir,
|
||||
workingDirectory: workingDir,
|
||||
|
@ -38,6 +38,7 @@ export class SharedProcess {
|
||||
|
||||
public constructor(
|
||||
private readonly userDataDir: string,
|
||||
private readonly extensionsDir: string,
|
||||
private readonly builtInExtensionsDir: string,
|
||||
) {
|
||||
this.retry.run();
|
||||
@ -95,10 +96,8 @@ export class SharedProcess {
|
||||
this.activeProcess.kill();
|
||||
}
|
||||
|
||||
const extensionsDir = path.join(this.userDataDir, "extensions");
|
||||
const backupsDir = path.join(this.userDataDir, "Backups");
|
||||
await Promise.all([
|
||||
fse.mkdirp(extensionsDir),
|
||||
fse.mkdirp(backupsDir),
|
||||
]);
|
||||
|
||||
@ -141,7 +140,7 @@ export class SharedProcess {
|
||||
args: {
|
||||
"builtin-extensions-dir": this.builtInExtensionsDir,
|
||||
"user-data-dir": this.userDataDir,
|
||||
"extensions-dir": extensionsDir,
|
||||
"extensions-dir": this.extensionsDir,
|
||||
},
|
||||
logLevel: this.logger.level,
|
||||
sharedIPCHandle: this.socketPath,
|
||||
|
@ -7,10 +7,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@coder/logger/-/logger-1.0.3.tgz#e0e1ae5496fde5a3c6ef3d748fdfb26a55add8b8"
|
||||
integrity sha512-1o5qDZX2VZUNnzgz5KfAdMnaqaX6FNeTs0dUdg73MRHfQW94tFTIryFC1xTTCuzxGDjVHOHkaUAI4uHA2bheOA==
|
||||
|
||||
"@coder/nbin@^1.0.4":
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.0.4.tgz#13a3d110fe116ed5d5fdbd1384f0335745dfd859"
|
||||
integrity sha512-mtd5hzPHWBwKpTCYdJdLdiY4CFCEb8HUtv3NgH8SSLFiPDwY7H1UlpqeamIty27NZ+9NLnrBd/DfaE3aVo7rxQ==
|
||||
"@coder/nbin@^1.0.5":
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.0.5.tgz#6a9e9982eb179d6bcc9c2e7dfebb608b7c4605d9"
|
||||
integrity sha512-rai1/WgvH2j8SlRweOSk0JmrAzBx8bc22P+pThnPHj5terd0GScshqNR3EIoL/cdC2Ii4wjfOYodYbl/QynYGg==
|
||||
dependencies:
|
||||
"@coder/logger" "^1.0.3"
|
||||
fs-extra "^7.0.1"
|
||||
|
Reference in New Issue
Block a user