Skip to content

Commit 5897e9c

Browse files
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.
1 parent f2db006 commit 5897e9c

File tree

9 files changed

+33
-27
lines changed

9 files changed

+33
-27
lines changed

.changeset/wide-books-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
several improvements

apps/cli/src/helpers/create-project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { $ } from "execa";
44
import fs from "fs-extra";
55
import pc from "picocolors";
66
import { PKG_ROOT } from "../constants";
7-
import type { ProjectConfig } from "../types";
7+
import type { ProjectConfig, ProjectDatabase, ProjectOrm } from "../types";
88
import { setupAddons } from "./addons-setup";
99
import { setupAuth } from "./auth-setup";
1010
import { createReadme } from "./create-readme";
@@ -142,7 +142,7 @@ export async function createProject(options: ProjectConfig): Promise<string> {
142142
}
143143
}
144144

145-
function getOrmTemplateDir(orm: string, database: string): string {
145+
function getOrmTemplateDir(orm: ProjectOrm, database: ProjectDatabase): string {
146146
if (orm === "drizzle") {
147147
return database === "sqlite"
148148
? "template/with-drizzle-sqlite"

apps/cli/src/helpers/create-readme.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import fs from "fs-extra";
3-
import type { ProjectConfig } from "../types";
3+
import type { ProjectConfig, ProjectDatabase, ProjectOrm } from "../types";
44

55
export async function createReadme(projectDir: string, options: ProjectConfig) {
66
const readmePath = path.join(projectDir, "README.md");
@@ -110,10 +110,10 @@ function generateFeaturesList(
110110
}
111111

112112
function generateDatabaseSetup(
113-
database: string,
113+
database: ProjectDatabase,
114114
auth: boolean,
115115
packageManagerRunCmd: string,
116-
orm: string,
116+
orm: ProjectOrm,
117117
): string {
118118
if (database === "none") {
119119
return "";
@@ -167,8 +167,8 @@ ${packageManagerRunCmd} db:push
167167

168168
function generateScriptsList(
169169
packageManagerRunCmd: string,
170-
database: string,
171-
orm: string,
170+
database: ProjectDatabase,
171+
orm: ProjectOrm,
172172
auth: boolean,
173173
): string {
174174
let scripts = `- \`${packageManagerRunCmd} dev\`: Start both client and server in development mode

apps/cli/src/helpers/post-installation.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { log } from "@clack/prompts";
22
import pc from "picocolors";
3+
import type { PackageManager, ProjectDatabase, ProjectOrm } from "../types";
34

45
export function displayPostInstallInstructions(
5-
database: string,
6+
database: ProjectDatabase,
67
projectName: string,
7-
packageManager: string,
8+
packageManager: PackageManager,
89
depsInstalled: boolean,
9-
orm?: string,
10+
orm?: ProjectOrm,
1011
) {
1112
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
1213
const cdCmd = `cd ${projectName}`;
@@ -25,8 +26,8 @@ ${database !== "none" ? getDatabaseInstructions(database, orm, runCmd) : ""}`);
2526
}
2627

2728
function getDatabaseInstructions(
28-
database: string,
29-
orm?: string,
29+
database: ProjectDatabase,
30+
orm?: ProjectOrm,
3031
runCmd?: string,
3132
): string {
3233
const instructions = [];
@@ -39,7 +40,7 @@ function getDatabaseInstructions(
3940
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
4041
);
4142

42-
if (database === "turso") {
43+
if (database === "sqlite") {
4344
instructions.push(
4445
`${pc.yellow("NOTE:")} Turso support with Prisma is in Early Access and requires additional setup.`,
4546
`${pc.dim("Learn more at: https://www.prisma.io/docs/orm/overview/databases/turso")}`,
@@ -52,12 +53,12 @@ function getDatabaseInstructions(
5253
instructions.push(
5354
`${pc.cyan("•")} Database UI: ${pc.dim(`${runCmd} db:studio`)}`,
5455
);
55-
}
5656

57-
if (database === "sqlite") {
58-
instructions.push(
59-
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
60-
);
57+
if (database === "sqlite") {
58+
instructions.push(
59+
`${pc.cyan("•")} Start local DB: ${pc.dim(`cd packages/server && ${runCmd} db:local`)}`,
60+
);
61+
}
6162
}
6263

6364
return instructions.length

apps/cli/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { gatherConfig } from "./prompts/config-prompts";
88
import type { ProjectAddons, ProjectConfig } from "./types";
99
import { displayConfig } from "./utils/display-config";
1010
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
11-
import { getVersion } from "./utils/get-version";
11+
import { getLatestCLIVersion } from "./utils/get-latest-cli-version";
1212
import { renderTitle } from "./utils/render-title";
1313

1414
process.on("SIGINT", () => {
@@ -22,7 +22,7 @@ async function main() {
2222
program
2323
.name("create-better-t-stack")
2424
.description("Create a new Better-T Stack project")
25-
.version(getVersion())
25+
.version(getLatestCLIVersion())
2626
.argument("[project-directory]", "Project name/directory")
2727
.option("-y, --yes", "Use default configuration")
2828
.option("--no-database", "Skip database setup")

apps/cli/src/utils/get-version.ts renamed to apps/cli/src/utils/get-latest-cli-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "node:path";
22
import fs from "fs-extra";
33
import { PKG_ROOT } from "../constants";
44

5-
export const getVersion = () => {
5+
export const getLatestCLIVersion = () => {
66
const packageJsonPath = path.join(PKG_ROOT, "package.json");
77

88
const packageJsonContent = fs.readJSONSync(packageJsonPath);

apps/cli/template/base/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"dev": "turbo dev",
99
"build": "turbo build",
1010
"check-types": "turbo check-types",
11-
"dev:client": "turbo -F @better-t/client dev",
12-
"dev:server": "turbo -F @better-t/server dev",
13-
"db:push": "turbo -F @better-t/server db:push",
14-
"db:studio": "turbo -F @better-t/server db:studio"
11+
"dev:client": "turbo -F client dev",
12+
"dev:server": "turbo -F server dev",
13+
"db:push": "turbo -F server db:push",
14+
"db:studio": "turbo -F server db:studio"
1515
},
1616
"packageManager": "bun@1.2.4",
1717
"devDependencies": {

apps/cli/template/base/packages/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@better-t/client",
2+
"name": "client",
33
"version": "0.0.0",
44
"private": true,
55
"type": "module",

apps/cli/template/base/packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@better-t/server",
2+
"name": "server",
33
"main": "src/index.ts",
44
"type": "module",
55
"scripts": {

0 commit comments

Comments
 (0)