@toktokhan-dev/cli-plugin-gen-api-react-query 0.1.8 → 0.1.9

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/dist/index.js CHANGED
@@ -121,10 +121,18 @@ const writeSwaggerApiFile = (params) => {
121
121
  });
122
122
  };
123
123
  async function generatePretty(path, contents) {
124
- const organized = await prettierString(contents, {
125
- parser: 'babel-ts',
126
- plugins: ['prettier-plugin-organize-imports'],
127
- });
124
+ // prettier-plugin-organize-imports가 설치되어 있으면 사용, 없으면 스킵
125
+ let organized = contents;
126
+ try {
127
+ organized = await prettierString(contents, {
128
+ parser: 'babel-ts',
129
+ plugins: ['prettier-plugin-organize-imports'],
130
+ });
131
+ }
132
+ catch (err) {
133
+ // 플러그인이 없거나 에러 발생 시 원본 사용
134
+ console.warn('⚠️ prettier-plugin-organize-imports not found, skipping import organization');
135
+ }
128
136
  const formatted = await prettierString(organized, {
129
137
  parser: 'typescript',
130
138
  configPath: 'auto',
@@ -347,20 +355,27 @@ function mergeTypeScriptContent(existing, newContent) {
347
355
  const mergedTypesString = Object.values(mergedTypes).join('\n\n');
348
356
  // 3) 기타 코드(타입/임포트 외)는 "새로운 내용"을 기준으로 유지
349
357
  const removeHeaderComment = (content) => {
350
- // 파일 상단의 블록 코멘트 혹은 연속된 라인 코멘트 제거
351
- const blockCommentAtTop = content.match(/^\s*\/\*[\s\S]*?\*\/\s*/);
352
- if (blockCommentAtTop) {
353
- return content.slice(blockCommentAtTop[0].length);
354
- }
355
- const lineCommentsAtTop = content.match(/^(?:\s*\/\/.*\n)+/);
356
- if (lineCommentsAtTop) {
357
- return content.slice(lineCommentsAtTop[0].length);
358
- }
359
- return content;
358
+ // 파일 상단의 모든 블록 코멘트와 라인 코멘트를 제거 (재귀적 처리)
359
+ const removeBlockComment = (str) => {
360
+ const result = str.replace(/^\s*\/\*[\s\S]*?\*\/\s*/, '');
361
+ return result === str ? str : removeBlockComment(result);
362
+ };
363
+ const removeLineComment = (str) => {
364
+ const result = str.replace(/^(?:\s*\/\/.*\n)+/, '');
365
+ return result === str ? str : removeLineComment(result);
366
+ };
367
+ // 블록 주석 제거 후 라인 주석 제거
368
+ return removeLineComment(removeBlockComment(content));
360
369
  };
361
370
  // 새 본문에서 타입 블록 제거 후 남은 코드
362
371
  const newBodyWithoutTypes = (newBody || '').replace(typeBlockRegex, '');
363
- const otherCodeFromNew = removeHeaderComment(newBodyWithoutTypes).trim();
372
+ let otherCodeFromNew = removeHeaderComment(newBodyWithoutTypes).trim();
373
+ // 본문 내에 남아있는 "!DO NOT EDIT THIS FILE" 주석 블록들을 모두 제거
374
+ otherCodeFromNew = otherCodeFromNew.replace(/\/\*\*?\s*\*\s*!DO NOT EDIT THIS FILE[\s\S]*?\*\//g, '');
375
+ // "tok-cli.config.ts 에서 설정된..." 주석도 제거
376
+ otherCodeFromNew = otherCodeFromNew.replace(/\/\*\*?\s*\*\s*tok-cli\.config\.ts[\s\S]*?\*\//g, '');
377
+ // 연속된 빈 줄 정리
378
+ otherCodeFromNew = otherCodeFromNew.replace(/\n\s*\n\s*\n+/g, '\n\n').trim();
364
379
  // 4) 헤더 주석은 새 컨텐츠 상단의 헤더가 있으면 우선 사용, 없으면 기존의 것을 사용
365
380
  const pickHeader = (content) => {
366
381
  const block = content.match(/^\s*(\/\*[\s\S]*?\*\/)\s*/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toktokhan-dev/cli-plugin-gen-api-react-query",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A CLI plugin for generating API hooks with React Query built by TOKTOKHAN.DEV",
5
5
  "author": "TOKTOKHAN.DEV <fe-system@toktokhan.dev>",
6
6
  "license": "ISC",
@@ -40,10 +40,11 @@ export type InfiniteQueryHookParams<
40
40
  TData = RequestFnReturn<T>,
41
41
  OriginData = RequestFnReturn<T>,
42
42
  Variables = Parameter<T>,
43
+ TPageParam = string
43
44
  > = {
44
45
  options?: Partial<
45
46
  Omit<
46
- UseInfiniteQueryOptions<OriginData, Error, TData, any, any>,
47
+ UseInfiniteQueryOptions<OriginData, Error, TData, OriginData, any, TPageParam>,
47
48
  'queryKey' | 'queryFn'
48
49
  >
49
50
  >;
@@ -80,10 +81,11 @@ export type SuspenseInfiniteQueryHookParams<
80
81
  TData = RequestFnReturn<T>,
81
82
  OriginData = RequestFnReturn<T>,
82
83
  Variables = Parameter<T>,
84
+ TPageParam = string
83
85
  > = {
84
86
  options?: Partial<
85
87
  Omit<
86
- UseSuspenseInfiniteQueryOptions<OriginData, Error, TData, any, any>,
88
+ UseSuspenseInfiniteQueryOptions<OriginData, Error, TData, OriginData, any, TPageParam>,
87
89
  'queryKey' | 'queryFn'
88
90
  >
89
91
  >;