Skip to content

Commit bc6d38e

Browse files
committed
refactor: simplify command parameters and improve configuration handling in project and export commands
1 parent 5ea0cf3 commit bc6d38e

File tree

16 files changed

+75
-76
lines changed

16 files changed

+75
-76
lines changed

.changeset/free-wombats-train.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@codefast-ui/progress-circle": patch
3+
"@codefast-ui/checkbox-group": patch
4+
"@codefast-ui/input-number": patch
5+
"@codefast/typescript-config": patch
6+
"@codefast-ui/input": patch
7+
"@codefast/eslint-config": patch
8+
"@codefast/style-guide": patch
9+
"@codefast/hooks": patch
10+
"@codefast/cli": patch
11+
"@codefast/ui": patch
12+
---
13+
14+
refactor: simplify command parameters and improve configuration handling in project and export commands

commitlint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const config = {
22
extends: ["@commitlint/config-conventional"],
33
rules: {
44
"body-max-line-length": [2, "always", 350],
5+
"header-max-length": [2, "always", 150],
56
},
67
};
78

packages/cli/src/application/commands/create-project.command.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { inject, injectable } from "inversify";
33
import process from "node:process";
44

55
import type { CreateProjectUseCase } from "@/application/use-cases/create-project.use-case";
6-
import type { ConfigGroups } from "@/domain/entities/config-file";
76

87
import { TYPES } from "@/ioc/types";
98

@@ -13,16 +12,16 @@ export class CreateProjectCommand {
1312

1413
/**
1514
* Returns a Commander.js command for creating or configuring a project.
16-
* @param configGroups - Configuration groups for project files.
15+
*
1716
* @returns Configured Commander.js command.
1817
*/
19-
getCommand(configGroups: ConfigGroups): Command {
18+
getCommand(): Command {
2019
return new Command()
2120
.name("create-project")
2221
.description("Create a new Next.js project with TypeScript, TailwindCSS, and linting setup")
2322
.argument("[project-name]", "Name of the project to create")
2423
.action(async (projectName: string) => {
25-
await this.createProjectUseCase.execute(projectName, configGroups);
24+
await this.createProjectUseCase.execute(projectName);
2625

2726
process.exit(0);
2827
});

packages/cli/src/application/use-cases/create-project.use-case.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Project } from "@/domain/entities/project";
88
import type { ProjectRepositoryInterface } from "@/domain/interfaces/project.repository";
99

1010
import { handleError } from "@/application/utilities/error-handler";
11+
import { ConfigService } from "@/infrastructure/services/config.service";
1112
import { TYPES } from "@/ioc/types";
1213

1314
@injectable()
@@ -17,18 +18,20 @@ export class CreateProjectUseCase {
1718
@inject(TYPES.FileSystemPort) private fileSystemPort: FileSystemPort,
1819
@inject(TYPES.CommandExecutorPort) private commandExecutorPort: CommandExecutorPort,
1920
@inject(TYPES.PromptPort) private promptPort: PromptPort,
21+
@inject(TYPES.ConfigService) private configService: ConfigService,
2022
) {}
2123

2224
/**
2325
* Executes the project creation or configuration process.
24-
* @param projectNameArg - Optional project name provided via CLI.
25-
* @param configGroups - Configuration groups for project files.
26+
* @param projectName - Optional project name provided via CLI.
27+
*
2628
* @returns The created or configured project.
2729
*/
28-
async execute(projectNameArg?: string, configGroups: ConfigGroups = {}): Promise<Project> {
30+
async execute(projectName?: string): Promise<Project> {
2931
try {
3032
this.commandExecutorPort.checkEnvironment();
31-
const project = await this.checkExistingProject(projectNameArg);
33+
const project = await this.checkExistingProject(projectName);
34+
const configGroups = this.configService.getConfigGroups();
3235

3336
this.createOrConfigureProject(project, configGroups);
3437
this.displaySuccessMessage(project);

packages/cli/src/application/use-cases/update-exports.use-case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class UpdateExportsUseCase {
2121
): Promise<void> {
2222
try {
2323
console.info("Searching for packages...");
24-
const packageJsonPaths = await this.packageRepository.findAllPackages(config.defaultPackageConfig);
24+
const packageJsonPaths = await this.packageRepository.findAllPackages(config);
2525

2626
if (packageJsonPaths.length === 0) {
2727
console.warn("No packages found.");
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { z } from "zod";
22

3-
export const ConfigFileSchema = z.object({
3+
export const configFileSchema = z.object({
44
path: z.string().describe("Relative path to the configuration file"),
55
content: z.string().describe("Content of the configuration file"),
66
description: z.string().optional().describe("Description of the configuration file's purpose"),
77
});
88

9-
export const ConfigCategorySchema = z.array(ConfigFileSchema).describe("Array of configuration files for a category");
9+
export const ConfigCategorySchema = z.array(configFileSchema).describe("Array of configuration files for a category");
1010

1111
export const ConfigGroupsSchema = z
1212
.record(z.string(), ConfigCategorySchema)
1313
.describe("Configuration groups by category");
1414

15-
export type ConfigFile = z.infer<typeof ConfigFileSchema>;
16-
1715
export type ConfigGroups = z.infer<typeof ConfigGroupsSchema>;

packages/cli/src/domain/entities/package-config.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,23 @@ export const exportConfigSchema = z.object({
4545

4646
export const PackageExportsSchema = z.record(z.string(), z.union([exportConfigSchema, z.string()]));
4747

48-
export const packageJsonSchema = z.object({
49-
dependencies: z
50-
.record(z.string(), z.string())
51-
.optional()
52-
.describe("List of runtime dependencies with their versions"),
53-
devDependencies: z
54-
.record(z.string(), z.string())
55-
.optional()
56-
.describe("List of development dependencies with their versions"),
57-
exports: PackageExportsSchema.optional().describe("Export mappings for the package"),
58-
name: z.string().describe("Name of the package"),
59-
scripts: z.record(z.string(), z.string()).describe("Script commands defined for the package"),
60-
"simple-git-hooks": z.record(z.string(), z.string()).optional().describe("Git hooks configuration for the package"),
61-
version: z.string().optional().describe("Version of the package"),
62-
});
48+
export const packageJsonSchema = z
49+
.object({
50+
dependencies: z
51+
.record(z.string(), z.string())
52+
.optional()
53+
.describe("List of runtime dependencies with their versions"),
54+
devDependencies: z
55+
.record(z.string(), z.string())
56+
.optional()
57+
.describe("List of development dependencies with their versions"),
58+
exports: PackageExportsSchema.optional().describe("Export mappings for the package"),
59+
name: z.string().describe("Name of the package"),
60+
scripts: z.record(z.string(), z.string()).describe("Script commands defined for the package"),
61+
"simple-git-hooks": z.record(z.string(), z.string()).optional().describe("Git hooks configuration for the package"),
62+
version: z.string().optional().describe("Version of the package"),
63+
})
64+
.catchall(z.unknown());
6365

6466
export type PackageConfig = z.infer<typeof packageConfigSchema>;
6567

packages/cli/src/domain/entities/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from "zod";
44
* Schema for validating project configuration.
55
* Ensures the project name is URL-friendly, not reserved, and the directory is valid.
66
*/
7-
export const ProjectSchema = z.object({
7+
export const projectSchema = z.object({
88
name: z
99
.string()
1010
.min(1, "Project name cannot be empty")
@@ -23,4 +23,4 @@ export const ProjectSchema = z.object({
2323
packageJsonExists: z.boolean().describe("Whether package.json exists in the project directory"),
2424
});
2525

26-
export type Project = z.infer<typeof ProjectSchema>;
26+
export type Project = z.infer<typeof projectSchema>;
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { ConfigGroups } from "@/domain/entities/config-file";
2-
import type { ScriptConfig } from "@/domain/entities/package-config";
32

43
/**
54
* Interface for accessing CLI configuration, including config groups for a create-project
65
* and script configuration for update-exports.
76
*/
87
export interface ConfigServiceInterface {
98
getConfigGroups: () => ConfigGroups;
10-
getScriptConfig: () => ScriptConfig;
119
}

packages/cli/src/domain/interfaces/package.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { AnalysisResult, PackageConfig, PackageExports, ScriptConfig } from
55
*/
66
export interface PackageRepository {
77
analyzeImports: (indexFilePath: string, packageConfig: PackageConfig) => AnalysisResult;
8-
findAllPackages: (config: PackageConfig) => Promise<string[]>;
8+
findAllPackages: (configPath?: string) => Promise<string[]>;
99
generateExports: (
1010
packageName: string,
1111
imports: AnalysisResult["imports"],

0 commit comments

Comments
 (0)