Skip to content
This repository was archived by the owner on May 28, 2026. It is now read-only.

Commit 9e810f1

Browse files
authored
feat(cli): case options for filenames
2 parents 8a92981 + 81b92fe commit 9e810f1

8 files changed

Lines changed: 150 additions & 52 deletions

File tree

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rehooks-cli",
3-
"version": "4.6.0",
3+
"version": "4.6.1",
44
"description": "A CLI to scaffold your react custom hooks, with a focus on performance, reusability, and type-safety.",
55
"publishConfig": {
66
"access": "public"
@@ -53,7 +53,7 @@
5353
"tsup": "^8.3.0",
5454
"type-fest": "^4.26.1",
5555
"typescript": "^5.6.3",
56-
"zod": "^3.23.8"
56+
"zod": "^3.25.67"
5757
},
5858
"dependencies": {
5959
"axios": "^1.7.7",
@@ -64,4 +64,4 @@
6464
"package-json": "^10.0.1",
6565
"semver": "^7.6.3"
6666
}
67-
}
67+
}

packages/cli/src/commands/add.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { join } from "path";
1717
import type { Hook } from "~/schema/config.schema";
1818
import { getConfig } from "~/utils/config";
1919
import { BASE_URL } from "~/utils/constants";
20+
import { splitter } from "~/utils/splitter";
2021

2122
export const add = new Command()
2223
.name("add")
@@ -86,6 +87,7 @@ export const add = new Command()
8687
}
8788

8889
const { content } = selectedHookResponse.data;
90+
log.info("heyy");
8991
writeFileSync(hookFilePath, content);
9092
addedHooks.push(hook);
9193
} catch (error) {
@@ -138,7 +140,16 @@ export const add = new Command()
138140
const addSpinner = spinner();
139141

140142
for (const hook of selectedHookArray) {
141-
const hookFilePath = join(directory, `${hook}.ts`);
143+
let currentHook: string = hook;
144+
145+
if (config.case === "kebab") {
146+
const words = splitter(currentHook);
147+
currentHook = words.join("_");
148+
} else {
149+
currentHook = hook;
150+
}
151+
152+
const hookFilePath = join(directory, `${currentHook}.ts`);
142153

143154
if (existsSync(hookFilePath) && !shouldForceOverwrite) {
144155
// Stop the spinner before showing the prompt
@@ -185,8 +196,6 @@ export const add = new Command()
185196
}
186197
}
187198

188-
addSpinner.stop(green("Hooks added successfully!"));
189-
190199
if (addedHooks.length > 0) {
191200
outro(
192201
green(

packages/cli/src/commands/init.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
isCancel,
66
log,
77
outro,
8+
select,
89
text,
910
} from "@clack/prompts";
1011
import { bold, cyan, green, red, yellow } from "colorette";
@@ -19,6 +20,7 @@ import {
1920
} from "fs";
2021
import { resolve } from "path";
2122

23+
import type { RehooksConfig } from "~/schema/config.schema";
2224
import { checkReactVersion } from "~/utils/checker";
2325
import { getConfig, getTsConfig } from "~/utils/config";
2426
import { DIR_PLACEHOLDER, SRC_DIR_PLACEHOLDER } from "~/utils/constants";
@@ -145,7 +147,34 @@ export const init = new Command()
145147

146148
// Write rehooks.json file
147149
log.info(cyan("Creating rehooks.json configuration file..."));
148-
const defaultConfig = { directory, forceOverwrite: false };
150+
151+
const defaultConfig: RehooksConfig = {
152+
directory,
153+
forceOverwrite: false,
154+
case: "camel",
155+
};
156+
157+
const chooseCase = await select({
158+
message: "In what case do you want your hook file names to be written?",
159+
options: [
160+
{
161+
label: "camelCase",
162+
value: "camel",
163+
hint: "Camel",
164+
},
165+
{
166+
label: "kebab_case",
167+
value: "kebab",
168+
hint: "Kebab",
169+
},
170+
],
171+
});
172+
173+
if (chooseCase.toString() === "camel") {
174+
defaultConfig.case = "camel";
175+
} else {
176+
defaultConfig.case = "kebab";
177+
}
149178

150179
try {
151180
writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));

packages/cli/src/commands/list.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { bold, green, red } from "colorette";
44
import { Command } from "commander";
55

66
import type { Hook } from "~/schema/config.schema";
7-
import { getConfig } from "~/utils/config";
87
import { BASE_URL } from "~/utils/constants";
98
import { sleep } from "~/utils/sleep";
109
import { trancute } from "~/utils/trancute";
@@ -15,18 +14,6 @@ export const list = new Command()
1514
.action(async () => {
1615
intro("Listing hooks...");
1716

18-
// Check if project has rehooks.json
19-
const config = await getConfig(process.cwd());
20-
if (!config) {
21-
outro(red("Rehooks configuration not found or invalid."));
22-
return;
23-
}
24-
25-
if (isCancel(config)) {
26-
cancel(red("Operation Cancelled."));
27-
process.exit(0);
28-
}
29-
3017
try {
3118
const fetchSpinner = spinner();
3219
fetchSpinner.start("Fetching hooks...");

packages/cli/src/schema/config.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { z } from "zod";
1+
import { z } from "zod/v4";
22

33
const configSchema = z.object({
44
directory: z.string(),
55
forceOverwrite: z.boolean().default(false),
6+
case: z.literal(["kebab", "camel"]),
67
});
78

89
type RehooksConfig = z.infer<typeof configSchema>;

packages/cli/src/schema/tsconfig.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from "zod";
1+
import { z } from "zod/v4";
22

33
const tsConfigSchema = z.object({
44
compilerOptions: z

packages/cli/src/utils/splitter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function splitter(str: string): string[] {
2+
return str.split(/(?=[A-Z])/).map((word) => word.toLowerCase());
3+
}

0 commit comments

Comments
 (0)