jsdoc-builder 0.0.5 → 0.0.7
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 +269 -58
- package/README.ja.md +304 -0
- package/README.ko.md +304 -0
- package/README.zh-CN.md +304 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +26 -5
- package/dist/index.d.ts +33 -0
- package/dist/index.js +793 -56
- package/dist/vite.d.ts +20 -0
- package/dist/vite.js +111 -0
- package/example/example.jsx +17 -0
- package/example/example.tsx +21 -0
- package/example/example.vue +36 -0
- package/package.json +20 -3
package/README.MD
CHANGED
|
@@ -1,105 +1,316 @@
|
|
|
1
1
|
# JSDoc Builder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](./README.MD) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [日本語](./README.ja.md)
|
|
4
|
+
|
|
5
|
+
JSDoc Builder is a CLI and library that adds JSDoc comments to JavaScript/TypeScript code automatically.
|
|
6
|
+
It supports JavaScript, TypeScript, JSX, TSX, and Vue SFC files.
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Why JSDoc Builder](#why-jsdoc-builder)
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [CLI Usage](#cli-usage)
|
|
15
|
+
- [Config File](#config-file)
|
|
16
|
+
- [AI Providers (OpenAI and Gemini)](#ai-providers-openai-and-gemini)
|
|
17
|
+
- [Language Support for Descriptions](#language-support-for-descriptions)
|
|
18
|
+
- [Vite Plugin Usage](#vite-plugin-usage)
|
|
19
|
+
- [Programmatic API](#programmatic-api)
|
|
20
|
+
- [Behavior and Safety](#behavior-and-safety)
|
|
21
|
+
- [Troubleshooting](#troubleshooting)
|
|
22
|
+
- [License](#license)
|
|
23
|
+
|
|
24
|
+
## Why JSDoc Builder
|
|
25
|
+
|
|
26
|
+
- Reduces repetitive JSDoc writing.
|
|
27
|
+
- Keeps function docs consistent across mixed JS/TS/Vue codebases.
|
|
28
|
+
- Works as:
|
|
29
|
+
- CLI for one-off or script-based use
|
|
30
|
+
- Library API for custom tooling
|
|
31
|
+
- Vite plugin for on-the-fly transform during dev/build
|
|
4
32
|
|
|
5
33
|
## Features
|
|
6
34
|
|
|
7
|
-
-
|
|
35
|
+
- Generates JSDoc for:
|
|
8
36
|
- Function declarations
|
|
9
|
-
- Arrow functions
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
37
|
+
- Arrow functions assigned to variables
|
|
38
|
+
- Function expressions assigned to variables
|
|
39
|
+
- Supported file types:
|
|
40
|
+
- `.js`, `.mjs`, `.cjs`
|
|
41
|
+
- `.ts`
|
|
42
|
+
- `.jsx`
|
|
43
|
+
- `.tsx`
|
|
44
|
+
- `.vue` (updates only `<script>` content)
|
|
45
|
+
- Skips nodes that already have JSDoc comments.
|
|
46
|
+
- Tries to infer parameter and return types.
|
|
47
|
+
- Supports custom JSDoc templates via config.
|
|
48
|
+
- Supports AI-generated `@description` using OpenAI or Gemini.
|
|
49
|
+
- Provides safe fallback when AI key/request is unavailable.
|
|
13
50
|
|
|
14
51
|
## Installation
|
|
15
52
|
|
|
16
|
-
Install
|
|
53
|
+
Install globally:
|
|
17
54
|
|
|
18
55
|
```bash
|
|
19
|
-
npm install jsdoc-builder
|
|
56
|
+
npm install -g jsdoc-builder
|
|
20
57
|
```
|
|
21
58
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install jsdoc-builder --save-dev
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
### CLI Command
|
|
31
|
-
|
|
32
|
-
Run the following command to generate JSDoc comments for a file:
|
|
59
|
+
Or install in a project:
|
|
33
60
|
|
|
34
61
|
```bash
|
|
35
|
-
jsdoc-builder
|
|
62
|
+
npm install --save-dev jsdoc-builder
|
|
36
63
|
```
|
|
37
64
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
### Example
|
|
65
|
+
## Quick Start
|
|
41
66
|
|
|
42
|
-
|
|
67
|
+
1. Create a source file:
|
|
43
68
|
|
|
44
|
-
```
|
|
69
|
+
```ts
|
|
45
70
|
function add(a: number, b: number) {
|
|
46
71
|
return a + b;
|
|
47
72
|
}
|
|
48
|
-
|
|
49
|
-
const multiply = (a: number, b: number): number => {
|
|
50
|
-
return a * b;
|
|
51
|
-
};
|
|
52
73
|
```
|
|
53
74
|
|
|
54
|
-
|
|
75
|
+
2. Run CLI:
|
|
55
76
|
|
|
56
77
|
```bash
|
|
57
|
-
jsdoc-builder example.ts
|
|
78
|
+
jsdoc-builder ./example.ts
|
|
58
79
|
```
|
|
59
80
|
|
|
60
|
-
|
|
81
|
+
3. Result:
|
|
61
82
|
|
|
62
|
-
```
|
|
83
|
+
```ts
|
|
63
84
|
/**
|
|
64
|
-
* @description
|
|
85
|
+
* @description add function
|
|
65
86
|
* @param {number} a
|
|
66
87
|
* @param {number} b
|
|
67
|
-
* @returns {
|
|
88
|
+
* @returns {number}
|
|
68
89
|
*/
|
|
69
90
|
function add(a: number, b: number) {
|
|
70
91
|
return a + b;
|
|
71
92
|
}
|
|
93
|
+
```
|
|
72
94
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
## CLI Usage
|
|
96
|
+
|
|
97
|
+
Basic:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
jsdoc-builder <file-path>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Options:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
jsdoc-builder <file-path> --config ./jsdoc-builder.config.json
|
|
107
|
+
jsdoc-builder <file-path> --no-ai
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- `-c, --config <path>`: custom config file path.
|
|
111
|
+
- `--no-ai`: force disable AI descriptions even if config enables AI.
|
|
112
|
+
|
|
113
|
+
## Config File
|
|
114
|
+
|
|
115
|
+
Default config location is `./jsdoc-builder.config.json`.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"template": {
|
|
122
|
+
"descriptionLine": "@description {{description}}",
|
|
123
|
+
"paramLine": "@param {${type}} ${name}",
|
|
124
|
+
"returnsLine": "@returns {${type}}"
|
|
125
|
+
},
|
|
126
|
+
"includeReturnsWhenVoid": true,
|
|
127
|
+
"ai": {
|
|
128
|
+
"enabled": true,
|
|
129
|
+
"provider": "openai",
|
|
130
|
+
"model": "gpt-4o-mini",
|
|
131
|
+
"apiKey": "YOUR_API_KEY",
|
|
132
|
+
"baseUrl": "https://api.openai.com/v1/chat/completions",
|
|
133
|
+
"timeoutMs": 12000,
|
|
134
|
+
"promptTemplate": "Write one concise sentence for '{{functionName}}'. Params: {{parameters}}. Return type: {{returnType}}. Source: {{sourceSnippet}}"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Config Fields
|
|
140
|
+
|
|
141
|
+
- `template.descriptionLine`: template for description line.
|
|
142
|
+
- `template.paramLine`: template for each parameter line.
|
|
143
|
+
- `template.returnsLine`: template for returns line.
|
|
144
|
+
- `includeReturnsWhenVoid`: when `false`, omits `@returns` for `void` functions.
|
|
145
|
+
- `ai.enabled`: enables or disables AI generation.
|
|
146
|
+
- `ai.provider`: `"openai"` or `"gemini"`.
|
|
147
|
+
- `ai.model`: model name for selected provider.
|
|
148
|
+
- `ai.apiKey`: provider API key.
|
|
149
|
+
- `ai.baseUrl`: provider base endpoint.
|
|
150
|
+
- `ai.timeoutMs`: request timeout in milliseconds.
|
|
151
|
+
- `ai.promptTemplate`: prompt template used for the AI request.
|
|
152
|
+
|
|
153
|
+
### Template Placeholders
|
|
154
|
+
|
|
155
|
+
Supported placeholders in templates:
|
|
156
|
+
|
|
157
|
+
- `{{functionName}}` or `${functionName}`
|
|
158
|
+
- `{{description}}` or `${description}`
|
|
159
|
+
- `{{type}}` or `${type}`
|
|
160
|
+
- `{{name}}` or `${name}`
|
|
161
|
+
- `{{returnType}}` or `${returnType}`
|
|
162
|
+
- `{{paramsCount}}` or `${paramsCount}`
|
|
163
|
+
|
|
164
|
+
## AI Providers (OpenAI and Gemini)
|
|
165
|
+
|
|
166
|
+
### OpenAI
|
|
167
|
+
|
|
168
|
+
- `ai.provider`: `"openai"`
|
|
169
|
+
- Default model: `gpt-4o-mini`
|
|
170
|
+
- Default endpoint: `https://api.openai.com/v1/chat/completions`
|
|
171
|
+
- Env fallback key: `OPENAI_API_KEY`
|
|
172
|
+
|
|
173
|
+
### Gemini
|
|
174
|
+
|
|
175
|
+
- `ai.provider`: `"gemini"`
|
|
176
|
+
- Default model: `gemini-1.5-flash`
|
|
177
|
+
- Default base URL: `https://generativelanguage.googleapis.com/v1beta`
|
|
178
|
+
- Env fallback key: `GEMINI_API_KEY` or `GOOGLE_API_KEY`
|
|
179
|
+
|
|
180
|
+
Gemini config example:
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"ai": {
|
|
185
|
+
"enabled": true,
|
|
186
|
+
"provider": "gemini",
|
|
187
|
+
"model": "gemini-1.5-flash",
|
|
188
|
+
"apiKey": "YOUR_GEMINI_API_KEY"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Missing API Key Behavior
|
|
194
|
+
|
|
195
|
+
If `ai.apiKey` is missing:
|
|
196
|
+
|
|
197
|
+
1. JSDoc Builder checks environment variables based on provider.
|
|
198
|
+
2. If still missing, AI is disabled automatically.
|
|
199
|
+
3. `@description` falls back to `"<functionName> function"`.
|
|
200
|
+
|
|
201
|
+
## Language Support for Descriptions
|
|
202
|
+
|
|
203
|
+
JSDoc Builder can generate description text in Korean, English, Chinese, or Japanese by changing `ai.promptTemplate`.
|
|
204
|
+
|
|
205
|
+
Korean prompt example:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"ai": {
|
|
210
|
+
"enabled": true,
|
|
211
|
+
"provider": "openai",
|
|
212
|
+
"promptTemplate": "함수 '{{functionName}}'의 JSDoc 설명을 한국어 한 문장으로 작성해 주세요. 파라미터: {{parameters}}, 반환 타입: {{returnType}}"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Chinese prompt example:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"ai": {
|
|
222
|
+
"enabled": true,
|
|
223
|
+
"provider": "gemini",
|
|
224
|
+
"promptTemplate": "请用中文一句话编写函数 '{{functionName}}' 的 JSDoc 描述。参数: {{parameters}},返回类型: {{returnType}}"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Japanese prompt example:
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"ai": {
|
|
234
|
+
"enabled": true,
|
|
235
|
+
"provider": "openai",
|
|
236
|
+
"promptTemplate": "関数 '{{functionName}}' の JSDoc 説明を日本語で1文で作成してください。引数: {{parameters}}、戻り値型: {{returnType}}"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Vite Plugin Usage
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { defineConfig } from "vite";
|
|
245
|
+
import { jsdocBuilderVitePlugin } from "jsdoc-builder/vite";
|
|
246
|
+
|
|
247
|
+
export default defineConfig({
|
|
248
|
+
plugins: [
|
|
249
|
+
jsdocBuilderVitePlugin({
|
|
250
|
+
apply: "serve",
|
|
251
|
+
configPath: "./jsdoc-builder.config.json",
|
|
252
|
+
include: ["src/"],
|
|
253
|
+
exclude: [/node_modules/, /dist/],
|
|
254
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"]
|
|
255
|
+
})
|
|
256
|
+
]
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Plugin options:
|
|
261
|
+
|
|
262
|
+
- `apply`: `"serve" | "build" | "both"` (default `"both"`)
|
|
263
|
+
- `include`: only process matching files (string includes or RegExp)
|
|
264
|
+
- `exclude`: skip matching files
|
|
265
|
+
- `extensions`: file extensions to process
|
|
266
|
+
- Also supports all `GenerateJSDocOptions` (`configPath`, `config`, `disableAI`)
|
|
267
|
+
|
|
268
|
+
## Programmatic API
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
import { generateJSDoc, generateJSDocFromCode } from "jsdoc-builder";
|
|
272
|
+
|
|
273
|
+
await generateJSDoc("./src/utils.ts", {
|
|
274
|
+
configPath: "./jsdoc-builder.config.json"
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const output = await generateJSDocFromCode(
|
|
278
|
+
"/virtual/example.ts",
|
|
279
|
+
"const sum = (a, b) => a + b;",
|
|
280
|
+
{
|
|
281
|
+
config: {
|
|
282
|
+
ai: { enabled: false }
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
console.log(output);
|
|
82
288
|
```
|
|
83
289
|
|
|
84
|
-
|
|
290
|
+
### API Reference
|
|
85
291
|
|
|
86
|
-
|
|
292
|
+
- `generateJSDoc(filePath, options?)`: reads a file, transforms it, writes result.
|
|
293
|
+
- `generateJSDocFromCode(filePath, code, options?)`: returns transformed code string.
|
|
87
294
|
|
|
88
|
-
|
|
89
|
-
- **Parameters**:
|
|
90
|
-
- `filePath` (string): The path to the file to be processed.
|
|
91
|
-
- **Returns**: `void`
|
|
295
|
+
## Behavior and Safety
|
|
92
296
|
|
|
93
|
-
|
|
297
|
+
- Existing JSDoc is preserved.
|
|
298
|
+
- If no transform target is found, content is unchanged.
|
|
299
|
+
- Vue files keep template/style blocks untouched.
|
|
300
|
+
- AI errors do not break processing; fallback description is used.
|
|
94
301
|
|
|
95
|
-
|
|
302
|
+
## Troubleshooting
|
|
96
303
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
304
|
+
- `Cannot find module ...` in TypeScript:
|
|
305
|
+
- Check `tsconfig.json` includes Node types.
|
|
306
|
+
- Use `module` and `moduleResolution` values compatible with your TS version.
|
|
307
|
+
- AI descriptions are not generated:
|
|
308
|
+
- Confirm `ai.enabled: true`
|
|
309
|
+
- Confirm provider API key is set in config or env
|
|
310
|
+
- Confirm provider endpoint is reachable
|
|
311
|
+
- Descriptions are in the wrong language:
|
|
312
|
+
- Update `ai.promptTemplate` with your target language instruction.
|
|
102
313
|
|
|
103
314
|
## License
|
|
104
315
|
|
|
105
|
-
|
|
316
|
+
MIT. See [LICENSE](./LICENSE).
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# JSDoc Builder
|
|
2
|
+
|
|
3
|
+
[English](./README.MD) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [日本語](./README.ja.md)
|
|
4
|
+
|
|
5
|
+
JSDoc Builder は、JavaScript/TypeScript のコードに JSDoc コメントを自動生成する CLI/ライブラリです。
|
|
6
|
+
JavaScript、TypeScript、JSX、TSX、Vue SFC をサポートします。
|
|
7
|
+
|
|
8
|
+
## 目次
|
|
9
|
+
|
|
10
|
+
- [概要](#概要)
|
|
11
|
+
- [主な機能](#主な機能)
|
|
12
|
+
- [インストール](#インストール)
|
|
13
|
+
- [クイックスタート](#クイックスタート)
|
|
14
|
+
- [CLI の使い方](#cli-の使い方)
|
|
15
|
+
- [設定ファイル](#設定ファイル)
|
|
16
|
+
- [AI プロバイダー (OpenAI / Gemini)](#ai-プロバイダー-openai--gemini)
|
|
17
|
+
- [説明文の多言語対応(韓国語/英語/中国語/日本語)](#説明文の多言語対応韓国語英語中国語日本語)
|
|
18
|
+
- [Vite プラグイン](#vite-プラグイン)
|
|
19
|
+
- [プログラム API](#プログラム-api)
|
|
20
|
+
- [挙動と安全性](#挙動と安全性)
|
|
21
|
+
- [トラブルシューティング](#トラブルシューティング)
|
|
22
|
+
- [ライセンス](#ライセンス)
|
|
23
|
+
|
|
24
|
+
## 概要
|
|
25
|
+
|
|
26
|
+
- JSDoc の繰り返し作業を減らします。
|
|
27
|
+
- JS/TS/Vue 混在プロジェクトでもコメント形式を統一できます。
|
|
28
|
+
- 以下の使い方に対応します。
|
|
29
|
+
- CLI
|
|
30
|
+
- ライブラリ API
|
|
31
|
+
- Vite プラグイン
|
|
32
|
+
|
|
33
|
+
## 主な機能
|
|
34
|
+
|
|
35
|
+
- 次の対象に JSDoc を生成:
|
|
36
|
+
- 関数宣言
|
|
37
|
+
- 変数に代入されたアロー関数
|
|
38
|
+
- 変数に代入された関数式
|
|
39
|
+
- 対応拡張子:
|
|
40
|
+
- `.js`, `.mjs`, `.cjs`
|
|
41
|
+
- `.ts`
|
|
42
|
+
- `.jsx`
|
|
43
|
+
- `.tsx`
|
|
44
|
+
- `.vue`(`<script>` のみ更新)
|
|
45
|
+
- 既存 JSDoc があるノードはスキップ。
|
|
46
|
+
- 可能な範囲で引数型/戻り値型を推論。
|
|
47
|
+
- テンプレートのカスタマイズに対応。
|
|
48
|
+
- OpenAI/Gemini による `@description` 生成に対応。
|
|
49
|
+
- API キーなし/AI 失敗時は安全にフォールバック。
|
|
50
|
+
|
|
51
|
+
## インストール
|
|
52
|
+
|
|
53
|
+
グローバル:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install -g jsdoc-builder
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
プロジェクト:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install --save-dev jsdoc-builder
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## クイックスタート
|
|
66
|
+
|
|
67
|
+
1. ファイルを用意:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
function add(a: number, b: number) {
|
|
71
|
+
return a + b;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
2. 実行:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
jsdoc-builder ./example.ts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
3. 出力:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
/**
|
|
85
|
+
* @description add function
|
|
86
|
+
* @param {number} a
|
|
87
|
+
* @param {number} b
|
|
88
|
+
* @returns {number}
|
|
89
|
+
*/
|
|
90
|
+
function add(a: number, b: number) {
|
|
91
|
+
return a + b;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## CLI の使い方
|
|
96
|
+
|
|
97
|
+
基本:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
jsdoc-builder <file-path>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
オプション:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
jsdoc-builder <file-path> --config ./jsdoc-builder.config.json
|
|
107
|
+
jsdoc-builder <file-path> --no-ai
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- `-c, --config <path>`: 設定ファイルパス
|
|
111
|
+
- `--no-ai`: 設定で AI が有効でも強制的に無効化
|
|
112
|
+
|
|
113
|
+
## 設定ファイル
|
|
114
|
+
|
|
115
|
+
デフォルトパスは `./jsdoc-builder.config.json` です。
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"template": {
|
|
120
|
+
"descriptionLine": "@description {{description}}",
|
|
121
|
+
"paramLine": "@param {${type}} ${name}",
|
|
122
|
+
"returnsLine": "@returns {${type}}"
|
|
123
|
+
},
|
|
124
|
+
"includeReturnsWhenVoid": true,
|
|
125
|
+
"ai": {
|
|
126
|
+
"enabled": true,
|
|
127
|
+
"provider": "openai",
|
|
128
|
+
"model": "gpt-4o-mini",
|
|
129
|
+
"apiKey": "YOUR_API_KEY",
|
|
130
|
+
"baseUrl": "https://api.openai.com/v1/chat/completions",
|
|
131
|
+
"timeoutMs": 12000,
|
|
132
|
+
"promptTemplate": "Write one concise sentence for '{{functionName}}'. Params: {{parameters}}. Return type: {{returnType}}. Source: {{sourceSnippet}}"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 設定項目
|
|
138
|
+
|
|
139
|
+
- `template.descriptionLine`: 説明行テンプレート
|
|
140
|
+
- `template.paramLine`: 引数行テンプレート
|
|
141
|
+
- `template.returnsLine`: 戻り値行テンプレート
|
|
142
|
+
- `includeReturnsWhenVoid`: `false` の場合、`void` 関数の `@returns` を省略
|
|
143
|
+
- `ai.enabled`: AI 生成の有効/無効
|
|
144
|
+
- `ai.provider`: `"openai"` または `"gemini"`
|
|
145
|
+
- `ai.model`: モデル名
|
|
146
|
+
- `ai.apiKey`: API キー
|
|
147
|
+
- `ai.baseUrl`: エンドポイントのベース URL
|
|
148
|
+
- `ai.timeoutMs`: タイムアウト(ミリ秒)
|
|
149
|
+
- `ai.promptTemplate`: AI プロンプトテンプレート
|
|
150
|
+
|
|
151
|
+
### テンプレートのプレースホルダー
|
|
152
|
+
|
|
153
|
+
- `{{functionName}}` / `${functionName}`
|
|
154
|
+
- `{{description}}` / `${description}`
|
|
155
|
+
- `{{type}}` / `${type}`
|
|
156
|
+
- `{{name}}` / `${name}`
|
|
157
|
+
- `{{returnType}}` / `${returnType}`
|
|
158
|
+
- `{{paramsCount}}` / `${paramsCount}`
|
|
159
|
+
|
|
160
|
+
## AI プロバイダー (OpenAI / Gemini)
|
|
161
|
+
|
|
162
|
+
OpenAI:
|
|
163
|
+
|
|
164
|
+
- `ai.provider`: `"openai"`
|
|
165
|
+
- デフォルトモデル: `gpt-4o-mini`
|
|
166
|
+
- デフォルト URL: `https://api.openai.com/v1/chat/completions`
|
|
167
|
+
- 環境変数キー: `OPENAI_API_KEY`
|
|
168
|
+
|
|
169
|
+
Gemini:
|
|
170
|
+
|
|
171
|
+
- `ai.provider`: `"gemini"`
|
|
172
|
+
- デフォルトモデル: `gemini-1.5-flash`
|
|
173
|
+
- デフォルト URL: `https://generativelanguage.googleapis.com/v1beta`
|
|
174
|
+
- 環境変数キー: `GEMINI_API_KEY` または `GOOGLE_API_KEY`
|
|
175
|
+
|
|
176
|
+
Gemini 設定例:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"ai": {
|
|
181
|
+
"enabled": true,
|
|
182
|
+
"provider": "gemini",
|
|
183
|
+
"model": "gemini-1.5-flash",
|
|
184
|
+
"apiKey": "YOUR_GEMINI_API_KEY"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### API キーがない場合の挙動
|
|
190
|
+
|
|
191
|
+
1. プロバイダーごとの環境変数を確認
|
|
192
|
+
2. 取得できなければ AI を自動的に無効化
|
|
193
|
+
3. `@description` は `"<functionName> function"` にフォールバック
|
|
194
|
+
|
|
195
|
+
## 説明文の多言語対応(韓国語/英語/中国語/日本語)
|
|
196
|
+
|
|
197
|
+
`ai.promptTemplate` を変更することで、説明文の言語を制御できます。
|
|
198
|
+
|
|
199
|
+
韓国語例:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"ai": {
|
|
204
|
+
"enabled": true,
|
|
205
|
+
"provider": "openai",
|
|
206
|
+
"promptTemplate": "함수 '{{functionName}}'의 JSDoc 설명을 한국어 한 문장으로 작성해 주세요. 파라미터: {{parameters}}, 반환 타입: {{returnType}}"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
中国語例:
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"ai": {
|
|
216
|
+
"enabled": true,
|
|
217
|
+
"provider": "gemini",
|
|
218
|
+
"promptTemplate": "请用中文一句话编写函数 '{{functionName}}' 的 JSDoc 描述。参数: {{parameters}},返回类型: {{returnType}}"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
日本語例:
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"ai": {
|
|
228
|
+
"enabled": true,
|
|
229
|
+
"provider": "openai",
|
|
230
|
+
"promptTemplate": "関数 '{{functionName}}' の JSDoc 説明を日本語で1文で作成してください。引数: {{parameters}}、戻り値型: {{returnType}}"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Vite プラグイン
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { defineConfig } from "vite";
|
|
239
|
+
import { jsdocBuilderVitePlugin } from "jsdoc-builder/vite";
|
|
240
|
+
|
|
241
|
+
export default defineConfig({
|
|
242
|
+
plugins: [
|
|
243
|
+
jsdocBuilderVitePlugin({
|
|
244
|
+
apply: "serve",
|
|
245
|
+
configPath: "./jsdoc-builder.config.json",
|
|
246
|
+
include: ["src/"],
|
|
247
|
+
exclude: [/node_modules/, /dist/],
|
|
248
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".vue"]
|
|
249
|
+
})
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
主なオプション:
|
|
255
|
+
|
|
256
|
+
- `apply`: `"serve" | "build" | "both"`(既定値 `"both"`)
|
|
257
|
+
- `include`: 処理対象のフィルター
|
|
258
|
+
- `exclude`: 除外対象のフィルター
|
|
259
|
+
- `extensions`: 対象拡張子
|
|
260
|
+
- `GenerateJSDocOptions` も使用可(`configPath`, `config`, `disableAI`)
|
|
261
|
+
|
|
262
|
+
## プログラム API
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import { generateJSDoc, generateJSDocFromCode } from "jsdoc-builder";
|
|
266
|
+
|
|
267
|
+
await generateJSDoc("./src/utils.ts", {
|
|
268
|
+
configPath: "./jsdoc-builder.config.json"
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const output = await generateJSDocFromCode(
|
|
272
|
+
"/virtual/example.ts",
|
|
273
|
+
"const sum = (a, b) => a + b;",
|
|
274
|
+
{
|
|
275
|
+
config: {
|
|
276
|
+
ai: { enabled: false }
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
console.log(output);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 挙動と安全性
|
|
285
|
+
|
|
286
|
+
- 既存 JSDoc は保持されます。
|
|
287
|
+
- 変換対象がない場合は内容を変更しません。
|
|
288
|
+
- Vue はテンプレート/スタイルを変更しません。
|
|
289
|
+
- AI エラー時も処理は継続し、フォールバック説明を使用します。
|
|
290
|
+
|
|
291
|
+
## トラブルシューティング
|
|
292
|
+
|
|
293
|
+
- TypeScript モジュール関連エラー:
|
|
294
|
+
- `tsconfig.json` の Node 型/モジュール解決設定を確認
|
|
295
|
+
- AI 説明が生成されない:
|
|
296
|
+
- `ai.enabled: true` を確認
|
|
297
|
+
- API キー(設定または環境変数)を確認
|
|
298
|
+
- エンドポイントへの接続を確認
|
|
299
|
+
- 言語が期待どおりでない:
|
|
300
|
+
- `ai.promptTemplate` の言語指示を修正
|
|
301
|
+
|
|
302
|
+
## ライセンス
|
|
303
|
+
|
|
304
|
+
MIT. [LICENSE](./LICENSE) を参照。
|