From 1d2bdd64912b084f93f333e53bc0829f7da7333a Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Thu, 1 Feb 2024 22:39:10 -1000 Subject: [PATCH] Continuous deployment. --- .eslintignore | 1 + .gitignore | 1 + examples/codemirror/package.json | 2 +- examples/monaco/package.json | 2 +- examples/tiptap/.env.local | 1 - examples/tiptap/.env.template | 1 - examples/tiptap/package.json | 2 +- examples/tiptap/reflect.config.json | 7 ---- package-lock.json | 14 +++---- packages/reflect-yjs/package.json | 2 +- publish-reflect.js | 65 +++++++++++++++++++++++++++++ vercel.json | 3 ++ 12 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 .eslintignore delete mode 100644 examples/tiptap/.env.local delete mode 100644 examples/tiptap/.env.template delete mode 100644 examples/tiptap/reflect.config.json create mode 100644 publish-reflect.js create mode 100644 vercel.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..b8d05c9 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +publish-reflect.js diff --git a/.gitignore b/.gitignore index 06268dd..1a81057 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dist next-env.d.ts .reflect/ **/*.tgz +.DS_Store \ No newline at end of file diff --git a/examples/codemirror/package.json b/examples/codemirror/package.json index 2d3b124..555c251 100644 --- a/examples/codemirror/package.json +++ b/examples/codemirror/package.json @@ -17,7 +17,7 @@ "@codemirror/lang-javascript": "^6.2.1", "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react-dom": "^18.2.17", "@types/react": "^18.2.38", "@vitejs/plugin-react": "^4.2.0", diff --git a/examples/monaco/package.json b/examples/monaco/package.json index bb598c0..506ec06 100644 --- a/examples/monaco/package.json +++ b/examples/monaco/package.json @@ -16,7 +16,7 @@ "devDependencies": { "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react": "^4.2.0", diff --git a/examples/tiptap/.env.local b/examples/tiptap/.env.local deleted file mode 100644 index afb4f39..0000000 --- a/examples/tiptap/.env.local +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_REFLECT_URL=http://127.0.0.1:8080/ diff --git a/examples/tiptap/.env.template b/examples/tiptap/.env.template deleted file mode 100644 index 794399c..0000000 --- a/examples/tiptap/.env.template +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_REFLECT_URL=https://{{appHostname}} diff --git a/examples/tiptap/package.json b/examples/tiptap/package.json index 669638e..658f131 100644 --- a/examples/tiptap/package.json +++ b/examples/tiptap/package.json @@ -20,7 +20,7 @@ "next": "^13.5.4" }, "dependencies": { - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@tiptap/core": "^2.0.4", "@tiptap/extension-code-block-lowlight": "^2.1.13", "@tiptap/extension-collaboration": "^2.0.4", diff --git a/examples/tiptap/reflect.config.json b/examples/tiptap/reflect.config.json deleted file mode 100644 index 9899998..0000000 --- a/examples/tiptap/reflect.config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "server": "./src/reflect/index.ts", - "templates": { - "package.json": "package.json", - ".env.template": ".env.local" - } -} diff --git a/package-lock.json b/package-lock.json index 2eb2c08..525418c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@codemirror/lang-javascript": "^6.2.1", "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react": "^4.2.0", @@ -48,7 +48,7 @@ "devDependencies": { "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react": "^4.2.0", @@ -69,7 +69,7 @@ "name": "reflect-yjs-tiptap", "license": "Apache-2.0", "dependencies": { - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@tiptap/core": "^2.0.4", "@tiptap/extension-code-block-lowlight": "^2.1.13", "@tiptap/extension-collaboration": "^2.0.4", @@ -6847,7 +6847,7 @@ "node": ">=18" }, "peerDependencies": { - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "y-protocols": "^1.0.6", "yjs": "^13.6.10" } @@ -10585,7 +10585,7 @@ "@codemirror/lang-javascript": "^6.2.1", "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react": "^4.2.0", @@ -10606,7 +10606,7 @@ "requires": { "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react": "^4.2.0", @@ -10626,7 +10626,7 @@ "reflect-yjs-tiptap": { "version": "file:examples/tiptap", "requires": { - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "@tiptap/core": "^2.0.4", "@tiptap/extension-code-block-lowlight": "^2.1.13", "@tiptap/extension-collaboration": "^2.0.4", diff --git a/packages/reflect-yjs/package.json b/packages/reflect-yjs/package.json index 075eef9..4a02ee4 100644 --- a/packages/reflect-yjs/package.json +++ b/packages/reflect-yjs/package.json @@ -24,7 +24,7 @@ "test:watch": "vitest watch --browser.provider=playwright --browser.name=chromium --browser.headless" }, "peerDependencies": { - "@rocicorp/reflect": "0.39.202402020122", + "@rocicorp/reflect": "^0.39.202402020122", "y-protocols": "^1.0.6", "yjs": "^13.6.10" }, diff --git a/publish-reflect.js b/publish-reflect.js new file mode 100644 index 0000000..dd57ede --- /dev/null +++ b/publish-reflect.js @@ -0,0 +1,65 @@ +const { spawn } = require("child_process"); +const fs = require("fs"); + +const appBaseName = "reflect-type"; +const refName = getEnv( + process.env.VERCEL_GIT_COMMIT_REF, + "VERCEL_GIT_COMMIT_REF" +); + +const appName = `${appBaseName}-${refName}` + .toLowerCase() + .replace(/^[^a-z]/, "") + .replace(/[^a-z0-9-]/g, "-"); + +publish(); + +async function publish() { + const output = await runCommand("npx", [ + "reflect", + "publish", + "--server-path=./src/reflect/index.ts", + "--reflect-channel=canary", + `--app=${appName}`, + "--auth-key-from-env=REFLECT_AUTH_KEY", + ]); + const lines = output.toString().split("\n"); + const success = lines.findIndex((line) => + line.includes("🎁 Published successfully to:") + ); + const url = lines[success + 1]; + + fs.writeFileSync("./.env", `NEXT_PUBLIC_REFLECT_SERVER=${url}`); +} + +function runCommand(command, args) { + console.log("running command: " + command + " " + args.join(" ")); + return new Promise((resolve, reject) => { + const child = spawn(command, args); + + let output = ""; + child.stdout.on("data", (data) => { + output += data; + process.stdout.write(data); + }); + + child.stderr.on("data", (data) => { + process.stderr.write(data); + }); + + child.on("close", (code) => { + if (code !== 0) { + reject(new Error(`Command failed with exit code ${code}`)); + } else { + resolve(output); + } + }); + }); +} + +function getEnv(v, name) { + if (!v) { + throw new Error("Missing required env var: " + name); + } + return v; +} diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..d4072c1 --- /dev/null +++ b/vercel.json @@ -0,0 +1,3 @@ +{ + "buildCommand": "node publish-reflect.js && turbo run build --force" +}