add code-cli.sh
This commit is contained in:
parent
e9564ddeb0
commit
9e6c1612c4
2 changed files with 49 additions and 10 deletions
37
scripts/code-cli.sh
Executable file
37
scripts/code-cli.sh
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
|
||||
ROOT=$(dirname $(dirname $(realpath "$0")))
|
||||
else
|
||||
ROOT=$(dirname $(dirname $(readlink -f $0)))
|
||||
fi
|
||||
|
||||
function code() {
|
||||
cd $ROOT
|
||||
|
||||
# Node modules
|
||||
test -d node_modules || ./scripts/npm.sh install
|
||||
|
||||
# Get electron
|
||||
./node_modules/.bin/gulp electron
|
||||
|
||||
# Build
|
||||
test -d out || ./node_modules/.bin/gulp compile
|
||||
|
||||
# Launch Code
|
||||
[[ "$OSTYPE" == "darwin"* ]] \
|
||||
&& ELECTRON=.build/electron/Electron.app/Contents/MacOS/Electron \
|
||||
|| ELECTRON=.build/electron/electron
|
||||
|
||||
CLI="$ROOT/out/cli.js"
|
||||
|
||||
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 \
|
||||
NODE_ENV=development \
|
||||
VSCODE_DEV=1 \
|
||||
ELECTRON_ENABLE_LOGGING=1 \
|
||||
ELECTRON_ENABLE_STACK_DUMPING=1 \
|
||||
"$ELECTRON" "$CLI" . $@
|
||||
}
|
||||
|
||||
code "$@"
|
|
@ -8,6 +8,7 @@ import * as fs from 'fs';
|
|||
import * as os from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import uri from 'vs/base/common/uri';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
|
||||
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
|
||||
const packageJsonPath = path.join(rootPath, 'package.json');
|
||||
|
@ -49,27 +50,28 @@ ${ indent }-w, --wait Wait for the window to be closed before returni
|
|||
|
||||
export function main(argv: string[]) {
|
||||
const argParser = new ArgParser(argv);
|
||||
let exit = true;
|
||||
|
||||
if (argParser.hasFlag('help', 'h')) {
|
||||
console.log(argParser.help());
|
||||
} else if (argParser.hasFlag('version', 'v')) {
|
||||
console.log(packageJson.version);
|
||||
} else {
|
||||
delete process.env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
|
||||
if (argParser.hasFlag('wait', 'w')) {
|
||||
exit = false;
|
||||
const env = assign({}, process.env);
|
||||
delete env['ATOM_SHELL_INTERNAL_RUN_AS_NODE'];
|
||||
|
||||
let child = spawn(process.execPath, process.argv.slice(2), { detached: true, stdio: 'ignore' });
|
||||
const child = spawn(process.execPath, process.argv.slice(2), {
|
||||
detached: true,
|
||||
stdio: 'ignore',
|
||||
env
|
||||
});
|
||||
|
||||
if (argParser.hasFlag('wait', 'w')) {
|
||||
child.on('exit', process.exit);
|
||||
} else {
|
||||
spawn(process.execPath, process.argv.slice(2), { detached: true, stdio: 'ignore' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (exit) {
|
||||
process.exit(0);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main(process.argv.slice(2));
|
||||
|
|
Loading…
Reference in a new issue