vscode/scripts/code.sh

77 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2015-11-13 21:39:38 +08:00
2019-04-11 16:23:14 +08:00
set -e
2015-11-13 21:39:38 +08:00
if [[ "$OSTYPE" == "darwin"* ]]; then
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
2017-02-22 04:22:01 +08:00
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
# On Linux with Electron 2.0.x running out of a VM causes
# a freeze so we only enable this flag on macOS
export ELECTRON_ENABLE_LOGGING=1
2015-11-13 21:39:38 +08:00
else
2017-02-22 04:22:01 +08:00
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
2019-04-11 16:23:14 +08:00
if grep -qi Microsoft /proc/version; then
IN_WSL=true
fi
2015-11-13 21:39:38 +08:00
fi
2015-11-26 16:29:43 +08:00
function code() {
2017-02-22 04:22:01 +08:00
cd "$ROOT"
2015-11-13 21:39:38 +08:00
if [[ "$OSTYPE" == "darwin"* ]]; then
2016-08-09 23:56:05 +08:00
NAME=`node -p "require('./product.json').nameLong"`
CODE="./.build/electron/$NAME.app/Contents/MacOS/Electron"
else
NAME=`node -p "require('./product.json').applicationName"`
2016-08-09 23:57:09 +08:00
CODE=".build/electron/$NAME"
fi
2015-11-26 16:29:43 +08:00
# Node modules
2017-11-16 17:47:02 +08:00
test -d node_modules || yarn
2015-11-13 21:39:38 +08:00
2015-11-26 16:29:43 +08:00
# Get electron
2017-11-16 21:43:41 +08:00
node build/lib/electron.js || ./node_modules/.bin/gulp electron
2015-11-26 16:29:43 +08:00
2018-01-30 05:04:27 +08:00
# Manage built-in extensions
if [[ "$1" == "--builtin" ]]; then
exec "$CODE" build/builtin
return
fi
2018-01-29 19:23:43 +08:00
# Sync built-in extensions
node build/lib/builtInExtensions.js
2015-11-26 17:07:11 +08:00
# Build
test -d out || ./node_modules/.bin/gulp compile
2015-11-26 17:07:11 +08:00
2015-11-26 16:29:43 +08:00
# Configuration
export NODE_ENV=development
export VSCODE_DEV=1
export VSCODE_CLI=1
2015-11-26 16:29:43 +08:00
export ELECTRON_ENABLE_STACK_DUMPING=1
# Launch Code
exec "$CODE" . "$@"
2015-11-26 16:29:43 +08:00
}
2019-04-11 16:23:14 +08:00
function code-wsl()
{
# in a wsl shell
local WIN_CODE_CLI_CMD=$(wslpath -w "$ROOT/scripts/code-cli.bat")
if ! [ -z "$WIN_CODE_CLI_CMD" ]; then
local WSL_EXT_ID="ms-vscode.remote-wsl"
local WSL_EXT_WLOC=$(cmd.exe /c "$WIN_CODE_CLI_CMD" --locate-extension $WSL_EXT_ID)
if ! [ -z "$WSL_EXT_WLOC" ]; then
# replace \r\n with \n in WSL_EXT_WLOC
local WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode-dev.sh
$WSL_CODE "$ROOT" "$@"
exit $?
fi
2019-04-11 16:23:14 +08:00
fi
}
if ! [ -z ${IN_WSL+x} ]; then
2019-04-11 16:23:14 +08:00
code-wsl "$@"
fi
code "$@"