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 fs from "fs-extra";
|
||||||
import pc from "picocolors";
|
import pc from "picocolors";
|
||||||
import { PKG_ROOT } from "../constants";
|
import { PKG_ROOT } from "../constants";
|
||||||
import type { ProjectConfig } from "../types";
|
import type { ProjectConfig, ProjectDatabase, ProjectOrm } from "../types";
|
||||||
import { setupAddons } from "./addons-setup";
|
import { setupAddons } from "./addons-setup";
|
||||||
import { setupAuth } from "./auth-setup";
|
import { setupAuth } from "./auth-setup";
|
||||||
import { createReadme } from "./create-readme";
|
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") {
|
if (orm === "drizzle") {
|
||||||
return database === "sqlite"
|
return database === "sqlite"
|
||||||
? "template/with-drizzle-sqlite"
|
? "template/with-drizzle-sqlite"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import fs from "fs-extra";
|
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) {
|
export async function createReadme(projectDir: string, options: ProjectConfig) {
|
||||||
const readmePath = path.join(projectDir, "README.md");
|
const readmePath = path.join(projectDir, "README.md");
|
||||||
@@ -110,10 +110,10 @@ function generateFeaturesList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateDatabaseSetup(
|
function generateDatabaseSetup(
|
||||||
database: string,
|
database: ProjectDatabase,
|
||||||
auth: boolean,
|
auth: boolean,
|
||||||
packageManagerRunCmd: string,
|
packageManagerRunCmd: string,
|
||||||
orm: string,
|
orm: ProjectOrm,
|
||||||
): string {
|
): string {
|
||||||
if (database === "none") {
|
if (database === "none") {
|
||||||
return "";
|
return "";
|
||||||
@@ -167,8 +167,8 @@ ${packageManagerRunCmd} db:push
|
|||||||
|
|
||||||
function generateScriptsList(
|
function generateScriptsList(
|
||||||
packageManagerRunCmd: string,
|
packageManagerRunCmd: string,
|
||||||
database: string,
|
database: ProjectDatabase,
|
||||||
orm: string,
|
orm: ProjectOrm,
|
||||||
auth: boolean,
|
auth: boolean,
|
||||||
): string {
|
): string {
|
||||||
let scripts = `- \`${packageManagerRunCmd} dev\`: Start both client and server in development mode
|
let scripts = `- \`${packageManagerRunCmd} dev\`: Start both client and server in development mode
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { log } from "@clack/prompts";
|
import { log } from "@clack/prompts";
|
||||||
import pc from "picocolors";
|
import pc from "picocolors";
|
||||||
|
import type { PackageManager, ProjectDatabase, ProjectOrm } from "../types";
|
||||||
|
|
||||||
export function displayPostInstallInstructions(
|
export function displayPostInstallInstructions(
|
||||||
database: string,
|
database: ProjectDatabase,
|
||||||
projectName: string,
|
projectName: string,
|
||||||
packageManager: string,
|
packageManager: PackageManager,
|
||||||
depsInstalled: boolean,
|
depsInstalled: boolean,
|
||||||
orm?: string,
|
orm?: ProjectOrm,
|
||||||
) {
|
) {
|
||||||
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
|
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
|
||||||
const cdCmd = `cd ${projectName}`;
|
const cdCmd = `cd ${projectName}`;
|
||||||
@@ -25,8 +26,8 @@ ${database !== "none" ? getDatabaseInstructions(database, orm, runCmd) : ""}`);
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDatabaseInstructions(
|
function getDatabaseInstructions(
|
||||||
database: string,
|
database: ProjectDatabase,
|
||||||
orm?: string,
|
orm?: ProjectOrm,
|
||||||
runCmd?: string,
|
runCmd?: string,
|
||||||
): string {
|
): string {
|
||||||
const instructions = [];
|
const instructions = [];
|
||||||
@@ -39,7 +40,7 @@ function getDatabaseInstructions(
|
|||||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (database === "turso") {
|
if (database === "sqlite") {
|
||||||
instructions.push(
|
instructions.push(
|
||||||
`${pc.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,
|
`${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")}`,
|
`${pc.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`,
|
||||||
@@ -52,13 +53,13 @@ function getDatabaseInstructions(
|
|||||||
instructions.push(
|
instructions.push(
|
||||||
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (database === "sqlite") {
|
if (database === "sqlite") {
|
||||||
instructions.push(
|
instructions.push(
|
||||||
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
|
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return instructions.length
|
return instructions.length
|
||||||
? `${pc.bold("Database commands:")}\n${instructions.join("\n")}\n\n`
|
? `${pc.bold("Database commands:")}\n${instructions.join("\n")}\n\n`
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { gatherConfig } from "./prompts/config-prompts";
|
|||||||
import type { ProjectAddons, ProjectConfig } from "./types";
|
import type { ProjectAddons, ProjectConfig } from "./types";
|
||||||
import { displayConfig } from "./utils/display-config";
|
import { displayConfig } from "./utils/display-config";
|
||||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
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";
|
import { renderTitle } from "./utils/render-title";
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
@@ -22,7 +22,7 @@ async function main() {
|
|||||||
program
|
program
|
||||||
.name("create-better-t-stack")
|
.name("create-better-t-stack")
|
||||||
.description("Create a new Better-T Stack project")
|
.description("Create a new Better-T Stack project")
|
||||||
.version(getVersion())
|
.version(getLatestCLIVersion())
|
||||||
.argument("[project-directory]", "Project name/directory")
|
.argument("[project-directory]", "Project name/directory")
|
||||||
.option("-y, --yes", "Use default configuration")
|
.option("-y, --yes", "Use default configuration")
|
||||||
.option("--no-database", "Skip database setup")
|
.option("--no-database", "Skip database setup")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import path from "node:path";
|
|||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { PKG_ROOT } from "../constants";
|
import { PKG_ROOT } from "../constants";
|
||||||
|
|
||||||
export const getVersion = () => {
|
export const getLatestCLIVersion = () => {
|
||||||
const packageJsonPath = path.join(PKG_ROOT, "package.json");
|
const packageJsonPath = path.join(PKG_ROOT, "package.json");
|
||||||
|
|
||||||
const packageJsonContent = fs.readJSONSync(packageJsonPath);
|
const packageJsonContent = fs.readJSONSync(packageJsonPath);
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
"dev": "turbo dev",
|
"dev": "turbo dev",
|
||||||
"build": "turbo build",
|
"build": "turbo build",
|
||||||
"check-types": "turbo check-types",
|
"check-types": "turbo check-types",
|
||||||
"dev:client": "turbo -F @better-t/client dev",
|
"dev:client": "turbo -F client dev",
|
||||||
"dev:server": "turbo -F @better-t/server dev",
|
"dev:server": "turbo -F server dev",
|
||||||
"db:push": "turbo -F @better-t/server db:push",
|
"db:push": "turbo -F server db:push",
|
||||||
"db:studio": "turbo -F @better-t/server db:studio"
|
"db:studio": "turbo -F server db:studio"
|
||||||
},
|
},
|
||||||
"packageManager": "bun@1.2.4",
|
"packageManager": "bun@1.2.4",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@better-t/client",
|
"name": "client",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@better-t/server",
|
"name": "server",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user