-
Notifications
You must be signed in to change notification settings - Fork 19
feat: playground #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
olliethedev
wants to merge
9
commits into
main
Choose a base branch
from
feat/playground
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: playground #104
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
51751af
feat: playground
olliethedev acfd7a8
refactor: improve StackBlitz embed functionality and project file han…
olliethedev e355eb7
feat: add custom headers for cross-origin isolation in Next.js config…
olliethedev 28f0127
feat: enhance stackblitz-template to handle workspace-built plugins a…
olliethedev ba90e8f
feat: add active route preview functionality in PlaygroundClient and …
olliethedev de0c24b
refactor: streamline StackBlitz SDK loading and error handling in emb…
olliethedev 6b5ae38
feat: implement useRegisteredRoutes hook for retrieving registered cl…
olliethedev 1435d40
feat: add extraPackages support in project generation and enhance Sta…
olliethedev 11d2f6a
feat: ensure CMS is included in selected plugins when ui-builder is a…
olliethedev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** | ||
| * Programmatic API for @btst/codegen scaffold utilities. | ||
| * Use this when consuming the CLI as a library (e.g. in the playground). | ||
| */ | ||
| export { buildScaffoldPlan } from "./utils/scaffold-plan"; | ||
| export { PLUGINS, ADAPTERS } from "./utils/constants"; | ||
| export { PLUGIN_ROUTES } from "./utils/plugin-routes"; | ||
| export type { | ||
| PluginKey, | ||
| Adapter, | ||
| Framework, | ||
| FileWritePlanItem, | ||
| ScaffoldPlan, | ||
| } from "./types"; | ||
| export type { PluginMeta, AdapterMeta } from "./utils/constants"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** | ||
| * Re-export PLUGIN_ROUTES from constants so it can be imported | ||
| * from either location without bundling issues. | ||
| */ | ||
| export { PLUGIN_ROUTES } from "./constants"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useState } from "react"; | ||
| import { getRegisteredRoutes, type RegisteredRoute } from "./plugin"; | ||
|
|
||
| /** | ||
| * React hook that returns all registered client route paths. | ||
| * Updates whenever the component mounts (after client hydration). | ||
| */ | ||
| export function useRegisteredRoutes(): RegisteredRoute[] { | ||
| const [routes, setRoutes] = useState<RegisteredRoute[]>(() => | ||
| getRegisteredRoutes(), | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| setRoutes(getRegisteredRoutes()); | ||
| }, []); | ||
|
|
||
| return routes; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/dev/types/routes.d.ts"; | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| const config = { | ||
| reactStrictMode: true, | ||
| basePath: "/playground", | ||
| assetPrefix: "/playground", | ||
| serverExternalPackages: ["handlebars"], | ||
| async headers() { | ||
| return [ | ||
| { | ||
| // COOP: same-origin + COEP: credentialless = cross-origin isolation. | ||
| // Required for SharedArrayBuffer, which WebContainers (template: "node") | ||
| // needs to boot. same-origin-allow-popups does NOT provide isolation. | ||
| source: "/(.*)", | ||
| headers: [ | ||
| { key: "Cross-Origin-Opener-Policy", value: "same-origin" }, | ||
| { key: "Cross-Origin-Embedder-Policy", value: "credentialless" }, | ||
| ], | ||
| }, | ||
| ]; | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "btst-playground", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "next build", | ||
| "dev": "next dev --port 3002", | ||
| "start": "next start --port 3002", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "dependencies": { | ||
| "@btst/codegen": "workspace:*", | ||
| "@stackblitz/sdk": "^1.9.0", | ||
| "next": "16.0.10", | ||
| "react": "^19.2.0", | ||
| "react-dom": "^19.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@tailwindcss/postcss": "^4.1.10", | ||
| "@types/node": "^24.0.0", | ||
| "@types/react": "^19.2.2", | ||
| "@types/react-dom": "^19.2.2", | ||
| "postcss": "^8.5.6", | ||
| "tailwindcss": "^4.1.10", | ||
| "typescript": "^5.8.3" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export default { | ||
| plugins: { | ||
| "@tailwindcss/postcss": {}, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| "use server"; | ||
|
|
||
| import { buildScaffoldPlan, PLUGINS, PLUGIN_ROUTES } from "@btst/codegen/lib"; | ||
| import type { PluginKey, FileWritePlanItem } from "@btst/codegen/lib"; | ||
|
|
||
| export interface GenerateResult { | ||
| files: FileWritePlanItem[]; | ||
| routes: string[]; | ||
| cssImports: string[]; | ||
| extraPackages: string[]; | ||
| } | ||
|
|
||
| export async function generateProject( | ||
| plugins: PluginKey[], | ||
| ): Promise<GenerateResult> { | ||
| // ui-builder requires cms | ||
| const selectedPlugins: PluginKey[] = | ||
| plugins.includes("ui-builder") && !plugins.includes("cms") | ||
| ? ["cms", ...plugins] | ||
olliethedev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| : plugins; | ||
|
|
||
| // Always include route-docs so users can see all available routes | ||
| const withRouteDocs: PluginKey[] = selectedPlugins.includes("route-docs") | ||
| ? selectedPlugins | ||
| : [...selectedPlugins, "route-docs"]; | ||
|
|
||
| const plan = await buildScaffoldPlan({ | ||
| framework: "nextjs", | ||
| adapter: "memory", | ||
| plugins: withRouteDocs, | ||
| alias: "@/", | ||
| cssFile: "app/globals.css", | ||
| }); | ||
|
|
||
| const cssImports = PLUGINS.filter((p) => | ||
| withRouteDocs.includes(p.key as PluginKey), | ||
| ) | ||
| .map((p) => p.cssImport) | ||
| .filter((c): c is string => Boolean(c)); | ||
|
|
||
| const routes = withRouteDocs.flatMap((p) => PLUGIN_ROUTES[p] ?? []); | ||
| const extraPackages = Array.from( | ||
| new Set( | ||
| PLUGINS.filter((p) => withRouteDocs.includes(p.key as PluginKey)).flatMap( | ||
| (p) => p.extraPackages ?? [], | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| return { | ||
| files: plan.files, | ||
| routes, | ||
| cssImports, | ||
| extraPackages, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @import "tailwindcss"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { Metadata } from "next"; | ||
| import type { ReactNode } from "react"; | ||
| import "./globals.css"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: { | ||
| default: "BTST Playground", | ||
| template: "%s | BTST Playground", | ||
| }, | ||
| description: | ||
| "Build a BTST project in your browser — select plugins and see them live in a StackBlitz WebContainer.", | ||
| }; | ||
|
|
||
| export default function RootLayout({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <html lang="en" suppressHydrationWarning> | ||
| <body className="min-h-screen bg-zinc-50 dark:bg-zinc-950 text-zinc-900 dark:text-zinc-100 antialiased"> | ||
| {children} | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
typescondition in package exports mapMedium Severity
The newly added
exportsmap lackstypesconditions for both"."and"./lib"entries. Before this PR, TypeScript resolved types via the top-level"types"field. Now thatexportsis present, TypeScript withmoduleResolution: "bundler"or"node16"usesexportsinstead and ignores the top-level"types"fallback. The"./lib"export is especially at risk since it has notypesfallback at all — TypeScript must infer the declaration file from./dist/lib.mjs, which only works if unbuild produces a.d.ts(not.d.mts) that TypeScript's heuristic can discover.