@uiwwsw/react-query-helper 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 uiwwsw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+
2
+ # React Query Helper
3
+
4
+ ![React Query Helper Logo](https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/logo.png) <!-- 로고 이미지가 있다면 여기에 추가하세요. 없으면 이 줄을 삭제하거나 주석 처리하세요. -->
5
+
6
+ ## 🚀 소개
7
+
8
+ `React Query Helper`는 기존 TypeScript API 파일에서 React Query 훅과 옵션 객체를 자동으로 생성해주는 강력한 CLI 도구입니다. 반복적인 React Query 설정 작업을 줄여 개발 생산성을 극대화하고, 일관된 코드 스타일을 유지할 수 있도록 돕습니다.
9
+
10
+ API 파일의 변경을 감지하여 실시간으로 관련 React Query 코드를 업데이트하거나, 한 번의 명령으로 전체 프로젝트의 코드를 생성할 수 있습니다.
11
+
12
+ ## ✨ 주요 기능
13
+
14
+ - **자동 코드 생성**: TypeScript API 파일에 정의된 함수를 기반으로 React Query 훅 (예: `useGetUserQuery`, `useCreateUserMutation`) 및 옵션 객체를 자동으로 생성합니다.
15
+ - **파일 변경 감지 (Watch Mode)**: `--watch` 모드를 통해 소스 API 파일의 변경 사항을 실시간으로 감지하고, 관련 React Query 코드를 즉시 업데이트합니다.
16
+ - **일괄 생성 (Generate Mode)**: `--generate` 모드를 사용하여 프로젝트 내 모든 API 파일에 대한 React Query 코드를 한 번에 생성합니다.
17
+ - **설정 파일 기반**: `rqh.config.ts` 파일을 통해 소스 디렉토리, 출력 디렉토리, 무시할 파일 등을 유연하게 설정할 수 있습니다.
18
+ - **Prettier 통합**: 생성된 코드는 자동으로 Prettier를 통해 포맷팅되어 일관된 코드 스타일을 유지합니다.
19
+
20
+ ## 📦 설치
21
+
22
+ `React Query Helper`는 [Bun](https://bun.sh/) 런타임을 사용하여 개발되었습니다. Bun이 설치되어 있지 않다면 먼저 설치해주세요.
23
+
24
+ ```bash
25
+ bun install
26
+ ```
27
+
28
+ ## 🛠️ 사용법
29
+
30
+ ### 1. 설정 파일 (`rqh.config.ts`) 생성
31
+
32
+ 프로젝트 루트에 `rqh.config.ts` 파일을 생성하고, **API 파일이 위치한 디렉토리(`sourceDir`)**와 **생성된 코드가 저장될 디렉토리(`outputDir`)**를 설정합니다. 이 경로는 프로젝트의 루트 디렉토리를 기준으로 합니다.
33
+
34
+ ```typescript
35
+ // rqh.config.ts
36
+ /** @type {import('./src/config').AutoQueryConfig} */
37
+ const config = {
38
+ sourceDir: "./libs", // API 함수가 정의된 TypeScript 파일들이 있는 디렉토리 (예: libs/users/api.ts)
39
+ outputDir: "./src/options", // React Query 훅 및 옵션 파일이 생성될 디렉토리
40
+ // ignoredFiles: ["some-ignored-file.ts"], // (선택 사항) 코드 생성에서 제외할 파일 이름들의 배열
41
+ };
42
+
43
+ export default config;
44
+ ```
45
+
46
+ ### 2. 코드 생성
47
+
48
+ #### 일괄 생성 모드 (`--generate`)
49
+
50
+ `rqh.config.ts`에 설정된 `sourceDir` 내의 모든 API 파일에 대해 React Query 코드를 한 번에 생성합니다. 주로 초기 설정 시 또는 전체 코드 재생성이 필요할 때 사용합니다.
51
+
52
+ ```bash
53
+ bun run src/cli.ts --generate
54
+ # 또는 package.json에 정의된 스크립트 사용
55
+ bun generate
56
+ ```
57
+
58
+ #### 변경 감지 모드 (`--watch`)
59
+
60
+ `rqh.config.ts`에 설정된 `sourceDir` 내의 API 파일 변경 사항을 실시간으로 감지하고, 해당 파일에 대한 React Query 코드를 자동으로 업데이트합니다. 개발 중 편리하게 사용할 수 있습니다.
61
+
62
+ ```bash
63
+ bun run src/cli.ts --watch
64
+ # 또는 package.json에 정의된 스크립트 사용
65
+ bun dev
66
+ ```
67
+
68
+ ### 3. 생성된 코드 사용 예시
69
+
70
+ `rqh.config.ts`에 설정된 `outputDir` (예: `./src/options`)에 다음과 같은 파일이 생성됩니다. **생성되는 파일의 경로는 `sourceDir`와 `outputDir` 설정에 따라 달라집니다.**
71
+
72
+ 예를 들어, `sourceDir`이 `./libs`이고 `outputDir`이 `./src/options`일 때, `libs/users/api.ts` 파일에 `getUser` 함수가 있다면:
73
+
74
+ ```typescript
75
+ // libs/users/api.ts
76
+ export const getUser = async (id: string) => {
77
+ return { id, name: `User ${id}` };
78
+ };
79
+
80
+ export const createUser = (name: string) => {
81
+ return { id: Date.now().toString(), name };
82
+ };
83
+
84
+ export function deleteUser(id: string) {
85
+ return { success: true, id };
86
+ }
87
+ ```
88
+
89
+ `src/options/users/apiOptions.ts`와 같은 파일이 `outputDir` 내에 생성될 수 있습니다. (정확한 파일명은 `analyzer.ts`와 `generator.ts`의 로직에 따라 달라질 수 있습니다.)
90
+
91
+ ```typescript
92
+ // src/options/users/apiOptions.ts (예시 - 경로는 rqh.config.ts 설정에 따라 달라짐)
93
+ import { getUser, createUser, deleteUser } from "../../../libs/users/api"; // API 파일 경로도 상대적으로 참조됩니다.
94
+ import { useQuery, useMutation } from "@tanstack/react-query";
95
+
96
+ // getUser에 대한 React Query 훅
97
+ export const useGetUserQuery = (id: string, options?: any) => {
98
+ return useQuery({
99
+ queryKey: ["users", id],
100
+ queryFn: () => getUser(id),
101
+ ...options,
102
+ });
103
+ };
104
+
105
+ // createUser에 대한 React Query 뮤테이션 훅
106
+ export const useCreateUserMutation = (options?: any) => {
107
+ return useMutation({
108
+ mutationFn: (name: string) => createUser(name),
109
+ ...options,
110
+ });
111
+ };
112
+
113
+ // deleteUser에 대한 React Query 뮤테이션 훅
114
+ export const useDeleteUserMutation = (options?: any) => {
115
+ return useMutation({
116
+ mutationFn: (id: string) => deleteUser(id),
117
+ ...options,
118
+ });
119
+ };
120
+ ```
121
+
122
+ 이제 애플리케이션에서 이 훅들을 가져와 사용할 수 있습니다. **가져오는 경로 또한 `rqh.config.ts`의 `outputDir` 설정에 따라 달라집니다.**
123
+
124
+ ```typescript
125
+ // YourComponent.tsx
126
+ import { useGetUserQuery, useCreateUserMutation } from "../options/users/apiOptions"; // 경로는 rqh.config.ts 설정에 따라 달라짐
127
+
128
+ function UserProfile({ userId }: { userId: string }) {
129
+ const { data: user, isLoading } = useGetUserQuery(userId);
130
+ const createUserMutation = useCreateUserMutation({
131
+ onSuccess: () => {
132
+ console.log("User created!");
133
+ },
134
+ });
135
+
136
+ if (isLoading) return <div>Loading...</div>;
137
+ if (!user) return <div>User not found.</div>;
138
+
139
+ return (
140
+ <div>
141
+ <h1>{user.name}</h1>
142
+ <button onClick={() => createUserMutation.mutate("New User")}>
143
+ Create New User
144
+ </button>
145
+ </div>
146
+ );
147
+ }
148
+ ```
149
+
150
+ ## ⚙️ 설정 (`rqh.config.ts`)
151
+
152
+ `rqh.config.ts` 파일에서 다음 `AutoQueryConfig` 인터페이스에 정의된 옵션들을 설정할 수 있습니다.
153
+
154
+ - `sourceDir`: (필수) API 함수가 정의된 TypeScript 파일들이 있는 디렉토리의 경로입니다. 이 디렉토리 내의 `.ts` 파일들을 분석하여 React Query 코드를 생성합니다. 프로젝트 루트를 기준으로 한 상대 경로를 사용합니다.
155
+ - `outputDir`: (필수) 생성된 React Query 훅 및 옵션 파일이 저장될 디렉토리의 경로입니다. 프로젝트 루트를 기준으로 한 상대 경로를 사용합니다.
156
+ - `ignoredFiles`: (선택 사항) 코드 생성 과정에서 무시할 파일 이름들의 배열입니다. (예: `["utils.ts", "types.ts"]`) 이 목록에 있는 파일은 `sourceDir` 내에 있더라도 코드가 생성되지 않습니다.
157
+ - `templateDir`: (선택 사항) 내부적으로 사용되는 템플릿 디렉토리입니다. 일반적으로 사용자가 직접 설정할 필요는 없습니다.
158
+
159
+ ## 🤝 기여
160
+
161
+ 버그 리포트, 기능 제안, 코드 기여 등 모든 형태의 기여를 환영합니다. 자세한 내용은 `CONTRIBUTING.md` 파일을 참조해주세요.
162
+
163
+ ## 📄 라이선스
164
+
165
+ 이 프로젝트는 [LICENSE](LICENSE) 파일에 명시된 라이선스에 따라 배포됩니다.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}