mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
several bug fixes
This commit is contained in:
@@ -7,10 +7,7 @@
|
||||
"bin": {
|
||||
"create-better-t-stack": "dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"template"
|
||||
],
|
||||
"files": ["dist", "template"],
|
||||
"keywords": [],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type { PackageManager, ProjectAddons } from "../types";
|
||||
import type { PackageManager, ProjectAddons, ProjectFrontend } from "../types";
|
||||
import { addPackageDependency } from "../utils/add-package-deps";
|
||||
import { setupTauri } from "./tauri-setup";
|
||||
|
||||
@@ -9,14 +9,17 @@ export async function setupAddons(
|
||||
projectDir: string,
|
||||
addons: ProjectAddons[],
|
||||
packageManager: PackageManager,
|
||||
frontends: ProjectFrontend[],
|
||||
) {
|
||||
const hasWebFrontend = frontends.includes("web");
|
||||
|
||||
// if (addons.includes("docker")) {
|
||||
// await setupDocker(projectDir);
|
||||
// }
|
||||
if (addons.includes("pwa")) {
|
||||
if (addons.includes("pwa") && hasWebFrontend) {
|
||||
await setupPwa(projectDir);
|
||||
}
|
||||
if (addons.includes("tauri")) {
|
||||
if (addons.includes("tauri") && hasWebFrontend) {
|
||||
await setupTauri(projectDir, packageManager);
|
||||
}
|
||||
if (addons.includes("biome")) {
|
||||
@@ -89,6 +92,10 @@ async function setupPwa(projectDir: string) {
|
||||
|
||||
const clientPackageDir = path.join(projectDir, "apps/web");
|
||||
|
||||
if (!(await fs.pathExists(clientPackageDir))) {
|
||||
return;
|
||||
}
|
||||
|
||||
addPackageDependency({
|
||||
dependencies: ["vite-plugin-pwa"],
|
||||
devDependencies: ["@vite-pwa/assets-generator"],
|
||||
|
||||
@@ -71,6 +71,7 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
options.examples,
|
||||
options.orm,
|
||||
options.auth,
|
||||
options.frontend,
|
||||
);
|
||||
|
||||
await setupEnvironmentVariables(projectDir, options);
|
||||
@@ -78,7 +79,12 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
await initializeGit(projectDir, options.git);
|
||||
|
||||
if (options.addons.length > 0) {
|
||||
await setupAddons(projectDir, options.addons, options.packageManager);
|
||||
await setupAddons(
|
||||
projectDir,
|
||||
options.addons,
|
||||
options.packageManager,
|
||||
options.frontend,
|
||||
);
|
||||
}
|
||||
|
||||
await updatePackageConfigurations(projectDir, options);
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type { ProjectOrm } from "../types";
|
||||
import type { ProjectFrontend, ProjectOrm } from "../types";
|
||||
|
||||
export async function setupExamples(
|
||||
projectDir: string,
|
||||
examples: string[],
|
||||
orm: ProjectOrm,
|
||||
auth: boolean,
|
||||
frontend: ProjectFrontend[] = ["web"],
|
||||
): Promise<void> {
|
||||
if (examples.includes("todo")) {
|
||||
const hasWebFrontend = frontend.includes("web");
|
||||
|
||||
const webAppExists = await fs.pathExists(path.join(projectDir, "apps/web"));
|
||||
|
||||
if (examples.includes("todo") && hasWebFrontend && webAppExists) {
|
||||
await setupTodoExample(projectDir, orm, auth);
|
||||
} else {
|
||||
await cleanupTodoFiles(projectDir, orm);
|
||||
|
||||
@@ -13,6 +13,10 @@ export async function setupTauri(
|
||||
const s = spinner();
|
||||
const clientPackageDir = path.join(projectDir, "apps/web");
|
||||
|
||||
if (!(await fs.pathExists(clientPackageDir))) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
s.start("Setting up Tauri desktop app support...");
|
||||
|
||||
|
||||
@@ -122,13 +122,13 @@ async function main() {
|
||||
}),
|
||||
...((options.web !== undefined || options.native !== undefined) && {
|
||||
frontend: [
|
||||
...(options.web === false ? [] : options.web === true ? ["web"] : []),
|
||||
...(options.web === false ? [] : ["web"]),
|
||||
...(options.native === false
|
||||
? []
|
||||
: options.native === true
|
||||
? ["native"]
|
||||
: []),
|
||||
] as ProjectFrontend[],
|
||||
].filter(Boolean) as ProjectFrontend[],
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -137,7 +137,6 @@ async function main() {
|
||||
log.message(displayConfig(flagConfig));
|
||||
log.message("");
|
||||
}
|
||||
|
||||
const config = options.yes
|
||||
? {
|
||||
...DEFAULT_CONFIG,
|
||||
@@ -180,6 +179,13 @@ async function main() {
|
||||
runtime: options.runtime
|
||||
? (options.runtime as Runtime)
|
||||
: DEFAULT_CONFIG.runtime,
|
||||
frontend:
|
||||
options.web === false || options.native === true
|
||||
? ([
|
||||
...(options.web === false ? [] : ["web"]),
|
||||
...(options.native ? ["native"] : []),
|
||||
] as ProjectFrontend[])
|
||||
: DEFAULT_CONFIG.frontend,
|
||||
}
|
||||
: await gatherConfig(flagConfig);
|
||||
|
||||
|
||||
@@ -1,38 +1,52 @@
|
||||
import { cancel, isCancel, multiselect } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import { DEFAULT_CONFIG } from "../constants";
|
||||
import type { ProjectAddons } from "../types";
|
||||
import type { ProjectAddons, ProjectFrontend } from "../types";
|
||||
|
||||
export async function getAddonsChoice(
|
||||
Addons?: ProjectAddons[],
|
||||
frontends?: ProjectFrontend[],
|
||||
): Promise<ProjectAddons[]> {
|
||||
if (Addons !== undefined) return Addons;
|
||||
|
||||
const hasWeb = frontends?.includes("web");
|
||||
|
||||
const addonOptions = [
|
||||
{
|
||||
value: "biome" as const,
|
||||
label: "Biome",
|
||||
hint: "Add Biome for linting and formatting",
|
||||
},
|
||||
{
|
||||
value: "husky" as const,
|
||||
label: "Husky",
|
||||
hint: "Add Git hooks with Husky, lint-staged (requires Biome)",
|
||||
},
|
||||
];
|
||||
|
||||
const webAddonOptions = [
|
||||
{
|
||||
value: "pwa" as const,
|
||||
label: "PWA (Progressive Web App)",
|
||||
hint: "Make your app installable and work offline",
|
||||
},
|
||||
{
|
||||
value: "tauri" as const,
|
||||
label: "Tauri Desktop App",
|
||||
hint: "Build native desktop apps from your web frontend",
|
||||
},
|
||||
];
|
||||
|
||||
const options = hasWeb ? [...webAddonOptions, ...addonOptions] : addonOptions;
|
||||
|
||||
const initialValues = DEFAULT_CONFIG.addons.filter(
|
||||
(addon) => hasWeb || (addon !== "pwa" && addon !== "tauri"),
|
||||
);
|
||||
|
||||
const response = await multiselect<ProjectAddons>({
|
||||
message: "Which Addons would you like to add?",
|
||||
options: [
|
||||
{
|
||||
value: "pwa",
|
||||
label: "PWA (Progressive Web App)",
|
||||
hint: "Make your app installable and work offline",
|
||||
},
|
||||
{
|
||||
value: "tauri",
|
||||
label: "Tauri Desktop App",
|
||||
hint: "Build native desktop apps from your web frontend",
|
||||
},
|
||||
{
|
||||
value: "biome",
|
||||
label: "Biome",
|
||||
hint: "Add Biome for linting and formatting",
|
||||
},
|
||||
{
|
||||
value: "husky",
|
||||
label: "Husky",
|
||||
hint: "Add Git hooks with Husky, lint-staged (requires Biome)",
|
||||
},
|
||||
],
|
||||
initialValues: DEFAULT_CONFIG.addons,
|
||||
options,
|
||||
initialValues,
|
||||
required: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -65,9 +65,9 @@ export async function gatherConfig(
|
||||
results.database === "sqlite" && results.orm !== "prisma"
|
||||
? getTursoSetupChoice(flags.turso)
|
||||
: Promise.resolve(false),
|
||||
addons: () => getAddonsChoice(flags.addons),
|
||||
addons: ({ results }) => getAddonsChoice(flags.addons, results.frontend),
|
||||
examples: ({ results }) =>
|
||||
getExamplesChoice(flags.examples, results.database),
|
||||
getExamplesChoice(flags.examples, results.database, results.frontend),
|
||||
git: () => getGitChoice(flags.git),
|
||||
packageManager: () => getPackageManagerChoice(flags.packageManager),
|
||||
noInstall: () => getNoInstallChoice(flags.noInstall),
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
import { cancel, isCancel, multiselect } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import { DEFAULT_CONFIG } from "../constants";
|
||||
import type { ProjectDatabase, ProjectExamples } from "../types";
|
||||
import type {
|
||||
ProjectDatabase,
|
||||
ProjectExamples,
|
||||
ProjectFrontend,
|
||||
} from "../types";
|
||||
|
||||
export async function getExamplesChoice(
|
||||
examples?: ProjectExamples[],
|
||||
database?: ProjectDatabase,
|
||||
frontends?: ProjectFrontend[],
|
||||
): Promise<ProjectExamples[]> {
|
||||
if (examples !== undefined) return examples;
|
||||
|
||||
if (database === "none") return [];
|
||||
|
||||
const hasWebFrontend = frontends?.includes("web");
|
||||
if (!hasWebFrontend) return [];
|
||||
|
||||
const response = await multiselect<ProjectExamples>({
|
||||
message: "Which examples would you like to include?",
|
||||
options: [
|
||||
|
||||
@@ -8,6 +8,12 @@ export function displayConfig(config: Partial<ProjectConfig>) {
|
||||
configDisplay.push(`${pc.blue("Project Name:")} ${config.projectName}`);
|
||||
}
|
||||
|
||||
if (config.frontend !== undefined) {
|
||||
const frontendText =
|
||||
config.frontend.length > 0 ? config.frontend.join(", ") : "none";
|
||||
configDisplay.push(`${pc.blue("Frontend:")} ${frontendText}`);
|
||||
}
|
||||
|
||||
if (config.backendFramework !== undefined) {
|
||||
configDisplay.push(
|
||||
`${pc.blue("Backend Framework:")} ${config.backendFramework}`,
|
||||
|
||||
Reference in New Issue
Block a user