mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add orpc
This commit is contained in:
@@ -1,29 +1,30 @@
|
||||
import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type {
|
||||
ProjectAddons,
|
||||
ProjectFrontend,
|
||||
ProjectPackageManager,
|
||||
} from "../types";
|
||||
import type { ProjectFrontend } from "../types";
|
||||
import { addPackageDependency } from "../utils/add-package-deps";
|
||||
import { setupStarlight } from "./starlight-setup";
|
||||
import { setupTauri } from "./tauri-setup";
|
||||
|
||||
export async function setupAddons(
|
||||
projectDir: string,
|
||||
addons: ProjectAddons[],
|
||||
packageManager: ProjectPackageManager,
|
||||
frontends: ProjectFrontend[],
|
||||
) {
|
||||
import type { ProjectConfig } from "../types";
|
||||
|
||||
export async function setupAddons(config: ProjectConfig) {
|
||||
const { projectName, addons, packageManager, frontend } = config;
|
||||
const projectDir = path.resolve(process.cwd(), projectName);
|
||||
const hasWebFrontend =
|
||||
frontends.includes("react-router") || frontends.includes("tanstack-router");
|
||||
frontend.includes("react-router") || frontend.includes("tanstack-router");
|
||||
|
||||
if (addons.includes("turborepo")) {
|
||||
await addPackageDependency({
|
||||
devDependencies: ["turbo"],
|
||||
projectDir,
|
||||
});
|
||||
}
|
||||
|
||||
if (addons.includes("pwa") && hasWebFrontend) {
|
||||
await setupPwa(projectDir, frontends);
|
||||
await setupPwa(projectDir, frontend);
|
||||
}
|
||||
if (addons.includes("tauri") && hasWebFrontend) {
|
||||
await setupTauri(projectDir, packageManager, frontends);
|
||||
await setupTauri(config);
|
||||
}
|
||||
if (addons.includes("biome")) {
|
||||
await setupBiome(projectDir);
|
||||
@@ -32,7 +33,7 @@ export async function setupAddons(
|
||||
await setupHusky(projectDir);
|
||||
}
|
||||
if (addons.includes("starlight")) {
|
||||
await setupStarlight(projectDir, packageManager);
|
||||
await setupStarlight(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +45,7 @@ export function getWebAppDir(
|
||||
}
|
||||
|
||||
async function setupBiome(projectDir: string) {
|
||||
const biomeTemplateDir = path.join(PKG_ROOT, "template/with-biome");
|
||||
if (await fs.pathExists(biomeTemplateDir)) {
|
||||
await fs.copy(biomeTemplateDir, projectDir, { overwrite: true });
|
||||
}
|
||||
|
||||
addPackageDependency({
|
||||
await addPackageDependency({
|
||||
devDependencies: ["@biomejs/biome"],
|
||||
projectDir,
|
||||
});
|
||||
@@ -68,12 +64,7 @@ async function setupBiome(projectDir: string) {
|
||||
}
|
||||
|
||||
async function setupHusky(projectDir: string) {
|
||||
const huskyTemplateDir = path.join(PKG_ROOT, "template/with-husky");
|
||||
if (await fs.pathExists(huskyTemplateDir)) {
|
||||
await fs.copy(huskyTemplateDir, projectDir, { overwrite: true });
|
||||
}
|
||||
|
||||
addPackageDependency({
|
||||
await addPackageDependency({
|
||||
devDependencies: ["husky", "lint-staged"],
|
||||
projectDir,
|
||||
});
|
||||
@@ -98,81 +89,18 @@ async function setupHusky(projectDir: string) {
|
||||
}
|
||||
|
||||
async function setupPwa(projectDir: string, frontends: ProjectFrontend[]) {
|
||||
const pwaTemplateDir = path.join(PKG_ROOT, "template/with-pwa");
|
||||
if (await fs.pathExists(pwaTemplateDir)) {
|
||||
await fs.copy(pwaTemplateDir, projectDir, { overwrite: true });
|
||||
}
|
||||
|
||||
const clientPackageDir = getWebAppDir(projectDir, frontends);
|
||||
|
||||
if (!(await fs.pathExists(clientPackageDir))) {
|
||||
return;
|
||||
}
|
||||
|
||||
addPackageDependency({
|
||||
await addPackageDependency({
|
||||
dependencies: ["vite-plugin-pwa"],
|
||||
devDependencies: ["@vite-pwa/assets-generator"],
|
||||
projectDir: clientPackageDir,
|
||||
});
|
||||
|
||||
const viteConfigPath = path.join(clientPackageDir, "vite.config.ts");
|
||||
if (await fs.pathExists(viteConfigPath)) {
|
||||
let viteConfig = await fs.readFile(viteConfigPath, "utf8");
|
||||
|
||||
if (!viteConfig.includes("vite-plugin-pwa")) {
|
||||
const firstImportMatch = viteConfig.match(
|
||||
/^import .* from ['"](.*)['"]/m,
|
||||
);
|
||||
|
||||
if (firstImportMatch) {
|
||||
viteConfig = viteConfig.replace(
|
||||
firstImportMatch[0],
|
||||
`import { VitePWA } from "vite-plugin-pwa";\n${firstImportMatch[0]}`,
|
||||
);
|
||||
} else {
|
||||
viteConfig = `import { VitePWA } from "vite-plugin-pwa";\n${viteConfig}`;
|
||||
}
|
||||
}
|
||||
|
||||
const pwaPluginCode = `VitePWA({
|
||||
registerType: "autoUpdate",
|
||||
manifest: {
|
||||
name: "My App",
|
||||
short_name: "My App",
|
||||
description: "My App",
|
||||
theme_color: "#0c0c0c",
|
||||
},
|
||||
pwaAssets: {
|
||||
disabled: false,
|
||||
config: true,
|
||||
},
|
||||
devOptions: {
|
||||
enabled: true,
|
||||
},
|
||||
})`;
|
||||
|
||||
if (!viteConfig.includes("VitePWA(")) {
|
||||
if (frontends.includes("react-router")) {
|
||||
viteConfig = viteConfig.replace(
|
||||
/plugins: \[\s*tailwindcss\(\)/,
|
||||
`plugins: [\n tailwindcss(),\n ${pwaPluginCode}`,
|
||||
);
|
||||
} else if (frontends.includes("tanstack-router")) {
|
||||
viteConfig = viteConfig.replace(
|
||||
/plugins: \[\s*tailwindcss\(\)/,
|
||||
`plugins: [\n tailwindcss(),\n ${pwaPluginCode}`,
|
||||
);
|
||||
} else {
|
||||
viteConfig = viteConfig.replace(
|
||||
/plugins: \[/,
|
||||
`plugins: [\n ${pwaPluginCode},`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await fs.writeFile(viteConfigPath, viteConfig);
|
||||
}
|
||||
|
||||
const clientPackageJsonPath = path.join(clientPackageDir, "package.json");
|
||||
if (await fs.pathExists(clientPackageJsonPath)) {
|
||||
const packageJson = await fs.readJson(clientPackageJsonPath);
|
||||
|
||||
Reference in New Issue
Block a user