@reliverse/rse
Version:
@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power
39 lines (38 loc) • 1.54 kB
JavaScript
import fs from "@reliverse/relifso";
import path from "node:path";
import { addPackageDependency } from "../../utils/add-package-deps.js";
export async function setupExamples(config) {
const { examples, frontend, backend, projectDir } = config;
if (backend === "convex" || !examples || examples.length === 0 || examples[0] === "none") {
return;
}
if (examples.includes("ai")) {
const clientDir = path.join(projectDir, "apps/web");
const serverDir = path.join(projectDir, "apps/server");
const clientDirExists = await fs.pathExists(clientDir);
const serverDirExists = await fs.pathExists(serverDir);
const hasNuxt = frontend.includes("nuxt");
const hasSvelte = frontend.includes("svelte");
const hasReact = frontend.includes("react-router") || frontend.includes("tanstack-router") || frontend.includes("next") || frontend.includes("tanstack-start") || frontend.includes("native-nativewind") || frontend.includes("native-unistyles");
if (clientDirExists) {
const dependencies = ["ai"];
if (hasNuxt) {
dependencies.push("@ai-sdk/vue");
} else if (hasSvelte) {
dependencies.push("@ai-sdk/svelte");
} else if (hasReact) {
dependencies.push("@ai-sdk/react");
}
await addPackageDependency({
dependencies,
projectDir: clientDir
});
}
if (serverDirExists && backend !== "none") {
await addPackageDependency({
dependencies: ["ai", "@ai-sdk/google"],
projectDir: serverDir
});
}
}
}