mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Improve TypeScript types and package naming in CLI generator
Adds proper type annotations for database and ORM parameters, simplifies package names in templates, and renames version utility function for clarity.
This commit is contained in:
5
.changeset/wide-books-worry.md
Normal file
5
.changeset/wide-books-worry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
several improvements
|
||||
@@ -4,7 +4,7 @@ import { $ } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import pc from "picocolors";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import type { ProjectConfig, ProjectDatabase, ProjectOrm } from "../types";
|
||||
import { setupAddons } from "./addons-setup";
|
||||
import { setupAuth } from "./auth-setup";
|
||||
import { createReadme } from "./create-readme";
|
||||
@@ -142,7 +142,7 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
function getOrmTemplateDir(orm: string, database: string): string {
|
||||
function getOrmTemplateDir(orm: ProjectOrm, database: ProjectDatabase): string {
|
||||
if (orm === "drizzle") {
|
||||
return database === "sqlite"
|
||||
? "template/with-drizzle-sqlite"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import type { ProjectConfig, ProjectDatabase, ProjectOrm } from "../types";
|
||||
|
||||
export async function createReadme(projectDir: string, options: ProjectConfig) {
|
||||
const readmePath = path.join(projectDir, "README.md");
|
||||
@@ -110,10 +110,10 @@ function generateFeaturesList(
|
||||
}
|
||||
|
||||
function generateDatabaseSetup(
|
||||
database: string,
|
||||
database: ProjectDatabase,
|
||||
auth: boolean,
|
||||
packageManagerRunCmd: string,
|
||||
orm: string,
|
||||
orm: ProjectOrm,
|
||||
): string {
|
||||
if (database === "none") {
|
||||
return "";
|
||||
@@ -167,8 +167,8 @@ ${packageManagerRunCmd} db:push
|
||||
|
||||
function generateScriptsList(
|
||||
packageManagerRunCmd: string,
|
||||
database: string,
|
||||
orm: string,
|
||||
database: ProjectDatabase,
|
||||
orm: ProjectOrm,
|
||||
auth: boolean,
|
||||
): string {
|
||||
let scripts = `- \`${packageManagerRunCmd} dev\`: Start both client and server in development mode
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { log } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import type { PackageManager, ProjectDatabase, ProjectOrm } from "../types";
|
||||
|
||||
export function displayPostInstallInstructions(
|
||||
database: string,
|
||||
database: ProjectDatabase,
|
||||
projectName: string,
|
||||
packageManager: string,
|
||||
packageManager: PackageManager,
|
||||
depsInstalled: boolean,
|
||||
orm?: string,
|
||||
orm?: ProjectOrm,
|
||||
) {
|
||||
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
|
||||
const cdCmd = `cd ${projectName}`;
|
||||
@@ -25,8 +26,8 @@ ${database !== "none" ? getDatabaseInstructions(database, orm, runCmd) : ""}`);
|
||||
}
|
||||
|
||||
function getDatabaseInstructions(
|
||||
database: string,
|
||||
orm?: string,
|
||||
database: ProjectDatabase,
|
||||
orm?: ProjectOrm,
|
||||
runCmd?: string,
|
||||
): string {
|
||||
const instructions = [];
|
||||
@@ -39,7 +40,7 @@ function getDatabaseInstructions(
|
||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||
);
|
||||
|
||||
if (database === "turso") {
|
||||
if (database === "sqlite") {
|
||||
instructions.push(
|
||||
`${pc.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,
|
||||
`${pc.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`,
|
||||
@@ -52,12 +53,12 @@ function getDatabaseInstructions(
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (database === "sqlite") {
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
|
||||
);
|
||||
if (database === "sqlite") {
|
||||
instructions.push(
|
||||
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return instructions.length
|
||||
|
||||
@@ -8,7 +8,7 @@ import { gatherConfig } from "./prompts/config-prompts";
|
||||
import type { ProjectAddons, ProjectConfig } from "./types";
|
||||
import { displayConfig } from "./utils/display-config";
|
||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||
import { getVersion } from "./utils/get-version";
|
||||
import { getLatestCLIVersion } from "./utils/get-latest-cli-version";
|
||||
import { renderTitle } from "./utils/render-title";
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
@@ -22,7 +22,7 @@ async function main() {
|
||||
program
|
||||
.name("create-better-t-stack")
|
||||
.description("Create a new Better-T Stack project")
|
||||
.version(getVersion())
|
||||
.version(getLatestCLIVersion())
|
||||
.argument("[project-directory]", "Project name/directory")
|
||||
.option("-y, --yes", "Use default configuration")
|
||||
.option("--no-database", "Skip database setup")
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from "node:path";
|
||||
import fs from "fs-extra";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
|
||||
export const getVersion = () => {
|
||||
export const getLatestCLIVersion = () => {
|
||||
const packageJsonPath = path.join(PKG_ROOT, "package.json");
|
||||
|
||||
const packageJsonContent = fs.readJSONSync(packageJsonPath);
|
||||
@@ -8,10 +8,10 @@
|
||||
"dev": "turbo dev",
|
||||
"build": "turbo build",
|
||||
"check-types": "turbo check-types",
|
||||
"dev:client": "turbo -F @better-t/client dev",
|
||||
"dev:server": "turbo -F @better-t/server dev",
|
||||
"db:push": "turbo -F @better-t/server db:push",
|
||||
"db:studio": "turbo -F @better-t/server db:studio"
|
||||
"dev:client": "turbo -F client dev",
|
||||
"dev:server": "turbo -F server dev",
|
||||
"db:push": "turbo -F server db:push",
|
||||
"db:studio": "turbo -F server db:studio"
|
||||
},
|
||||
"packageManager": "bun@1.2.4",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@better-t/client",
|
||||
"name": "client",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@better-t/server",
|
||||
"name": "server",
|
||||
"main": "src/index.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user