|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Builds vscode into lib/vscode/out-vscode. |
| 5 | + |
| 6 | +# MINIFY controls whether a minified version of vscode is built. |
| 7 | +MINIFY=${MINIFY-true} |
| 8 | + |
| 9 | +delete-bin-script() { |
| 10 | + rm -f "lib/vscode-reh-web-linux-x64/bin/$1" |
| 11 | +} |
| 12 | + |
| 13 | +copy-bin-script() { |
| 14 | + local script="$1" |
| 15 | + local dest="lib/vscode-reh-web-linux-x64/bin/$script" |
| 16 | + cp "lib/vscode/resources/server/bin/$script" "$dest" |
| 17 | + sed -i.bak "s/@@VERSION@@/$(vscode_version)/g" "$dest" |
| 18 | + sed -i.bak "s/@@COMMIT@@/$BUILD_SOURCEVERSION/g" "$dest" |
| 19 | + sed -i.bak "s/@@APPNAME@@/code-server/g" "$dest" |
| 20 | + |
| 21 | + # Fix Node path on Darwin and Linux. |
| 22 | + # We do not want expansion here; this text should make it to the file as-is. |
| 23 | + # shellcheck disable=SC2016 |
| 24 | + sed -i.bak 's/^ROOT=\(.*\)$/VSROOT=\1\nROOT="$(dirname "$(dirname "$VSROOT")")"/g' "$dest" |
| 25 | + sed -i.bak 's/ROOT\/out/VSROOT\/out/g' "$dest" |
| 26 | + # We do not want expansion here; this text should make it to the file as-is. |
| 27 | + # shellcheck disable=SC2016 |
| 28 | + sed -i.bak 's/$ROOT\/node/${NODE_EXEC_PATH:-$ROOT\/lib\/node}/g' "$dest" |
| 29 | + |
| 30 | + # Fix Node path on Windows. |
| 31 | + sed -i.bak 's/^set ROOT_DIR=\(.*\)$/set ROOT_DIR=%~dp0..\\..\\..\\..\r\nset VSROOT_DIR=\1/g' "$dest" |
| 32 | + sed -i.bak 's/%ROOT_DIR%\\out/%VSROOT_DIR%\\out/g' "$dest" |
| 33 | + |
| 34 | + chmod +x "$dest" |
| 35 | + rm "$dest.bak" |
| 36 | +} |
| 37 | + |
| 38 | +main() { |
| 39 | + cd "$(dirname "${0}")/../.." |
| 40 | + |
| 41 | + source ./ci/lib.sh |
| 42 | + |
| 43 | + # Set the commit Code will embed into the product.json. We need to do this |
| 44 | + # since Code tries to get the commit from the `.git` directory which will fail |
| 45 | + # as it is a submodule. |
| 46 | + # |
| 47 | + # Also, we use code-server's commit rather than VS Code's otherwise it would |
| 48 | + # not update when only our patch files change, and that will cause caching |
| 49 | + # issues where the browser keeps using outdated code. |
| 50 | + export BUILD_SOURCEVERSION |
| 51 | + BUILD_SOURCEVERSION=$(git rev-parse HEAD) |
| 52 | + |
| 53 | + pushd lib/vscode |
| 54 | + |
| 55 | + if [[ ! ${VERSION-} ]]; then |
| 56 | + echo "VERSION not set. Please set before running this script:" |
| 57 | + echo "VERSION='0.0.0' npm run build:vscode" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + |
| 61 | + # Add the date, our name, links, enable telemetry (this just makes telemetry |
| 62 | + # available; telemetry can still be disabled by flag or setting), and |
| 63 | + # configure trusted extensions (since some, like github.copilot-chat, never |
| 64 | + # ask to be trusted and this is the only way to get auth working). |
| 65 | + # |
| 66 | + # This needs to be done before building as Code will read this file and embed |
| 67 | + # it into the client-side code. |
| 68 | + git checkout product.json # Reset in case the script exited early. |
| 69 | + cp product.json product.original.json # Since jq has no inline edit. |
| 70 | + jq --slurp '.[0] * .[1]' product.original.json <( |
| 71 | + cat << EOF |
| 72 | + { |
| 73 | + "enableTelemetry": true, |
| 74 | + "quality": "stable", |
| 75 | + "codeServerVersion": "$VERSION", |
| 76 | + "nameShort": "code-server", |
| 77 | + "nameLong": "code-server", |
| 78 | + "applicationName": "code-server", |
| 79 | + "dataFolderName": ".code-server", |
| 80 | + "win32MutexName": "codeserver", |
| 81 | + "licenseUrl": "https://github.com/coder/code-server/blob/main/LICENSE", |
| 82 | + "win32DirName": "code-server", |
| 83 | + "win32NameVersion": "code-server", |
| 84 | + "win32AppUserModelId": "coder.code-server", |
| 85 | + "win32ShellNameShort": "c&ode-server", |
| 86 | + "darwinBundleIdentifier": "com.coder.code.server", |
| 87 | + "linuxIconName": "com.coder.code.server", |
| 88 | + "reportIssueUrl": "https://github.com/coder/code-server/issues/new", |
| 89 | + "documentationUrl": "https://go.microsoft.com/fwlink/?LinkID=533484#vscode", |
| 90 | + "keyboardShortcutsUrlMac": "https://go.microsoft.com/fwlink/?linkid=832143", |
| 91 | + "keyboardShortcutsUrlLinux": "https://go.microsoft.com/fwlink/?linkid=832144", |
| 92 | + "keyboardShortcutsUrlWin": "https://go.microsoft.com/fwlink/?linkid=832145", |
| 93 | + "introductoryVideosUrl": "https://go.microsoft.com/fwlink/?linkid=832146", |
| 94 | + "tipsAndTricksUrl": "https://go.microsoft.com/fwlink/?linkid=852118", |
| 95 | + "newsletterSignupUrl": "https://www.research.net/r/vsc-newsletter", |
| 96 | + "linkProtectionTrustedDomains": [ |
| 97 | + "https://open-vsx.org" |
| 98 | + ], |
| 99 | + "trustedExtensionAuthAccess": [ |
| 100 | + "vscode.git", "vscode.github", |
| 101 | + "github.vscode-pull-request-github", |
| 102 | + "github.copilot", "github.copilot-chat" |
| 103 | + ], |
| 104 | + "aiConfig": { |
| 105 | + "ariaKey": "code-server" |
| 106 | + } |
| 107 | + } |
| 108 | +EOF |
| 109 | + ) > product.json |
| 110 | + |
| 111 | + # Any platform here works since we will do our own packaging. We have to do |
| 112 | + # this because we have an NPM package that could be installed on any platform. |
| 113 | + # The correct platform dependencies and scripts will be installed as part of |
| 114 | + # the post-install during `npm install` or when building a standalone release. |
| 115 | + node --max-old-space-size=16384 --optimize-for-size \ |
| 116 | + ./node_modules/gulp/bin/gulp.js \ |
| 117 | + "vscode-reh-web-linux-x64${MINIFY:+-min}" |
| 118 | + |
| 119 | + # Reset so if you develop after building you will not be stuck with the wrong |
| 120 | + # commit (the dev client will use `oss-dev` but the dev server will still use |
| 121 | + # product.json which will have `stable-$commit`). |
| 122 | + git checkout product.json |
| 123 | + |
| 124 | + popd |
| 125 | + |
| 126 | + pushd lib/vscode-reh-web-linux-x64 |
| 127 | + # Make sure Code took the version we set in the environment variable. Not |
| 128 | + # having a version will break display languages. |
| 129 | + if ! jq -e .commit product.json; then |
| 130 | + echo "'commit' is missing from product.json" |
| 131 | + exit 1 |
| 132 | + fi |
| 133 | + popd |
| 134 | + |
| 135 | + # These provide a `code-server` command in the integrated terminal to open |
| 136 | + # files in the current instance. |
| 137 | + delete-bin-script remote-cli/code-server |
| 138 | + copy-bin-script remote-cli/code-darwin.sh |
| 139 | + copy-bin-script remote-cli/code-linux.sh |
| 140 | + copy-bin-script remote-cli/code.cmd |
| 141 | + |
| 142 | + # These provide a way for terminal applications to open browser windows. |
| 143 | + delete-bin-script helpers/browser.sh |
| 144 | + copy-bin-script helpers/browser-darwin.sh |
| 145 | + copy-bin-script helpers/browser-linux.sh |
| 146 | + copy-bin-script helpers/browser.cmd |
| 147 | +} |
| 148 | + |
| 149 | +main "$@" |
0 commit comments