Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demos/ai-chat/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
# misc
.DS_Store
*.pem
.btst-stack-src/
.btst-stack-ui/
9 changes: 9 additions & 0 deletions demos/ai-chat/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
@import "tw-animate-css";
@import "@btst/stack/plugins/ai-chat/css";
@import "@btst/stack/plugins/route-docs/css";
/* WebContainers workaround: the WASM Tailwind scanner cannot traverse node_modules
* (https://github.com/tailwindlabs/tailwindcss/issues/18418). copy-stack-src.mjs
* (run via predev/prebuild) copies @btst/stack/src outside node_modules so Tailwind
* can scan it. Safe to remove once the upstream bug is fixed. */
@source "./.btst-stack-src/**/*.{ts,tsx}";
@source "./.btst-stack-ui/**/*.{ts,tsx}";
/* Monorepo fallback: direct source path used in local development */
@source "../../../packages/stack/src/**/*.{ts,tsx}";
@source "../../../packages/ui/src/**/*.{ts,tsx}";

@custom-variant dark (&:is(.dark *));

Expand Down
45 changes: 45 additions & 0 deletions demos/ai-chat/copy-stack-src.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* Copies @btst/stack/src outside of node_modules so Tailwind's WASM scanner
* (used in WebContainers/StackBlitz) can traverse it.
*
* The WASM oxide scanner cannot scan inside node_modules due to a bug:
* https://github.com/tailwindlabs/tailwindcss/issues/18418
*
* Run automatically via the predev/prebuild npm lifecycle hooks.
*/
import { cp, mkdir, rm } from "fs/promises";
import { existsSync } from "fs";

const src = "node_modules/@btst/stack/src";
const dest = ".btst-stack-src";

const uiSrc = "node_modules/@btst/stack/dist/packages/ui";
const uiDest = ".btst-stack-ui";

if (!existsSync(src)) {
// Likely running in the monorepo where the workspace symlink does not expose
// src/ — fall back gracefully; @source paths in globals.css cover this case.
console.log(
"[copy-stack-src] node_modules/@btst/stack/src not found, skipping",
);
process.exit(0);
}

await rm(dest, { recursive: true, force: true });
await mkdir(dest, { recursive: true });
await cp(src, dest, { recursive: true });
console.log("[copy-stack-src] copied @btst/stack/src → .btst-stack-src");

if (existsSync(uiSrc)) {
await rm(uiDest, { recursive: true, force: true });
await mkdir(uiDest, { recursive: true });
await cp(uiSrc, uiDest, { recursive: true });
console.log(
"[copy-stack-src] copied @btst/stack/dist/packages/ui → .btst-stack-ui",
);
} else {
console.log(
"[copy-stack-src] node_modules/@btst/stack/dist/packages/ui not found, skipping",
);
}
8 changes: 4 additions & 4 deletions demos/ai-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "node copy-stack-src.mjs && next dev",
"build": "node copy-stack-src.mjs && next build",
"start": "next start"
},
"dependencies": {
"@ai-sdk/openai": "^3.0.41",
"@ai-sdk/react": "^3.0.118",
"@btst/adapter-memory": "^2.0.3",
"@btst/stack": "^2.5.1",
"@btst/stack": "^2.5.2",
"@btst/yar": "^1.2.0",
"@hookform/resolvers": "^5.2.2",
"@radix-ui/react-dialog": "^1.1.15",
Expand All @@ -29,7 +29,7 @@
"highlight.js": "^11.11.1",
"katex": "^0.16.35",
"lucide-react": "^0.577.0",
"next": "16.1.6",
"next": "15.4.1",
"next-themes": "^0.4.6",
"radix-ui": "^1.4.3",
"react": "19.2.3",
Expand Down
2 changes: 2 additions & 0 deletions demos/blog/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
# misc
.DS_Store
*.pem
.btst-stack-src/
.btst-stack-ui/
9 changes: 9 additions & 0 deletions demos/blog/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
@import "tw-animate-css";
@import "@btst/stack/plugins/blog/css";
@import "@btst/stack/plugins/route-docs/css";
/* WebContainers workaround: the WASM Tailwind scanner cannot traverse node_modules
* (https://github.com/tailwindlabs/tailwindcss/issues/18418). copy-stack-src.mjs
* (run via predev/prebuild) copies @btst/stack/src outside node_modules so Tailwind
* can scan it. Safe to remove once the upstream bug is fixed. */
@source "./.btst-stack-src/**/*.{ts,tsx}";
@source "./.btst-stack-ui/**/*.{ts,tsx}";
/* Monorepo fallback: direct source path used in local development */
@source "../../../packages/stack/src/**/*.{ts,tsx}";
@source "../../../packages/ui/src/**/*.{ts,tsx}";

@custom-variant dark (&:is(.dark *));

Expand Down
45 changes: 45 additions & 0 deletions demos/blog/copy-stack-src.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* Copies @btst/stack/src outside of node_modules so Tailwind's WASM scanner
* (used in WebContainers/StackBlitz) can traverse it.
*
* The WASM oxide scanner cannot scan inside node_modules due to a bug:
* https://github.com/tailwindlabs/tailwindcss/issues/18418
*
* Run automatically via the predev/prebuild npm lifecycle hooks.
*/
import { cp, mkdir, rm } from "fs/promises";
import { existsSync } from "fs";

const src = "node_modules/@btst/stack/src";
const dest = ".btst-stack-src";

const uiSrc = "node_modules/@btst/stack/dist/packages/ui";
const uiDest = ".btst-stack-ui";

if (!existsSync(src)) {
// Likely running in the monorepo where the workspace symlink does not expose
// src/ — fall back gracefully; @source paths in globals.css cover this case.
console.log(
"[copy-stack-src] node_modules/@btst/stack/src not found, skipping",
);
process.exit(0);
}

await rm(dest, { recursive: true, force: true });
await mkdir(dest, { recursive: true });
await cp(src, dest, { recursive: true });
console.log("[copy-stack-src] copied @btst/stack/src → .btst-stack-src");

if (existsSync(uiSrc)) {
await rm(uiDest, { recursive: true, force: true });
await mkdir(uiDest, { recursive: true });
await cp(uiSrc, uiDest, { recursive: true });
console.log(
"[copy-stack-src] copied @btst/stack/dist/packages/ui → .btst-stack-ui",
);
} else {
console.log(
"[copy-stack-src] node_modules/@btst/stack/dist/packages/ui not found, skipping",
);
}
5 changes: 0 additions & 5 deletions demos/blog/lib/seed.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { Adapter } from "@btst/stack/plugins/api";

let seeded = false;

export async function seedBlogData(adapter: Adapter) {
if (seeded) return;
seeded = true;

try {
// Check if posts already exist
const existing = await adapter.findMany({ model: "post", limit: 1 });
Expand Down
8 changes: 6 additions & 2 deletions demos/blog/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { blogBackendPlugin } from "@btst/stack/plugins/blog/api";
import { openApiBackendPlugin } from "@btst/stack/plugins/open-api/api";
import { seedBlogData } from "./seed";

// Persist stack and seed promise on `global` so Next.js module re-evaluations
// (HMR, per-request server components) don't create a second instance or re-run the seed.
const globalForStack = global as typeof global & {
__btst_stack__?: ReturnType<typeof createStack>;
__btst_seeded__?: Promise<void>;
};

function createStack() {
Expand All @@ -25,7 +28,8 @@ function createStack() {

export const myStack = (globalForStack.__btst_stack__ ??= createStack());

// Seed demo data after singleton is created
seedBlogData(myStack.adapter).catch(console.error);
globalForStack.__btst_seeded__ ??= seedBlogData(myStack.adapter).catch(
console.error,
);

export const { handler, dbSchema } = myStack;
8 changes: 4 additions & 4 deletions demos/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "node copy-stack-src.mjs && next dev",
"build": "node copy-stack-src.mjs && next build",
"start": "next start"
},
"dependencies": {
"@ai-sdk/react": "^3.0.118",
"@btst/adapter-memory": "^2.0.3",
"@btst/stack": "^2.5.1",
"@btst/stack": "^2.5.2",
"@btst/yar": "^1.2.0",
"@hookform/resolvers": "^5.2.2",
"@radix-ui/react-dialog": "^1.1.15",
Expand All @@ -28,7 +28,7 @@
"highlight.js": "^11.11.1",
"katex": "^0.16.35",
"lucide-react": "^0.577.0",
"next": "16.1.6",
"next": "15.4.1",
"next-themes": "^0.4.6",
"radix-ui": "^1.4.3",
"react": "19.2.3",
Expand Down
2 changes: 2 additions & 0 deletions demos/cms/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
# misc
.DS_Store
*.pem
.btst-stack-src/
.btst-stack-ui/
9 changes: 9 additions & 0 deletions demos/cms/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
@import "tw-animate-css";
@import "@btst/stack/plugins/cms/css";
@import "@btst/stack/plugins/route-docs/css";
/* WebContainers workaround: the WASM Tailwind scanner cannot traverse node_modules
* (https://github.com/tailwindlabs/tailwindcss/issues/18418). copy-stack-src.mjs
* (run via predev/prebuild) copies @btst/stack/src outside node_modules so Tailwind
* can scan it. Safe to remove once the upstream bug is fixed. */
@source "./.btst-stack-src/**/*.{ts,tsx}";
@source "./.btst-stack-ui/**/*.{ts,tsx}";
/* Monorepo fallback: direct source path used in local development */
@source "../../../packages/stack/src/**/*.{ts,tsx}";
@source "../../../packages/ui/src/**/*.{ts,tsx}";

@custom-variant dark (&:is(.dark *));

Expand Down
45 changes: 45 additions & 0 deletions demos/cms/copy-stack-src.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* Copies @btst/stack/src outside of node_modules so Tailwind's WASM scanner
* (used in WebContainers/StackBlitz) can traverse it.
*
* The WASM oxide scanner cannot scan inside node_modules due to a bug:
* https://github.com/tailwindlabs/tailwindcss/issues/18418
*
* Run automatically via the predev/prebuild npm lifecycle hooks.
*/
import { cp, mkdir, rm } from "fs/promises";
import { existsSync } from "fs";

const src = "node_modules/@btst/stack/src";
const dest = ".btst-stack-src";

const uiSrc = "node_modules/@btst/stack/dist/packages/ui";
const uiDest = ".btst-stack-ui";

if (!existsSync(src)) {
// Likely running in the monorepo where the workspace symlink does not expose
// src/ — fall back gracefully; @source paths in globals.css cover this case.
console.log(
"[copy-stack-src] node_modules/@btst/stack/src not found, skipping",
);
process.exit(0);
}

await rm(dest, { recursive: true, force: true });
await mkdir(dest, { recursive: true });
await cp(src, dest, { recursive: true });
console.log("[copy-stack-src] copied @btst/stack/src → .btst-stack-src");

if (existsSync(uiSrc)) {
await rm(uiDest, { recursive: true, force: true });
await mkdir(uiDest, { recursive: true });
await cp(uiSrc, uiDest, { recursive: true });
console.log(
"[copy-stack-src] copied @btst/stack/dist/packages/ui → .btst-stack-ui",
);
} else {
console.log(
"[copy-stack-src] node_modules/@btst/stack/dist/packages/ui not found, skipping",
);
}
5 changes: 0 additions & 5 deletions demos/cms/lib/seed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
let seeded = false;

export async function seedCmsData(api: any) {
if (seeded) return;
seeded = true;

try {
// Check if articles already exist (getAllContentItems also calls ensureSynced)
const existing = await api.cms.getAllContentItems("article", { limit: 1 });
Expand Down
8 changes: 6 additions & 2 deletions demos/cms/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { cmsBackendPlugin } from "@btst/stack/plugins/cms/api";
import { openApiBackendPlugin } from "@btst/stack/plugins/open-api/api";
import { z } from "zod";
import { seedCmsData } from "./seed";
// Persist stack and seed promise on `global` so Next.js module re-evaluations
// (HMR, per-request server components) don't create a second instance or re-run the seed.
const globalForStack = global as typeof global & {
__btst_stack__?: ReturnType<typeof createStack>;
__btst_seeded__?: Promise<void>;
};

// Simple article content type
Expand Down Expand Up @@ -45,7 +48,8 @@ function createStack() {

export const myStack = (globalForStack.__btst_stack__ ??= createStack());

// Seed demo data — uses api.cms.createContentItem which calls ensureSynced internally
seedCmsData(myStack.api).catch(console.error);
globalForStack.__btst_seeded__ ??= seedCmsData(myStack.api).catch(
console.error,
);

export const { handler, dbSchema } = myStack;
8 changes: 4 additions & 4 deletions demos/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "node copy-stack-src.mjs && next dev",
"build": "node copy-stack-src.mjs && next build",
"start": "next start"
},
"dependencies": {
"@ai-sdk/react": "^3.0.118",
"@btst/adapter-memory": "^2.0.3",
"@btst/stack": "^2.5.1",
"@btst/stack": "^2.5.2",
"@btst/yar": "^1.2.0",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
Expand Down Expand Up @@ -45,7 +45,7 @@
"highlight.js": "^11.11.1",
"katex": "^0.16.35",
"lucide-react": "^0.577.0",
"next": "16.1.6",
"next": "15.4.1",
"next-themes": "^0.4.6",
"radix-ui": "^1.4.3",
"react": "19.2.3",
Expand Down
2 changes: 2 additions & 0 deletions demos/form-builder/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
# misc
.DS_Store
*.pem
.btst-stack-src/
.btst-stack-ui/
9 changes: 9 additions & 0 deletions demos/form-builder/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
@import "tw-animate-css";
@import "@btst/stack/plugins/form-builder/css";
@import "@btst/stack/plugins/route-docs/css";
/* WebContainers workaround: the WASM Tailwind scanner cannot traverse node_modules
* (https://github.com/tailwindlabs/tailwindcss/issues/18418). copy-stack-src.mjs
* (run via predev/prebuild) copies @btst/stack/src outside node_modules so Tailwind
* can scan it. Safe to remove once the upstream bug is fixed. */
@source "./.btst-stack-src/**/*.{ts,tsx}";
@source "./.btst-stack-ui/**/*.{ts,tsx}";
/* Monorepo fallback: direct source path used in local development */
@source "../../../packages/stack/src/**/*.{ts,tsx}";
@source "../../../packages/ui/src/**/*.{ts,tsx}";

@custom-variant dark (&:is(.dark *));

Expand Down
Loading