2016-02-18 06:47:09 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-11-13 14:39:38 +01:00
|
|
|
|
2019-07-30 16:37:15 +02:00
|
|
|
set -e
|
2019-04-11 10:23:14 +02:00
|
|
|
|
2015-11-13 14:39:38 +01:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
|
2017-02-21 21:22:01 +01:00
|
|
|
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
|
2015-11-13 14:39:38 +01:00
|
|
|
else
|
2017-02-21 21:22:01 +01:00
|
|
|
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
|
2019-04-11 10:23:14 +02:00
|
|
|
if grep -qi Microsoft /proc/version; then
|
|
|
|
IN_WSL=true
|
|
|
|
fi
|
2015-11-13 14:39:38 +01:00
|
|
|
fi
|
|
|
|
|
2015-11-26 09:29:43 +01:00
|
|
|
function code() {
|
2017-02-21 21:22:01 +01:00
|
|
|
cd "$ROOT"
|
2015-11-13 14:39:38 +01:00
|
|
|
|
2016-08-09 17:13:08 +02:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
2016-08-09 17:56:05 +02:00
|
|
|
NAME=`node -p "require('./product.json').nameLong"`
|
2016-08-09 17:13:08 +02:00
|
|
|
CODE="./.build/electron/$NAME.app/Contents/MacOS/Electron"
|
|
|
|
else
|
|
|
|
NAME=`node -p "require('./product.json').applicationName"`
|
2016-08-09 17:57:09 +02:00
|
|
|
CODE=".build/electron/$NAME"
|
2016-08-09 17:13:08 +02:00
|
|
|
fi
|
|
|
|
|
2015-11-26 09:29:43 +01:00
|
|
|
# Node modules
|
2017-11-16 10:47:02 +01:00
|
|
|
test -d node_modules || yarn
|
2015-11-13 14:39:38 +01:00
|
|
|
|
2015-11-26 09:29:43 +01:00
|
|
|
# Get electron
|
2019-10-16 11:15:43 +02:00
|
|
|
yarn electron
|
2015-11-26 09:29:43 +01:00
|
|
|
|
2018-01-29 22:04:27 +01:00
|
|
|
# Manage built-in extensions
|
|
|
|
if [[ "$1" == "--builtin" ]]; then
|
|
|
|
exec "$CODE" build/builtin
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-01-29 12:23:43 +01:00
|
|
|
# Sync built-in extensions
|
|
|
|
node build/lib/builtInExtensions.js
|
2018-01-23 16:40:41 +01:00
|
|
|
|
2015-11-26 10:07:11 +01:00
|
|
|
# Build
|
2019-10-02 15:24:47 +02:00
|
|
|
test -d out || yarn compile
|
2015-11-26 10:07:11 +01:00
|
|
|
|
2015-11-26 09:29:43 +01:00
|
|
|
# Configuration
|
|
|
|
export NODE_ENV=development
|
|
|
|
export VSCODE_DEV=1
|
2016-08-08 16:12:32 +02:00
|
|
|
export VSCODE_CLI=1
|
2015-11-26 09:29:43 +01:00
|
|
|
export ELECTRON_ENABLE_STACK_DUMPING=1
|
2019-09-02 09:30:31 +02:00
|
|
|
export ELECTRON_ENABLE_LOGGING=1
|
2019-09-10 01:46:42 +02:00
|
|
|
export VSCODE_LOGS=
|
2015-11-26 09:29:43 +01:00
|
|
|
|
|
|
|
# Launch Code
|
2020-02-17 16:30:55 +01:00
|
|
|
exec "$CODE" . --no-sandbox "$@"
|
2015-11-26 09:29:43 +01:00
|
|
|
}
|
|
|
|
|
2019-04-11 10:23:14 +02:00
|
|
|
function code-wsl()
|
|
|
|
{
|
2020-03-30 14:45:18 +02:00
|
|
|
HOST_IP=$(powershell.exe -Command "& {(Get-NetIPAddress | Where-Object {\$_.InterfaceAlias -like '*WSL*' -and \$_.AddressFamily -eq 'IPv4'}).IPAddress | Write-Host -NoNewline}")
|
2020-03-30 14:33:49 +02:00
|
|
|
export DISPLAY="$HOST_IP:0"
|
|
|
|
|
2019-04-11 10:23:14 +02:00
|
|
|
# in a wsl shell
|
2019-07-29 16:02:58 +02: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 01:34:46 +02:00
|
|
|
local WSL_EXT_ID="ms-vscode-remote.remote-wsl"
|
2019-07-29 16:02:58 +02: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 13:02:53 +02: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 16:02:58 +02:00
|
|
|
else
|
|
|
|
echo "Remote WSL not installed, trying to run VSCode in WSL."
|
2019-04-15 13:02:53 +02:00
|
|
|
fi
|
2019-04-11 10:23:14 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-15 13:02:53 +02:00
|
|
|
if ! [ -z ${IN_WSL+x} ]; then
|
2019-04-11 10:23:14 +02:00
|
|
|
code-wsl "$@"
|
2019-04-15 13:02:53 +02:00
|
|
|
fi
|
2019-07-29 16:02:58 +02:00
|
|
|
code "$@"
|