Skip to content

Commit 9e6c161

Browse files
committed
add code-cli.sh
1 parent e9564dd commit 9e6c161

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

scripts/code-cli.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "$OSTYPE" == "darwin"* ]]; then
4+
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
5+
ROOT=$(dirname $(dirname $(realpath "$0")))
6+
else
7+
ROOT=$(dirname $(dirname $(readlink -f $0)))
8+
fi
9+
10+
function code() {
11+
cd $ROOT
12+
13+
# Node modules
14+
test -d node_modules || ./scripts/npm.sh install
15+
16+
# Get electron
17+
./node_modules/.bin/gulp electron
18+
19+
# Build
20+
test -d out || ./node_modules/.bin/gulp compile
21+
22+
# Launch Code
23+
[[ "$OSTYPE" == "darwin"* ]] \
24+
&& ELECTRON=.build/electron/Electron.app/Contents/MacOS/Electron \
25+
|| ELECTRON=.build/electron/electron
26+
27+
CLI="$ROOT/out/cli.js"
28+
29+
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 \
30+
NODE_ENV=development \
31+
VSCODE_DEV=1 \
32+
ELECTRON_ENABLE_LOGGING=1 \
33+
ELECTRON_ENABLE_STACK_DUMPING=1 \
34+
"$ELECTRON" "$CLI" . $@
35+
}
36+
37+
code "$@"

src/vs/workbench/electron-main/cli.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as fs from 'fs';
88
import * as os from 'os';
99
import { spawn } from 'child_process';
1010
import uri from 'vs/base/common/uri';
11+
import { assign } from 'vs/base/common/objects';
1112

1213
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
1314
const packageJsonPath = path.join(rootPath, 'package.json');
@@ -49,27 +50,28 @@ ${ indent }-w, --wait Wait for the window to be closed before returni
4950

5051
export function main(argv: string[]) {
5152
const argParser = new ArgParser(argv);
52-
let exit = true;
5353

5454
if (argParser.hasFlag('help', 'h')) {
5555
console.log(argParser.help());
5656
} else if (argParser.hasFlag('version', 'v')) {
5757
console.log(packageJson.version);
5858
} else {
59-
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
60-
if (argParser.hasFlag('wait', 'w')) {
61-
exit = false;
59+
const env = assign({}, process.env);
60+
delete env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
61+
62+
const child = spawn(process.execPath, process.argv.slice(2), {
63+
detached: true,
64+
stdio: 'ignore',
65+
env
66+
});
6267

63-
let child = spawn(process.execPath, process.argv.slice(2), { detached: true, stdio: 'ignore' });
68+
if (argParser.hasFlag('wait', 'w')) {
6469
child.on('exit', process.exit);
65-
} else {
66-
spawn(process.execPath, process.argv.slice(2), { detached: true, stdio: 'ignore' });
70+
return;
6771
}
6872
}
6973

70-
if (exit) {
71-
process.exit(0);
72-
}
74+
process.exit(0);
7375
}
7476

7577
main(process.argv.slice(2));

0 commit comments

Comments
 (0)