#!/bin/bash # builds the vs code extension, with the language server inside it: the tinyvm # javascript vm (built from src/js/tinyvm.ts) and the server's image # (build/js/lsp.bin and its map in lsp.json, from build/lsp), and the wasm server # (src/tools/mklspwasm.sh) when clang can build it. needs node and tsc; the # server build (src/tools/mklsp.sh) runs first if build/lsp is missing. # # everything generated lands in build/: the server files in # build/editors/vscode/server, the packing copy of the extension in build/vsix. # src/tools/mkvsix.sh [outfile.vsix] set -e case "${1:-}" in --help|-h) printf '%s\n' 'usage: src/tools/mkvsix.sh [OUTFILE.vsix]' 'builds and packages the vscode extension; defaults to build/zc-language-support.vsix.' 'requires node, tsc and vsce; includes the wasm server when clang supports wasm32.' 'environment: VSCE selects the extension packager.'; exit 0 ;; -*) echo "mkvsix: unknown option $1; use --help for usage" >&2; exit 2 ;; esac cd "$(dirname "$0")/../.." OUT=${1:-$PWD/build/zc-language-support.vsix} case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac mkdir -p "$(dirname "$OUT")" JS=build/js STAGE=build/editors/vscode/server bash src/tools/mklsp.sh build/lsp >/dev/null # typescript errors stop packaging, so broken generated code is never shipped. command -v tsc >/dev/null || { echo "mkvsix: tsc is not installed" >&2; exit 1; } make --no-print-directory build/js/layout.js >/dev/null tsc src/js/tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir "$JS" node src/js/extract_lsp.js mkdir -p "$STAGE" cp "$JS/tinyvm.js" "$JS/layout.js" "$JS/lsp.json" "$JS/lsp.bin" "$STAGE/" # the wasm server runs when there is one; without clang the vm server is packed alone if sh src/tools/findcc.sh --wasm >/dev/null 2>&1; then LSP_BUILD_DIR=build/lsp LSP_REUSE_BUILD=1 bash src/tools/mklspwasm.sh "$STAGE/lsp.wasm" else rm -f "$STAGE/lsp.wasm" echo "no clang with wasm32 and #embed: packing the javascript vm server only" >&2 fi # vsce packs a whole extension directory, so the extension is copied into # build/vsix/extension with the server beside its client, and packed there. the # tree is never written to. PACKROOT=build/vsix/extension rm -rf "$PACKROOT" mkdir -p "$PACKROOT" cp -R editors/vscode/. "$PACKROOT/" mkdir -p "$PACKROOT/server" cp "$STAGE"/* "$PACKROOT/server/" cd "$PACKROOT" if [ -n "${VSCE:-}" ]; then "$VSCE" package --allow-missing-repository --skip-license -o "$OUT" >/dev/null elif command -v vsce >/dev/null; then vsce package --allow-missing-repository --skip-license -o "$OUT" >/dev/null else npx -y @vscode/vsce package --allow-missing-repository --skip-license -o "$OUT" >/dev/null fi echo "$OUT"