@codefast/cli 0.3.5-canary.0 → 0.3.7-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,125 +1,339 @@
1
- # Command `update-exports`
1
+ # @codefast/cli
2
2
 
3
- ## Tổng Quan
3
+ Command line interface tools for CodeFast development, built with explicit architecture principles.
4
4
 
5
- Command `update-exports` là một công cụ tự động hóa việc cập nhật cấu hình `exports` trong file `package.json` của các package trong dự án. Nó phân tích mã nguồn để xác định các module được export và tạo cấu trúc exports phù hợp.
5
+ ## Overview
6
6
 
7
- ## Cách Sử Dụng
7
+ The CodeFast CLI is a TypeScript-based command-line tool designed to analyze and validate CodeFast projects. It provides powerful analysis capabilities for TypeScript projects and React component type checking, following explicit architecture guidelines for maintainability, testability, and scalability.
8
8
 
9
- ```shell script
10
- codefast update-exports [options]
9
+ ## Features
10
+
11
+ - **TypeScript Project Analysis**: Analyze TypeScript codebases and generate detailed statistics
12
+ - **React Component Type Checking**: Validate React component type correspondence across packages
13
+ - **Explicit Architecture**: Clean, maintainable codebase following DDD and SOLID principles
14
+ - **Dependency Injection**: Fully testable with InversifyJS container
15
+ - **Rich CLI Experience**: Colorful output with chalk and comprehensive help system
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ # Install globally
21
+ npm install -g @codefast/cli
22
+
23
+ # Or use with npx
24
+ npx @codefast/cli --help
11
25
  ```
12
26
 
13
- ### Tùy Chọn
14
-
15
- | Tùy chọn | Mô tả |
16
- | ------------------------- | ------------------------------------------------ |
17
- | `-p, --package <package>` | Lọc theo tên package cụ thể |
18
- | `-d, --dry-run` | Chạy mà không thực hiện thay đổi (chỉ xem trước) |
19
- | `-v, --verbose` | Hiển thị đầu ra chi tiết |
20
- | `-c, --config <path>` | Đường dẫn đến file cấu hình tùy chỉnh |
21
-
22
- ## Luồng Hoạt Động
23
-
24
- ```mermaid
25
- flowchart TD
26
- A[Bắt đầu update-exports] --> B[processAllPackages]
27
- B --> C[Tìm kiếm packages với findAllPackages]
28
- C --> D[Lấy cấu hình với getConfig]
29
- D --> E[Tìm tất cả package.json với glob]
30
- E --> F{Đã tìm thấy packages?}
31
- F -- Không --> G[Hiển thị cảnh báo]
32
- G --> Z[Kết thúc]
33
- F -- Có --> H[Xử lý từng package]
34
- H --> I[processPackage cho từng package]
35
- I --> J[Đọc package.json]
36
- J --> K{Match với package filter?}
37
- K -- Không --> L[Bỏ qua package]
38
- K -- Có --> M[Phân tích imports với analyzeImports]
39
- M --> N[Lưu kết quả phân tích]
40
- N --> O[Tạo exports mới với generateExports]
41
- O --> P{Dry run mode?}
42
- P -- Có --> Q[Tạo preview exports]
43
- Q --> Z
44
- P -- Không --> R[Sao lưu package.json]
45
- R --> S[Cập nhật package.json với exports mới]
46
- S --> Z
27
+ ## Usage
28
+
29
+ ### Available Commands
30
+
31
+ #### Hello Command
32
+
33
+ ```bash
34
+ codefast hello [options]
35
+ codefast hello --name "Developer"
47
36
  ```
48
37
 
49
- 1. **Khởi tạo và Tìm Kiếm Package**
38
+ Simple greeting command for testing CLI functionality.
50
39
 
51
- - Command đọc các tùy chọn từ người dùng
52
- - Tìm kiếm tất cả các file `package.json` trong workspace theo mẫu glob được cấu hình
40
+ **Options:**
53
41
 
54
- 2. **Xử Lý Từng Package**
42
+ - `-n, --name <name>`: Name to greet (default: "World")
55
43
 
56
- - Kiểm tra xem package có khớp với filter hay không (nếu có)
57
- - Đọc cấu hình cụ thể cho package
58
- - Xác định đường dẫn đến file index
44
+ #### Analyze Command
59
45
 
60
- 3. **Phân Tích Imports**
46
+ ```bash
47
+ codefast analyze [options]
48
+ codefast analyze --pattern "src/**/*.ts" --config "./tsconfig.json"
49
+ ```
61
50
 
62
- - Sử dụng ts-morph để phân tích cú pháp của file index
63
- - Tìm tất cả các khai báo export
64
- - Chuẩn hóa đường dẫn (ví dụ: @/ thành ./)
65
- - Bỏ qua các import từ modules bên ngoài
66
- - Xử lý đường dẫn export theo cấu hình
51
+ Analyze TypeScript project and generate statistics about classes, functions, and interfaces.
67
52
 
68
- 4. **Tạo Exports Mới**
53
+ **Options:**
69
54
 
70
- - Dựa trên imports đã phân tích, tạo cấu trúc exports mới
71
- - So sánh với exports hiện tại
55
+ - `-p, --pattern <pattern>`: File pattern to analyze (default: "src/**/*.ts")
56
+ - `-c, --config <path>`: Path to tsconfig.json file
72
57
 
73
- 5. **Lưu Thay Đổi**
58
+ **Example Output:**
74
59
 
75
- - Nếu ở chế độ dry-run:
76
- - Tạo preview của exports mới mà không thực hiện thay đổi
77
- - Nếu không ở chế độ dry-run:
78
- - Tạo bản sao lưu của package.json
79
- - Cập nhật package.json với exports mới
60
+ ```text
61
+ 🔍 Analyzing TypeScript project...
62
+ ✅ Found 45 TypeScript files
63
+ ⚠️ Loaded 45 source files for analysis
64
+ 📊 Project Statistics:
65
+ Classes: 12
66
+ Functions: 89
67
+ Interfaces: 23
68
+ ```
80
69
 
81
- 6. **Báo Cáo Kết Quả**
70
+ #### Check Component Types Command
82
71
 
83
- - Hiển thị thống kê về số lượng package đã xử lý thành công, bỏ qua, thất bại
72
+ ```bash
73
+ codefast check-component-types [options]
74
+ codefast check-component-types --packages-dir "packages"
75
+ ```
84
76
 
85
- ## Cấu Hình
77
+ Check React component type correspondence across packages in a monorepo.
86
78
 
87
- Command `update-exports` sử dụng file cấu hình để xác định:
79
+ **Options:**
88
80
 
89
- - Mẫu glob để tìm packages
90
- - Các prefix đường dẫn cần loại bỏ
91
- - Cấu hình cụ thể cho từng package
81
+ - `-d, --packages-dir <dir>`: Packages directory to analyze (default: "packages")
92
82
 
93
- Bạn có thể chỉ định file cấu hình tùy chỉnh bằng tùy chọn `-c, --config`.
83
+ ## Architecture
94
84
 
95
- ## Ví Dụ
85
+ This CLI follows **Explicit Architecture** principles, ensuring clear separation of concerns, testability, and maintainability.
96
86
 
97
- Cập nhật exports cho tất cả các package:
87
+ ### Directory Structure
98
88
 
99
- ```shell script
100
- codefast update-exports
89
+ ```text
90
+ src/
91
+ ├── core/ # Core business logic
92
+ │ └── application/ # Application layer
93
+ │ ├── ports/ # Interface definitions
94
+ │ │ ├── analysis/ # Analysis service interfaces
95
+ │ │ ├── services/ # Service interfaces
96
+ │ │ └── system/ # System service interfaces
97
+ │ └── use-cases/ # Business workflows
98
+ ├── infrastructure/ # Technical implementations
99
+ │ └── adapters/ # Port implementations
100
+ │ ├── analysis/ # Analysis service adapters
101
+ │ ├── services/ # Service adapters
102
+ │ └── system/ # System service adapters
103
+ ├── commands/ # CLI command handling
104
+ ├── di/ # Dependency injection
105
+ │ └── modules/ # DI module configurations
106
+ └── index.ts # CLI entry point
101
107
  ```
102
108
 
103
- Chạy ở chế độ verbose để xem thông tin chi tiết:
109
+ ### Architectural Layers
110
+
111
+ #### 1. Core/Application Layer
112
+
113
+ Contains business logic and defines interfaces (ports) for external dependencies.
114
+
115
+ **Use Cases:**
116
+
117
+ - `AnalyzeProjectUseCase`: Orchestrates TypeScript project analysis
118
+ - `CheckComponentTypesUseCase`: Handles React component type validation
119
+ - `GreetUserUseCase`: Simple greeting functionality
120
+
121
+ **Ports (Interfaces):**
122
+
123
+ - **Analysis Ports**: `TypeScriptAnalysisPort`, `ComponentAnalysisPort`
124
+ - **Service Ports**: `LoggingServicePort`
125
+ - **System Ports**: `FileSystemSystemPort`, `PathSystemPort`, `UrlSystemPort`
126
+
127
+ #### 2. Infrastructure Layer
128
+
129
+ Implements the ports using concrete technologies and external libraries.
130
+
131
+ **Adapters:**
132
+
133
+ - `TsMorphTypescriptAnalysisAdapter`: TypeScript analysis using ts-morph
134
+ - `ReactComponentAnalysisAdapter`: React component analysis
135
+ - `ChalkLoggingServiceAdapter`: Colored console logging with chalk
136
+ - `FastGlobFileSystemSystemAdapter`: File system operations with fast-glob
137
+ - `NodePathSystemAdapter`: Path operations using Node.js path module
138
+ - `NodeUrlSystemAdapter`: URL operations using Node.js url module
139
+
140
+ #### 3. Commands Layer
141
+
142
+ Handles CLI interface using the Commander.js framework.
143
+
144
+ - `CommandHandler`: Main command orchestrator with dependency injection
145
+
146
+ #### 4. Dependency Injection Layer
147
+
148
+ Manages dependencies using InversifyJS container.
149
+
150
+ **Modules:**
151
+
152
+ - `infrastructureModule`: Binds infrastructure adapters
153
+ - `applicationModule`: Binds use cases and application services
154
+ - `commandsModule`: Binds command handlers
155
+
156
+ ### Key Design Principles
157
+
158
+ 1. **Dependency Inversion**: All dependencies flow inward toward the core business logic
159
+ 2. **Interface Segregation**: Small, focused interfaces for each concern
160
+ 3. **Single Responsibility**: Each class has one reason to change
161
+ 4. **Testability**: All dependencies are injected and can be mocked
162
+ 5. **Explicit Dependencies**: No hidden dependencies or global state
163
+
164
+ ## Development
165
+
166
+ ### Prerequisites
167
+
168
+ - Node.js 20.0.0+
169
+ - pnpm 10.13.1+
170
+
171
+ ### Setup
104
172
 
105
- ```shell script
106
- codefast update-exports --verbose
173
+ ```bash
174
+ # Install dependencies
175
+ pnpm install
176
+
177
+ # Build the package
178
+ pnpm build
179
+
180
+ # Run in development mode
181
+ pnpm dev
182
+ ```
183
+
184
+ ### Available Scripts
185
+
186
+ ```bash
187
+ # Development
188
+ pnpm dev # Build and watch for changes
189
+ pnpm build # Build for production
190
+ pnpm clean # Clean build artifacts
191
+
192
+ # Code Quality
193
+ pnpm lint # Run ESLint
194
+ pnpm lint:fix # Fix ESLint issues
195
+ pnpm type-check # TypeScript type checking
196
+ pnpm format # Format code with Prettier
197
+ pnpm format:check # Check code formatting
198
+
199
+ # Testing
200
+ pnpm test # Run tests
201
+ pnpm test:watch # Run tests in watch mode
202
+ pnpm test:coverage # Run tests with coverage
203
+ pnpm test:coverage:ci # Run tests with CI coverage
204
+ ```
205
+
206
+ ### Testing Strategy
207
+
208
+ The CLI follows a comprehensive testing approach aligned with the explicit architecture:
209
+
210
+ #### Unit Testing
211
+
212
+ - **Domain/Application Layer**: Test use cases with mocked ports
213
+ - **Infrastructure Layer**: Test adapters with real or mocked external dependencies
214
+ - **Commands Layer**: Test command handlers with mocked use cases
215
+
216
+ #### Test Structure
217
+
218
+ ```text
219
+ src/
220
+ ├── core/application/use-cases/
221
+ │ ├── analyze-project.use-case.ts
222
+ │ └── analyze-project.use-case.test.ts
223
+ ├── infrastructure/adapters/
224
+ │ ├── ts-morph.typescript.analysis.adapter.ts
225
+ │ └── ts-morph.typescript.analysis.adapter.test.ts
226
+ └── commands/
227
+ ├── command-handler.ts
228
+ └── command-handler.test.ts
229
+ ```
230
+
231
+ #### Testing Best Practices
232
+
233
+ - Mock at the port boundaries (interfaces)
234
+ - Use dependency injection for test isolation
235
+ - Test business logic independently of technical details
236
+ - Maintain high coverage for critical paths
237
+
238
+ ### Adding New Features
239
+
240
+ #### 1. Define the Port (Interface)
241
+
242
+ ```typescript
243
+ // src/core/application/ports/new-feature.port.ts
244
+ export interface NewFeaturePort {
245
+ performAction(input: string): Promise<string>;
246
+ }
247
+ ```
248
+
249
+ #### 2. Create the Use Case
250
+
251
+ ```typescript
252
+ // src/core/application/use-cases/new-feature.use-case.ts
253
+ @injectable()
254
+ export class NewFeatureUseCase {
255
+ constructor(
256
+ @inject(TYPES.NewFeaturePort)
257
+ private readonly newFeatureService: NewFeaturePort,
258
+ ) {}
259
+
260
+ async execute(input: string): Promise<void> {
261
+ const result = await this.newFeatureService.performAction(input);
262
+ // Handle result...
263
+ }
264
+ }
265
+ ```
266
+
267
+ #### 3. Implement the Adapter
268
+
269
+ ```typescript
270
+ // src/infrastructure/adapters/new-feature.adapter.ts
271
+ @injectable()
272
+ export class NewFeatureAdapter implements NewFeaturePort {
273
+ async performAction(input: string): Promise<string> {
274
+ // Implementation using external library
275
+ return `Processed: ${ input }`;
276
+ }
277
+ }
107
278
  ```
108
279
 
109
- Chỉ xử lý một package cụ thể:
280
+ #### 4. Configure Dependency Injection
281
+
282
+ ```typescript
283
+ // src/di/types.ts
284
+ export const TYPES = {
285
+ // ... existing types
286
+ NewFeaturePort: Symbol.for('NewFeaturePort'),
287
+ NewFeatureUseCase: Symbol.for('NewFeatureUseCase'),
288
+ };
110
289
 
111
- ```shell script
112
- codefast update-exports --package @codefast/ui
290
+ // src/di/modules/infrastructure.module.ts
291
+ infrastructureModule.bind<NewFeaturePort>(TYPES.NewFeaturePort).to(NewFeatureAdapter);
292
+
293
+ // src/di/modules/application.module.ts
294
+ applicationModule.bind<NewFeatureUseCase>(TYPES.NewFeatureUseCase).to(NewFeatureUseCase);
113
295
  ```
114
296
 
115
- Xem trước thay đổi mà không thực sự cập nhật:
297
+ #### 5. Add CLI Command
116
298
 
117
- ```shell script
118
- codefast update-exports --dry-run
299
+ ```typescript
300
+ // src/commands/command-handler.ts
301
+ this.program.command('new-feature').description('Description of new feature').action(async (options) => {
302
+ await this.newFeatureUseCase.execute(options.input);
303
+ });
119
304
  ```
120
305
 
121
- ## Lưu Ý
306
+ ## Dependencies
307
+
308
+ ### Core Dependencies
309
+
310
+ - **chalk**: Terminal styling and colors
311
+ - **commander**: CLI framework and argument parsing
312
+ - **fast-glob**: Fast file globbing for file system operations
313
+ - **inversify**: Dependency injection container
314
+ - **reflect-metadata**: Metadata reflection for decorators
315
+ - **ts-morph**: TypeScript compiler API wrapper
316
+ - **zod**: Schema validation and type safety
317
+
318
+ ### Development Dependencies
319
+
320
+ - **@rslib/core**: Modern build tool for libraries
321
+ - **TypeScript**: Type checking and compilation
322
+ - **Jest**: Testing framework
323
+ - **ESLint**: Code linting
324
+ - **Prettier**: Code formatting
325
+
326
+ ## Contributing
327
+
328
+ 1. Follow the explicit architecture guidelines
329
+ 2. Write tests for new features
330
+ 3. Ensure all quality checks pass (`pnpm lint`, `pnpm type-check`, `pnpm test`)
331
+ 4. Update documentation for new commands or features
332
+
333
+ ## License
334
+
335
+ MIT License - see LICENSE file for details.
336
+
337
+ ## Related
122
338
 
123
- - Command sẽ tạo bản sao lưu của các file package.json trước khi thực hiện thay đổi
124
- - Các exports được tạo dựa trên việc phân tích mã nguồn, đảm bảo tính nhất quán
125
- - Sử dụng tùy chọn `--dry-run` để kiểm tra các thay đổi trước khi áp dụng
339
+ - [CodeFast UI Components](../ui/README.md)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_exports__={};function main(){console.log("Hello, world!")}for(var __webpack_i__ in main(),__webpack_exports__)exports[__webpack_i__]=__webpack_exports__[__webpack_i__];Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ console.log("Hello, world!");
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@codefast/cli",
3
- "version": "0.3.5-canary.0",
4
- "description": "CodeFast CLI - A development toolkit for CodeFast.",
3
+ "version": "0.3.7-canary.0",
4
+ "description": "Command line interface tools for CodeFast development",
5
+ "keywords": [
6
+ "cli",
7
+ "command-line",
8
+ "tools",
9
+ "typescript",
10
+ "monorepo",
11
+ "development"
12
+ ],
13
+ "homepage": "https://github.com/codefastlabs/codefast/tree/main/packages/cli#readme",
5
14
  "bugs": {
6
15
  "url": "https://github.com/codefastlabs/codefast/issues"
7
16
  },
@@ -12,9 +21,25 @@
12
21
  },
13
22
  "license": "MIT",
14
23
  "author": "Vuong Phan <mr.thevuong@gmail.com>",
24
+ "sideEffects": false,
15
25
  "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "import": {
29
+ "default": "./dist/esm/index.js",
30
+ "types": "./dist/esm/index.d.ts"
31
+ },
32
+ "require": {
33
+ "default": "./dist/cjs/index.cjs",
34
+ "types": "./dist/cjs/index.d.cts"
35
+ }
36
+ }
37
+ },
38
+ "main": "./dist/cjs/index.cjs",
39
+ "module": "./dist/esm/index.js",
40
+ "types": "./dist/esm/index.d.ts",
16
41
  "bin": {
17
- "codefast": "dist/index.js"
42
+ "codefast": "./dist/esm/index.js"
18
43
  },
19
44
  "files": [
20
45
  "dist",
@@ -23,36 +48,41 @@
23
48
  "LICENSE"
24
49
  ],
25
50
  "dependencies": {
26
- "chalk": "^5.4.1",
51
+ "chalk": "^5.3.0",
27
52
  "commander": "^14.0.0",
28
- "glob": "^11.0.3",
29
- "inversify": "^7.5.2",
30
- "lodash-es": "^4.17.21",
53
+ "fast-glob": "^3.3.2",
54
+ "inversify": "^7.6.1",
31
55
  "reflect-metadata": "^0.2.2",
32
56
  "ts-morph": "^26.0.0",
33
- "zod": "4.0.0-beta.20250414T061543"
57
+ "zod": "^4.0.10"
34
58
  },
35
59
  "devDependencies": {
36
- "@rslib/core": "^0.9.2",
37
- "@types/commander": "^2.12.5",
38
- "@types/lodash-es": "^4.17.12",
39
- "@types/node": "^24.0.1",
40
- "eslint": "^9.29.0",
60
+ "@rslib/core": "^0.11.0",
61
+ "@swc/core": "^1.13.2",
62
+ "@swc/jest": "^0.2.39",
63
+ "@types/jest": "^30.0.0",
64
+ "@types/node": "^24.1.0",
65
+ "eslint": "^9.32.0",
66
+ "jest": "^30.0.5",
67
+ "jiti": "^2.5.1",
41
68
  "ts-node": "^10.9.2",
42
69
  "typescript": "^5.8.3",
43
- "@codefast/eslint-config": "0.3.5-canary.0",
44
- "@codefast/typescript-config": "0.3.5-canary.0"
70
+ "@codefast/eslint-config": "0.3.7-canary.0",
71
+ "@codefast/typescript-config": "0.3.7-canary.0"
45
72
  },
46
73
  "publishConfig": {
47
74
  "access": "public"
48
75
  },
49
- "preferUnplugged": true,
50
76
  "scripts": {
51
77
  "build": "rslib build",
52
- "check-types": "tsc --noEmit",
53
- "clean": "rimraf dist",
54
- "dev": "cross-env NODE_ENV=development rslib build --watch",
55
- "lint": "eslint --cache --max-warnings 0",
56
- "lint:inspect": "npx @eslint/config-inspector@latest"
78
+ "clean": "rm -rf dist",
79
+ "dev": "rslib build --watch",
80
+ "lint": "TIMING=1 eslint --max-warnings 0 .",
81
+ "lint:fix": "TIMING=1 eslint --max-warnings 0 --fix .",
82
+ "test": "jest",
83
+ "test:coverage": "jest --coverage",
84
+ "test:coverage:ci": "jest --coverage --ci",
85
+ "test:watch": "jest --watch",
86
+ "type-check": "tsc --noEmit"
57
87
  }
58
88
  }