From 64d6dafa6a40f396e54de4a0069432198e0ec39e Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Fri, 5 Apr 2024 22:03:01 -0400 Subject: [PATCH] build: Configure deployment previews with Vega Editor (#9294) ## Motivation - A cloudflare-based take on https://github.com/vega/vega-lite/issues/9276 - As discussed w/ @domoritz, Previewing the editor site is probably more useful than the docs site, so we're going after that first ## Changes - Use explicit packageManager version so Cloudflare doesn't autoupgrade to yarn 3 (breaks lockfile) - Add a build script (originally this was a 1-liner in package.json but it was getting hard to read) that - Builds vega-lite - Clones vega/editor and links the local vega-lite in place of the full build - Install `vega/editor` without running the `prepare` script. (The CI device doesn't have rsync installed). - Makes empty index.json for vega / vega-lite examples. - Build editor with vite with `/` as the base URL (previously it was erroring due to thinking it was under the `/editor` subdomain). Technically this is an abstraction leak but fixing it would involve modifying the vega/editor repo too and I'd like to contain this change to 1 repo if possible. ## Testing - See Cloudflare comment below, confirm site loads ## Notes - For now only `cameron.yick/*` branches have the previews since the build script is WIP. It's using my personal Cloudflare account for testing. I'll open it up to all (non dependabot/*) PRs this change is confirmed. - I've filed an request to https://blog.cloudflare.com/cloudflare-new-oss-sponsorships-program to see if we can get deployment previews sponsored (they also sponsor D3, yarn). If not, I'll plan to discuss on Slack whether to keep Cloudflare or switch the config to a different account. - Free plan limits: 500 builds/ month: https://developers.cloudflare.com/pages/platform/limits/ . --- package.json | 4 +++- scripts/build-editor-preview.sh | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 scripts/build-editor-preview.sh diff --git a/package.json b/package.json index b3f4bd5759..9e63f184e6 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "clean": "yarn clean:build && del-cli 'site/data/*' 'examples/compiled/*.png' && find site/examples ! -name 'index.md' ! -name 'data' -type f -delete", "clean:build": "del-cli 'build/*' !build/vega-lite-schema.json", "data": "rsync -r node_modules/vega-datasets/data/* site/data", + "build-editor-preview": "scripts/build-editor-preview.sh", "schema": "mkdir -p build && ts-json-schema-generator -f tsconfig.json -p src/index.ts -t TopLevelSpec --no-type-check --no-ref-encode > build/vega-lite-schema.json && yarn renameschema && cp build/vega-lite-schema.json site/_data/", "renameschema": "scripts/rename-schema.sh", "presite": "yarn data && yarn schema && yarn build:site && yarn build:versions && scripts/create-example-pages.sh", @@ -138,5 +139,6 @@ }, "engines": { "node": ">=18" - } + }, + "packageManager": "yarn@1.22.19" } diff --git a/scripts/build-editor-preview.sh b/scripts/build-editor-preview.sh new file mode 100755 index 0000000000..9057003b9a --- /dev/null +++ b/scripts/build-editor-preview.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# Build the docs site and replace the main build with the local copy of vega-lite +echo "Attempting install" +# apt install rsync + +yarn build +yarn link +git clone https://github.com/vega/editor.git + +# +cd editor +yarn --frozen-lockfile --ignore-scripts +yarn link vega-lite + +# TODO: load in real files if we can get rsync installed in the runner someday? +# Put index.json files in public/spec/vega-lite and public/spec/vega +echo "Creating stub index.json for each vega library" + +mkdir -p public/spec/vega-lite +mkdir -p public/spec/vega +touch public/spec/vega-lite/index.json +touch public/spec/vega/index.json + +cat < public/spec/vega-lite/index.json +{} +EOF + +cat < public/spec/vega/index.json +{} +EOF + +# TBD if some vendor files are needed +yarn run vite build --base /