mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Configure server using env vars. Fixes #141333
This commit is contained in:
@@ -8,23 +8,15 @@
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const opn = require('opn');
|
const opn = require('opn');
|
||||||
const crypto = require('crypto');
|
|
||||||
const minimist = require('minimist');
|
const minimist = require('minimist');
|
||||||
|
|
||||||
function main() {
|
async function main() {
|
||||||
|
|
||||||
const args = minimist(process.argv.slice(2), {
|
const args = minimist(process.argv.slice(2), {
|
||||||
boolean: [
|
boolean: [
|
||||||
'help',
|
'help',
|
||||||
'launch'
|
'launch'
|
||||||
],
|
]
|
||||||
string: [
|
|
||||||
'host',
|
|
||||||
'port',
|
|
||||||
'driver',
|
|
||||||
'connection-token',
|
|
||||||
'server-data-dir'
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
@@ -36,46 +28,42 @@ function main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.env['VSCODE_SERVER_PORT'] = '9888';
|
||||||
|
|
||||||
const serverArgs = process.argv.slice(2).filter(v => v !== '--launch');
|
const serverArgs = process.argv.slice(2).filter(v => v !== '--launch');
|
||||||
|
const addr = await startServer(serverArgs);
|
||||||
const HOST = args['host'] ?? 'localhost';
|
|
||||||
const PORT = args['port'] ?? '9888';
|
|
||||||
const TOKEN = args['connection-token'] ?? String(crypto.randomInt(0xffffffff));
|
|
||||||
|
|
||||||
if (args['connection-token'] === undefined && args['connection-token-file'] === undefined && !args['without-connection-token']) {
|
|
||||||
serverArgs.push('--connection-token', TOKEN);
|
|
||||||
}
|
|
||||||
if (args['host'] === undefined) {
|
|
||||||
serverArgs.push('--host', HOST);
|
|
||||||
}
|
|
||||||
if (args['port'] === undefined) {
|
|
||||||
serverArgs.push('--port', PORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
startServer(serverArgs);
|
|
||||||
if (args['launch']) {
|
if (args['launch']) {
|
||||||
opn(`http://${HOST}:${PORT}/?tkn=${TOKEN}`);
|
opn(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startServer(programArgs) {
|
function startServer(programArgs) {
|
||||||
const env = { ...process.env };
|
return new Promise((s, e) => {
|
||||||
|
const env = { ...process.env };
|
||||||
|
const entryPoint = path.join(__dirname, '..', 'out', 'server-main.js');
|
||||||
|
|
||||||
const entryPoint = path.join(__dirname, '..', 'out', 'server-main.js');
|
console.log(`Starting server: ${entryPoint} ${programArgs.join(' ')}`);
|
||||||
|
const proc = cp.spawn(process.execPath, [entryPoint, ...programArgs], { env, stdio: [process.stdin, null, process.stderr] });
|
||||||
|
proc.stdout.on('data', e => {
|
||||||
|
const data = e.toString();
|
||||||
|
console.log(data);
|
||||||
|
const m = data.match(/Web UI available at (.*)/);
|
||||||
|
if (m) {
|
||||||
|
s(m[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`Starting server: ${entryPoint} ${programArgs.join(' ')}`);
|
proc.on('exit', (code) => process.exit(code));
|
||||||
const proc = cp.spawn(process.execPath, [entryPoint, ...programArgs], { env, stdio: 'inherit' });
|
|
||||||
|
|
||||||
proc.on('exit', (code) => process.exit(code));
|
process.on('exit', () => proc.kill());
|
||||||
|
process.on('SIGINT', () => {
|
||||||
process.on('exit', () => proc.kill());
|
proc.kill();
|
||||||
process.on('SIGINT', () => {
|
process.exit(128 + 2); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
|
||||||
proc.kill();
|
});
|
||||||
process.exit(128 + 2); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
|
process.on('SIGTERM', () => {
|
||||||
});
|
proc.kill();
|
||||||
process.on('SIGTERM', () => {
|
process.exit(128 + 15); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
|
||||||
proc.kill();
|
});
|
||||||
process.exit(128 + 15); // https://nodejs.org/docs/v14.16.0/api/process.html#process_signal_events
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ async function start() {
|
|||||||
string: ['install-extension', 'install-builtin-extension', 'uninstall-extension', 'locate-extension', 'socket-path', 'host', 'port', 'pick-port', 'compatibility'],
|
string: ['install-extension', 'install-builtin-extension', 'uninstall-extension', 'locate-extension', 'socket-path', 'host', 'port', 'pick-port', 'compatibility'],
|
||||||
alias: { help: 'h', version: 'v' }
|
alias: { help: 'h', version: 'v' }
|
||||||
});
|
});
|
||||||
|
['host', 'port', 'accept-server-license-terms'].forEach(e => {
|
||||||
|
if (!parsedArgs[e]) {
|
||||||
|
const envValue = process.env[`VSCODE_SERVER_${e.toUpperCase().replace('-', '_')}`];
|
||||||
|
if (envValue) {
|
||||||
|
parsedArgs[e] = envValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const extensionLookupArgs = ['list-extensions', 'locate-extension'];
|
const extensionLookupArgs = ['list-extensions', 'locate-extension'];
|
||||||
const extensionInstallArgs = ['install-extension', 'install-builtin-extension', 'uninstall-extension'];
|
const extensionInstallArgs = ['install-extension', 'install-builtin-extension', 'uninstall-extension'];
|
||||||
|
|||||||
Reference in New Issue
Block a user