mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Add Progressive Web App (PWA) support
Add PWA setup with vite-plugin-pwa, assets generator, and templates Include CLI flag and interactive prompt option for PWA installation
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type { ProjectAddons } from "../types";
|
||||
import { addPackageDependency } from "../utils/add-package-deps";
|
||||
|
||||
export async function setupAddons(projectDir: string, addons: ProjectAddons[]) {
|
||||
if (addons.includes("docker")) {
|
||||
await setupDocker(projectDir);
|
||||
}
|
||||
if (addons.includes("pwa")) {
|
||||
await setupPwa(projectDir);
|
||||
}
|
||||
}
|
||||
|
||||
async function setupDocker(projectDir: string) {
|
||||
@@ -89,3 +94,30 @@ node_modules
|
||||
dockerignoreContent,
|
||||
);
|
||||
}
|
||||
|
||||
async function setupPwa(projectDir: string) {
|
||||
const pwaTemplateDir = path.join(PKG_ROOT, "template/with-pwa");
|
||||
if (await fs.pathExists(pwaTemplateDir)) {
|
||||
await fs.copy(pwaTemplateDir, projectDir, { overwrite: true });
|
||||
}
|
||||
|
||||
const clientPackageDir = path.join(projectDir, "packages/client");
|
||||
|
||||
addPackageDependency({
|
||||
dependencies: ["vite-plugin-pwa"],
|
||||
devDependencies: ["@vite-pwa/assets-generator"],
|
||||
projectDir: clientPackageDir,
|
||||
});
|
||||
|
||||
const clientPackageJsonPath = path.join(clientPackageDir, "package.json");
|
||||
if (await fs.pathExists(clientPackageJsonPath)) {
|
||||
const packageJson = await fs.readJson(clientPackageJsonPath);
|
||||
|
||||
packageJson.scripts = {
|
||||
...packageJson.scripts,
|
||||
"generate-pwa-assets": "pwa-assets-generator",
|
||||
};
|
||||
|
||||
await fs.writeJson(clientPackageJsonPath, packageJson, { spaces: 2 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,15 +135,6 @@ cd packages/server && ${packageManagerRunCmd} db:local
|
||||
`;
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
setup += `
|
||||
3. Generate the authentication schema:
|
||||
\`\`\`bash
|
||||
cd packages/server && ${packageManagerRunCmd} auth:generate
|
||||
\`\`\`
|
||||
`;
|
||||
}
|
||||
|
||||
setup += `
|
||||
${auth ? "4" : "3"}. ${
|
||||
orm === "prisma"
|
||||
|
||||
Reference in New Issue
Block a user