Skip to content

Commit 8dd276a

Browse files
committed
feat: 파일명에 [한국어 키] 영어 패턴 지원
폴더명과 동일한 패턴으로 파일명도 지원: - [한국어 키] 영어 형식: [멘토 목록 조회] get-mentor-list.bru → get-mentor-list 추출 - 한글 설명은 가독성을 위해 사용, 실제 코드 생성에는 영문 부분만 사용 수정된 파일: - src/generator/queryKeyGenerator.ts: 파일명 추출 로직 추가 - src/generator/apiClientGenerator.ts: 파일명 추출 로직 추가 - docs/bruno-guide.md: 파일명 패턴 가이드라인 추가 - tests/cli.test.js: 파일명 패턴 테스트 추가 예시: - [목록 조회] get-list.bru → getList (쿼리 키), useGetList (훅) - [사용자 프로필] get-user-profile.bru → getUserProfile, useGetUserProfile 모든 테스트 통과 (새로운 파일명 패턴 테스트 포함)
1 parent 77a310a commit 8dd276a

5 files changed

Lines changed: 128 additions & 32 deletions

File tree

docs/bruno-guide.md

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,23 @@ docs {
153153
#### 지원하는 형식
154154

155155
1. **`[한글명] 숫자 영문키` 형식** (권장)
156+
156157
```
157158
[어드민] 7 Admin/ → 생성 폴더: 7 Admin
158159
[사용자] 8 Users/ → 생성 폴더: 8 Users
159160
[멘토] 9 Mentor/ → 생성 폴더: 9 Mentor
160161
```
162+
161163
- 대괄호 뒤의 모든 내용(숫자 + 영문키)이 폴더명이 됩니다
162164
- 한글명은 가독성을 위해 사용, 실제 폴더명에는 포함되지 않음
163165

164166
2. **`한글명 [EnglishKey]` 형식** (기존 방식, 호환)
167+
165168
```
166169
지원서 [applications]/ → 생성 폴더: applications
167170
사용자 [users]/ → 생성 폴더: users
168171
```
172+
169173
- 대괄호 안의 `EnglishKey`만 사용됩니다
170174
- 기존 프로젝트와 호환됩니다
171175

@@ -178,26 +182,49 @@ docs {
178182

179183
#### 폴더명 예시
180184

181-
| Bruno 폴더명 | 생성되는 폴더 | 설명 |
182-
|-------------|--------------|------|
183-
| `[어드민] 7 Admin` | `7 Admin` | 숫자와 공백 포함 가능 |
185+
| Bruno 폴더명 | 생성되는 폴더 | 설명 |
186+
| ----------------------- | -------------- | --------------------- |
187+
| `[어드민] 7 Admin` | `7 Admin` | 숫자와 공백 포함 가능 |
184188
| `지원서 [applications]` | `applications` | 대괄호 안의 키만 사용 |
185-
| `users` | `users` | 그대로 사용 |
189+
| `users` | `users` | 그대로 사용 |
186190

187191
### 파일명 규칙
188192

189193
**파일명이 쿼리 키와 훅 이름에 직접 사용됩니다!**
190194

195+
#### 지원하는 형식
196+
197+
1. **`[한국어 키] 영어` 형식** (권장, 폴더명과 동일한 패턴)
198+
199+
```
200+
[멘토 목록 조회] get-mentor-list.bru → get-mentor-list → getMentorList
201+
[사용자 프로필] get-user-profile.bru → get-user-profile → getUserProfile
202+
[지원서 생성] post-create-application.bru → post-create-application → postCreateApplication
203+
```
204+
205+
- 대괄호 뒤의 영문 부분만 사용됩니다
206+
- 한글 설명은 가독성을 위해 사용, 실제 코드 생성에는 포함되지 않음
207+
208+
2. **영문 파일명** (기존 방식, 호환)
209+
210+
```
211+
get-competitors.bru → get-competitors → getCompetitors
212+
get-user-profile.bru → get-user-profile → getUserProfile
213+
post-create-application.bru → post-create-application → postCreateApplication
214+
```
215+
216+
- 패턴이 없으면 파일명 그대로 사용
217+
191218
#### 권장 형식
192219

193220
**✅ 올바른 예시:**
194221

195222
```
196-
get-competitors.bru → QueryKeys.applications.getCompetitors
197-
get-user-profile.bru → QueryKeys.users.getUserProfile
198-
post-create-application.bru → QueryKeys.applications.postCreateApplication
199-
put-update-profile.bru → QueryKeys.users.putUpdateProfile
200-
delete-user.bru → QueryKeys.users.deleteUser
223+
[멘토 목록 조회] get-mentor-list.bru → QueryKeys.mentors.getMentorList
224+
[사용자 프로필] get-user-profile.bru → QueryKeys.users.getUserProfile
225+
[지원서 생성] post-create-application.bru → QueryKeys.applications.postCreateApplication
226+
[프로필 수정] put-update-profile.bru → QueryKeys.users.putUpdateProfile
227+
[사용자 삭제] delete-user.bru → QueryKeys.users.deleteUser
201228
```
202229

203230
#### 네이밍 규칙
@@ -225,38 +252,40 @@ delete-user.bru → QueryKeys.users.deleteUser
225252
-`멘토 목록 조회.bru` (쿼리 키 생성 시 문제 가능)
226253
-`get-mentor-list.bru` (영문 사용)
227254

228-
#### 변환 규칙
255+
#### 파일명 예시
229256

230-
파일명은 자동으로 camelCase로 변환됩니다:
257+
| Bruno 파일명 | 추출된 파일명 | 쿼리 키 이름 | 훅 이름 |
258+
| ------------------------------------- | ---------------------- | -------------------------- | ----------------------------- |
259+
| `[멘토 목록 조회] get-mentor-list.bru` | `get-mentor-list` | `getMentorList` | `useGetMentorList` |
260+
| `[사용자 프로필] get-user-profile.bru` | `get-user-profile` | `getUserProfile` | `useGetUserProfile` |
261+
| `[지원서 생성] post-create.bru` | `post-create` | `postCreate` | `usePostCreate` |
262+
| `get-competitors.bru` | `get-competitors` | `getCompetitors` | `useGetCompetitors` |
263+
| `멘토 목록 조회.bru` | `멘토 목록 조회` (비권장) | `멘토목록조회` (문제 가능) | `use멘토목록조회` (문제 가능) |
231264

232-
| 파일명 | 쿼리 키 이름 | 훅 이름 |
233-
| ----------------------------- | -------------------------- | ----------------------------- |
234-
| `get-competitors.bru` | `getCompetitors` | `useGetCompetitors` |
235-
| `get-user-profile.bru` | `getUserProfile` | `useGetUserProfile` |
236-
| `post-create-application.bru` | `postCreateApplication` | `usePostCreateApplication` |
237-
| `멘토 목록 조회.bru` | `멘토목록조회` (문제 가능) | `use멘토목록조회` (문제 가능) |
238-
239-
**핵심**: 파일명을 영문 kebab-case로 작성하면, 자동으로 일관된 쿼리 키와 훅 이름이 생성됩니다!
265+
**핵심**:
266+
- `[한국어 키] 영어` 형식으로 작성하면 한글 설명과 영문 코드를 모두 활용할 수 있습니다
267+
- 영문 부분만 kebab-case로 작성하면, 자동으로 일관된 쿼리 키와 훅 이름이 생성됩니다!
240268

241269
### 전체 구조 예시
242270

243271
```
244272
bruno/
245-
├── [어드민] 7 Admin/ # 폴더명: 7 Admin
246-
│ ├── get-list.bru # → QueryKeys["7 Admin"].getList
247-
│ ├── post-create.bru # → QueryKeys["7 Admin"].postCreate
248-
│ └── put-update.bru # → QueryKeys["7 Admin"].putUpdate
249-
├── 지원서 [applications]/ # 폴더명: applications
250-
│ ├── get-competitors.bru # → QueryKeys.applications.getCompetitors
251-
│ ├── get-details.bru # → QueryKeys.applications.getDetails
252-
│ └── post-create.bru # → QueryKeys.applications.postCreate
253-
├── 사용자 [users]/ # 폴더명: users
254-
│ ├── get-profile.bru # → QueryKeys.users.getProfile
255-
│ └── put-update-profile.bru # → QueryKeys.users.putUpdateProfile
273+
├── [어드민] 7 Admin/ # 폴더명: 7 Admin
274+
│ ├── [목록 조회] get-list.bru # → QueryKeys["7 Admin"].getList
275+
│ ├── [생성] post-create.bru # → QueryKeys["7 Admin"].postCreate
276+
│ └── [수정] put-update.bru # → QueryKeys["7 Admin"].putUpdate
277+
├── 지원서 [applications]/ # 폴더명: applications
278+
│ ├── [경쟁자 조회] get-competitors.bru # → QueryKeys.applications.getCompetitors
279+
│ ├── [상세 조회] get-details.bru # → QueryKeys.applications.getDetails
280+
│ └── [지원서 생성] post-create.bru # → QueryKeys.applications.postCreate
281+
├── 사용자 [users]/ # 폴더명: users
282+
│ ├── [프로필 조회] get-profile.bru # → QueryKeys.users.getProfile
283+
│ └── [프로필 수정] put-update-profile.bru # → QueryKeys.users.putUpdateProfile
256284
└── bruno.json
257285
```
258286

259287
**생성되는 구조:**
288+
260289
```
261290
src/apis/
262291
├── 7 Admin/

src/generator/apiClientGenerator.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ export function extractApiFunction(parsed: ParsedBrunoFile, filePath: string): A
2828
}
2929

3030
// .bru 파일명에서 함수명 생성
31-
const fileName = filePath.split('/').pop()?.replace('.bru', '') || '';
31+
let fileName = filePath.split('/').pop()?.replace('.bru', '') || '';
32+
33+
// [한국어 키] 영어 패턴 추출: [멘토 목록 조회] get-mentor-list → get-mentor-list
34+
const bracketPattern = /^\[[^\]]+\]\s+(.+)$/;
35+
const bracketMatch = fileName.match(bracketPattern);
36+
if (bracketMatch) {
37+
fileName = bracketMatch[1].trim(); // 대괄호 뒤의 영문 부분만 사용
38+
}
39+
3240
const functionName = toCamelCase(fileName);
3341
const responseType = functionNameToTypeName(functionName);
3442

src/generator/queryKeyGenerator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ export function generateQueryKeyStructure(
3535
domain = pathParts[brunoIndex + 1];
3636
}
3737

38-
const fileName = path.split('/').pop()?.replace('.bru', '') || '';
38+
let fileName = path.split('/').pop()?.replace('.bru', '') || '';
39+
40+
// [한국어 키] 영어 패턴 추출: [멘토 목록 조회] get-mentor-list → get-mentor-list
41+
const bracketPattern = /^\[[^\]]+\]\s+(.+)$/;
42+
const bracketMatch = fileName.match(bracketPattern);
43+
if (bracketMatch) {
44+
fileName = bracketMatch[1].trim(); // 대괄호 뒤의 영문 부분만 사용
45+
}
3946

4047
if (!structure[domain]) {
4148
structure[domain] = {};

tests/cli.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,33 @@ describe('새로운 폴더명 패턴 테스트', () => {
232232

233233
console.log('✅ [한글명] 숫자 영문키 패턴 테스트 통과');
234234
});
235+
236+
test('[한국어 키] 영어 파일명 패턴 추출', () => {
237+
const inputDir = join(FIXTURES_DIR, 'bruno');
238+
const outputDir = join(TEST_OUTPUT_DIR, 'apis-filename-pattern');
239+
240+
execSync(`node dist/cli/index.js generate-hooks -i ${inputDir} -o ${outputDir}`, {
241+
cwd: join(__dirname, '..'),
242+
});
243+
244+
// QueryKeys 파일 확인
245+
const queryKeysFile = join(outputDir, 'queryKeys.ts');
246+
const queryKeysContent = readFileSync(queryKeysFile, 'utf-8');
247+
248+
// [목록 조회] get-list.bru → getList로 추출되어야 함
249+
assert.ok(queryKeysContent.includes('getList'), 'getList 쿼리 키가 생성되어야 함');
250+
assert.ok(queryKeysContent.includes("'7 Admin.getList'"), '7 Admin.getList 쿼리 키가 생성되어야 함');
251+
252+
// 훅 파일 확인
253+
const hookFile = join(outputDir, '7 Admin', 'get-getList.ts');
254+
assert.ok(existsSync(hookFile), '[목록 조회] get-list.bru에서 getList 훅이 생성되어야 함');
255+
256+
const hookContent = readFileSync(hookFile, 'utf-8');
257+
assert.ok(hookContent.includes('getList'), '훅 내용에 getList가 포함되어야 함');
258+
assert.ok(hookContent.includes('useGetList'), 'useGetList 훅이 생성되어야 함');
259+
260+
console.log('✅ [한국어 키] 영어 파일명 패턴 테스트 통과');
261+
});
235262
});
236263

237264
describe('상태 코드별 응답 파싱 테스트', () => {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
meta {
2+
name: 목록 조회
3+
type: http
4+
seq: 1
5+
}
6+
7+
get /admin/list
8+
9+
headers {
10+
Authorization: Bearer {{token}}
11+
}
12+
13+
docs {
14+
```json
15+
{
16+
"items": [
17+
{
18+
"id": 1,
19+
"name": "Item 1"
20+
}
21+
],
22+
"total": 1
23+
}
24+
```
25+
}

0 commit comments

Comments
 (0)