cob add#
기존 feature에 부품을 1개씩 추가합니다. cob compose가 feature 전체를 one-shot으로 합성하는 명령이라면,
cob add는 이미 생성된 feature 위에 부품을 얹는 append-only 멱등 증분 명령입니다. 기존 파일은 절대 덮어쓰지 않으며(skip-if-exists), 같은 명령을 반복 실행해도 중복 파일이나 중복 export가 생기지 않습니다.
지원 부품#
| 부품 | 사용 브릭 | 배치 위치 | barrel |
|---|---|---|---|
usecase |
usecase |
lib/src/domain/usecase/ (테스트: test/src/domain/usecase/) |
usecase.dart |
bloc |
bloc |
lib/src/presentation/bloc/blocs/<name>/ |
bloc.dart |
widget |
widget |
lib/src/presentation/widget/ (테스트: test/src/presentation/widget/) |
widget.dart (+ presentation.dart에 widget barrel export 보장) |
endpoint |
b-endpoint |
backend/*_server/lib/src/feature/<feature>/
(통합 테스트: server 루트
test/
)
|
barrel 없음 — serverpod generate가 endpoints.dart 등록 수행 |
사용법#
cob add <usecase|bloc|widget|endpoint> <name> --feature <feature>
위치 인자는 정확히 2개(<part> <name>)이며, <name>은 snake_case(^[a-z][a-z0-9_]*$)여야 합니다.
옵션#
| 옵션 | 축약 | 설명 | 기본값 |
|---|---|---|---|
--feature |
-f |
대상 feature 이름 (snake_case) | 필수 |
--target |
- | 프론트엔드 대상 앱 (application, console) |
application |
--usecases |
- | bloc에 주입할 usecase 목록 (쉼표 구분, bloc 전용) | (빈 값) |
--widget-type |
- | 위젯 타입 (stateless, stateful, hook, widget 전용) |
stateless |
--project-dir | -d | 대상 프로젝트 디렉토리 | 현재 디렉토리 |
--bricks-dir |
-b |
bricks/ 디렉토리 경로 |
자동 탐지 (상위 디렉토리로 순회) |
동작 방식#
-
단발 brick generate — 해당 atomic 브릭 1개를 임시 디렉토리에 generate합니다. hooks는
pre_gen만 실행하고post_gen은 실행하지 않습니다(구 라우터 등록·mason make 쉘아웃 차단). - 배치 규칙으로 병합 — 생성된 파일을 부품별 배치 규칙에 따라 feature 패키지(또는 server)로 복사합니다.
- barrel 1줄 append — 해당 barrel 파일 끝에 export 라인 1줄을 추가합니다. barrel이 없으면 헤더와 함께 새로 만듭니다.
멱등 가드#
| 상황 | 동작 |
|---|---|
| 대상 파일이 이미 존재 | 덮어쓰지 않고 skip — N files added, M skipped (already exist)로 보고 |
| barrel에 export 라인이 이미 존재 | append 생략 — barrel: 이미 등록됨 출력 |
| 같은 명령 반복 실행 | 추가 0건, 전부 skip — 중복 파일/중복 export 없음 |
feature 부재 시#
cob add는 기존 feature에만 부품을 추가합니다. 대상 feature 패키지(feature/<target>/<feature>
또는 server의 lib/src/feature/<feature>)가 없으면 에러로 종료하며, 새 feature는 cob compose -m feature.yaml로 생성하라고 안내합니다.
의존 부품 정책 (경고 + 안내)#
usecase와 endpoint는 N:1/N:0 관계라 분리된 명령으로 각각 추가합니다. 의존 부품이 없어도 생성은 계속 진행하되, 경고와 다음 명령 안내를 출력합니다.
| 추가 부품 | 검사 대상 | 미존재 시 |
|---|---|---|
usecase |
I<Feature>Repository의 동명(camelCase) 메서드 |
경고 — interface와 구현체/mixin에 메서드 추가 안내 (usecase ↔ repository 1:1 이름 규약) |
bloc |
--usecases로 지정한 각 usecase 파일 |
경고 — cob add usecase <name> --feature <feature> 먼저 실행 안내 |
endpoint |
feature의 service/ 부품 |
경고 — endpoint 본문 구현 시 b-service 브릭으로 서비스 추가 안내 |
예시#
usecase 추가#
cob add usecase get_detail --feature notice_board
feature/application/notice_board에 get_detail_usecase.dart와 테스트를 생성하고 usecase.dart
barrel에 export를 추가합니다. INoticeBoardRepository에 getDetail 메서드가 없으면 경고합니다.
bloc 추가 (usecase 주입)#
cob add bloc notice_detail --feature notice_board --usecases get_detail
blocs/notice_detail/ 디렉토리를 생성하고 bloc.dart barrel에 export 'notice_detail/bloc.dart';를 추가합니다.
get_detail usecase가 없으면 먼저 추가하라고 경고합니다.
widget 추가 (hook 타입)#
cob add widget notice_badge --feature notice_board --widget-type hook
hook 위젯과 테스트를 생성하고 widget.dart barrel 및 상위 presentation.dart에 export를 보장합니다.
endpoint 추가 (백엔드)#
cob add endpoint notice_export --feature notice_board
backend/*_server/lib/src/feature/notice_board/에 endpoint를 생성합니다. barrel append 대신 serverpod generate
실행을 안내합니다.
cd backend/my_app_server && serverpod generate
console 앱 feature에 추가#
cob add usecase export_csv --feature notice_board --target console
관련 명령#
| 명령 | 용도 |
|---|---|
cob compose | 새 feature 전체를 one-shot 합성 |
cob apply | 완성된 feature 브릭을 프로젝트에 적용 |