From 0cd3b42b60c3eafef90d5f19e7733fb0c4642bfd Mon Sep 17 00:00:00 2001 From: David Matejka Date: Wed, 29 May 2024 10:51:25 +0200 Subject: [PATCH] chore(playground): update vite build to get project name from dsn --- packages/playground/admin/vite.config.ts | 51 ++++++++++++++---------- packages/playground/package.json | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/playground/admin/vite.config.ts b/packages/playground/admin/vite.config.ts index 1e332f7f7..c80a36f51 100644 --- a/packages/playground/admin/vite.config.ts +++ b/packages/playground/admin/vite.config.ts @@ -5,30 +5,37 @@ import { defineConfig } from 'vite' import { resolveConfig } from '../../../build/createViteConfig.js' import { resolve } from 'node:path' -export default defineConfig({ - base: '/', - plugins: [ - react(), - { - name: 'rewrite-middleware', - configureServer(serve) { - serve.middlewares.use((req, res, next) => { - if (req.url === '/app' || req.url?.startsWith('/app/') && !req.url?.match(/\.\w+($|\?)/)) { - req.url = '/app/' - } - next() - }) +export default defineConfig(() => { + const dsn = process.argv.find(it => it.includes('://')) + const projectName = dsn ? new URL(dsn).username : null + return ({ + define: projectName ? { + 'import.meta.env.VITE_CONTEMBER_ADMIN_PROJECT_NAME': JSON.stringify(projectName), + } : {}, + base: '/', + plugins: [ + react(), + { + name: 'rewrite-middleware', + configureServer(serve) { + serve.middlewares.use((req, res, next) => { + if (req.url === '/app' || req.url?.startsWith('/app/') && !req.url?.match(/\.\w+($|\?)/)) { + req.url = '/app/' + } + next() + }) + }, }, - }, - ], - resolve: resolveConfig, - build: { - rollupOptions: { - input: { - root: resolve(__dirname, './index.html'), - app: resolve(__dirname, './app/index.html'), + ], + resolve: resolveConfig, + build: { + rollupOptions: { + input: { + root: resolve(__dirname, './index.html'), + app: resolve(__dirname, './app/index.html'), + }, }, }, - }, + }) }) diff --git a/packages/playground/package.json b/packages/playground/package.json index 41ae985e2..e6a49c7dd 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "vite build admin", "contember": "docker-compose run contember-cli", - "deploy": "yarn -- contember deploy playground --admin http://admin-server:4000 --yes", + "deploy": "yarn run build \"$0\" && docker-compose run --no-deps contember-cli deploy \"$@\" --root ", "start": "vite dev admin --port ${VITE_PORT:-3000} --host 0.0.0.0", "test": "vitest --root ./ --environment jsdom" },