2016-02-18 13:47:09 +08:00
|
|
|
#!/usr/bin/env bash
|
2015-11-13 21:39:38 +08:00
|
|
|
|
2019-07-30 22:37:15 +08:00
|
|
|
set -e
|
2019-04-11 16:23:14 +08:00
|
|
|
|
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")")")
|
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
|
|
|
|
2016-08-09 23:13:08 +08:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
2016-08-09 23:56:05 +08:00
|
|
|
NAME=`node -p "require('./product.json').nameLong"`
|
2016-08-09 23:13:08 +08:00
|
|
|
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"
|
2016-08-09 23:13:08 +08:00
|
|
|
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
|
2019-10-16 17:15:43 +08:00
|
|
|
yarn 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
|
2018-01-23 23:40:41 +08:00
|
|
|
|
2015-11-26 17:07:11 +08:00
|
|
|
# Build
|
2019-10-02 21:24:47 +08:00
|
|
|
test -d out || yarn 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
|
2016-08-08 22:12:32 +08:00
|
|
|
export VSCODE_CLI=1
|
2015-11-26 16:29:43 +08:00
|
|
|
export ELECTRON_ENABLE_STACK_DUMPING=1
|
2019-09-02 15:30:31 +08:00
|
|
|
export ELECTRON_ENABLE_LOGGING=1
|
2019-09-10 07:46:42 +08:00
|
|
|
export VSCODE_LOGS=
|
2015-11-26 16:29:43 +08:00
|
|
|
|
|
|
|
# Launch Code
|
2020-02-17 23:30:55 +08:00
|
|
|
exec "$CODE" . --no-sandbox "$@"
|
2015-11-26 16:29:43 +08:00
|
|
|
}
|
|
|
|
|
2019-04-11 16:23:14 +08:00
|
|
|
function code-wsl()
|
|
|
|
{
|
|
|
|
# in a wsl shell
|
2019-07-29 22:02:58 +08:00
|
|
|
ELECTRON="$ROOT/.build/electron/Code - OSS.exe"
|
|
|
|
if [ -f "$ELECTRON" ]; then
|
|
|
|
local CWD=$(pwd)
|
|
|
|
cd $ROOT
|
|
|
|
export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
|
2019-05-01 07:34:46 +08:00
|
|
|
local WSL_EXT_ID="ms-vscode-remote.remote-wsl"
|
2019-07-29 22:02:58 +08:00
|
|
|
local WSL_EXT_WLOC=$(ELECTRON_RUN_AS_NODE=1 "$ROOT/.build/electron/Code - OSS.exe" "out/cli.js" --locate-extension $WSL_EXT_ID)
|
|
|
|
cd $CWD
|
|
|
|
if [ -n "$WSL_EXT_WLOC" ]; then
|
2019-04-15 19:02:53 +08:00
|
|
|
# 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 $?
|
2019-07-29 22:02:58 +08:00
|
|
|
else
|
|
|
|
echo "Remote WSL not installed, trying to run VSCode in WSL."
|
2019-04-15 19:02:53 +08:00
|
|
|
fi
|
2019-04-11 16:23:14 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-15 19:02:53 +08:00
|
|
|
if ! [ -z ${IN_WSL+x} ]; then
|
2019-04-11 16:23:14 +08:00
|
|
|
code-wsl "$@"
|
2019-04-15 19:02:53 +08:00
|
|
|
fi
|
2019-07-29 22:02:58 +08:00
|
|
|
code "$@"
|