scaffold-doc-cli 1.0.5 → 1.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/index.js +21 -10
- package/package.json +1 -1
- package/.github/scripts/doc-sync.mjs +0 -88
- package/.github/workflows/ai-doc-sync.yml +0 -47
- package/mkdocs.yml +0 -12
package/index.js
CHANGED
|
@@ -220,11 +220,17 @@ async function main() {
|
|
|
220
220
|
// 1. Detect Changed Files
|
|
221
221
|
let changedFiles = [];
|
|
222
222
|
try {
|
|
223
|
-
const output = execSync('git diff --name-only HEAD~1 HEAD').toString();
|
|
223
|
+
const output = execSync('git diff --name-only HEAD~1 HEAD 2>/dev/null').toString();
|
|
224
224
|
changedFiles = output.split('\\n').filter(f => f && !f.startsWith('.docs') && !f.startsWith('.github'));
|
|
225
225
|
} catch (e) {
|
|
226
|
-
console.
|
|
227
|
-
|
|
226
|
+
console.warn("HEAD~1 not found (likely first commit). Syncing all tracked files...");
|
|
227
|
+
try {
|
|
228
|
+
const output = execSync('git ls-tree -r HEAD --name-only').toString();
|
|
229
|
+
changedFiles = output.split('\\n').filter(f => f && !f.startsWith('.docs') && !f.startsWith('.github'));
|
|
230
|
+
} catch (err) {
|
|
231
|
+
console.error("Failed to list files:", err.message);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
228
234
|
}
|
|
229
235
|
|
|
230
236
|
if (changedFiles.length === 0) {
|
|
@@ -244,8 +250,10 @@ async function main() {
|
|
|
244
250
|
}
|
|
245
251
|
|
|
246
252
|
// 3. Prompt Gemini
|
|
247
|
-
|
|
248
|
-
|
|
253
|
+
// 3. Prompt Gemini (using @google/genai SDK)
|
|
254
|
+
// No need to get model instance first in this SDK version based on user snippet
|
|
255
|
+
|
|
256
|
+
|
|
249
257
|
const prompt = \`
|
|
250
258
|
You are a technical documentation assistant.
|
|
251
259
|
Analyze the following code changes and update the documentation in the .docs/ directory.
|
|
@@ -262,9 +270,12 @@ async function main() {
|
|
|
262
270
|
\`;
|
|
263
271
|
|
|
264
272
|
try {
|
|
265
|
-
const result = await
|
|
266
|
-
|
|
267
|
-
|
|
273
|
+
const result = await genAI.models.generateContent({
|
|
274
|
+
model: "gemini-2.5-flash",
|
|
275
|
+
contents: prompt
|
|
276
|
+
});
|
|
277
|
+
const text = result.text;
|
|
278
|
+
|
|
268
279
|
// Simple cleanup if model adds code blocks
|
|
269
280
|
const jsonStr = text.replace(/\\\`\\\`\\\`json/g, '').replace(/\\\`\\\`\\\`/g, '').trim();
|
|
270
281
|
const updates = JSON.parse(jsonStr);
|
|
@@ -273,11 +284,11 @@ async function main() {
|
|
|
273
284
|
for (const [relativePath, content] of Object.entries(updates)) {
|
|
274
285
|
const fullPath = path.join(process.cwd(), '.docs', relativePath);
|
|
275
286
|
const dir = path.dirname(fullPath);
|
|
276
|
-
|
|
287
|
+
|
|
277
288
|
if (!fs.existsSync(dir)) {
|
|
278
289
|
fs.mkdirSync(dir, { recursive: true });
|
|
279
290
|
}
|
|
280
|
-
|
|
291
|
+
|
|
281
292
|
fs.writeFileSync(fullPath, content);
|
|
282
293
|
console.log(\`Updated: .docs/\${relativePath}\`);
|
|
283
294
|
}
|
package/package.json
CHANGED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { GoogleGenAI } from "@google/genai";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
|
|
6
|
-
const genAI = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
console.log("Starting AI Doc Sync...");
|
|
10
|
-
|
|
11
|
-
// 1. Detect Changed Files
|
|
12
|
-
let changedFiles = [];
|
|
13
|
-
try {
|
|
14
|
-
const output = execSync('git diff --name-only HEAD~1 HEAD').toString();
|
|
15
|
-
changedFiles = output.split('\n').filter(f => f && !f.startsWith('.docs') && !f.startsWith('.github'));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.warn("Could not compare with HEAD~1 (likely first commit or shallow fetch). Falling back to listing all files.");
|
|
18
|
-
try {
|
|
19
|
-
const output = execSync('git ls-tree -r --name-only HEAD').toString();
|
|
20
|
-
changedFiles = output.split('\n').filter(f => f && !f.startsWith('.docs') && !f.startsWith('.github'));
|
|
21
|
-
} catch (fallbackError) {
|
|
22
|
-
console.error("Failed to list files:", fallbackError.message);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (changedFiles.length === 0) {
|
|
28
|
-
console.log("No relevant code changes detected.");
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
console.log("Processing changed files:", changedFiles);
|
|
33
|
-
|
|
34
|
-
// 2. Prepare Context for Gemini
|
|
35
|
-
let context = "";
|
|
36
|
-
for (const file of changedFiles) {
|
|
37
|
-
if (fs.existsSync(file)) {
|
|
38
|
-
context += `\n--- File: ${file} ---\n`;
|
|
39
|
-
context += fs.readFileSync(file, 'utf-8').slice(0, 10000); // Limit size
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 3. Prompt Gemini
|
|
44
|
-
const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" });
|
|
45
|
-
|
|
46
|
-
const prompt = `
|
|
47
|
-
You are a technical documentation assistant.
|
|
48
|
-
Analyze the following code changes and update the documentation in the .docs/ directory.
|
|
49
|
-
|
|
50
|
-
Rules:
|
|
51
|
-
1. Output MUST be a valid JSON object where keys are file paths (relative to .docs/, e.g., "reference/controllers.md") and values are the NEW content of that file.
|
|
52
|
-
2. You can create new files if necessary.
|
|
53
|
-
3. You can update existing files (e.g., getting-started.md, architecture.md).
|
|
54
|
-
4. Focus on accuracy and clarity.
|
|
55
|
-
5. Do not include markdown code fence blocks in your response, just the raw JSON string.
|
|
56
|
-
|
|
57
|
-
Code Context:
|
|
58
|
-
${context}
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const result = await model.generateContent(prompt);
|
|
63
|
-
const text = result.response.text();
|
|
64
|
-
|
|
65
|
-
// Simple cleanup if model adds code blocks
|
|
66
|
-
const jsonStr = text.replace(/\`\`\`json/g, '').replace(/\`\`\`/g, '').trim();
|
|
67
|
-
const updates = JSON.parse(jsonStr);
|
|
68
|
-
|
|
69
|
-
// 4. Write Updates
|
|
70
|
-
for (const [relativePath, content] of Object.entries(updates)) {
|
|
71
|
-
const fullPath = path.join(process.cwd(), '.docs', relativePath);
|
|
72
|
-
const dir = path.dirname(fullPath);
|
|
73
|
-
|
|
74
|
-
if (!fs.existsSync(dir)) {
|
|
75
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
fs.writeFileSync(fullPath, content);
|
|
79
|
-
console.log(`Updated: .docs/${relativePath}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error("AI Generation failed:", error);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
main();
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
name: AI Doc Sync
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
paths-ignore:
|
|
6
|
-
- '.docs/**'
|
|
7
|
-
workflow_dispatch:
|
|
8
|
-
|
|
9
|
-
permissions:
|
|
10
|
-
contents: write
|
|
11
|
-
pull-requests: write
|
|
12
|
-
|
|
13
|
-
jobs:
|
|
14
|
-
doc-completion:
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v3
|
|
18
|
-
with:
|
|
19
|
-
fetch-depth: 2
|
|
20
|
-
|
|
21
|
-
- name: Setup Node.js
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
with:
|
|
24
|
-
node-version: '22'
|
|
25
|
-
|
|
26
|
-
- name: Install Dependencies
|
|
27
|
-
run: npm install @google/genai --no-save
|
|
28
|
-
|
|
29
|
-
- name: Run AI Doc Sync
|
|
30
|
-
env:
|
|
31
|
-
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
|
32
|
-
run: node .github/scripts/doc-sync.mjs
|
|
33
|
-
|
|
34
|
-
- name: Create Pull Request
|
|
35
|
-
uses: peter-evans/create-pull-request@v5
|
|
36
|
-
with:
|
|
37
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
|
38
|
-
commit-message: "docs: auto-generated documentation updates"
|
|
39
|
-
title: "docs: AI-generated documentation updates"
|
|
40
|
-
body: |
|
|
41
|
-
Automatic documentation updates generated by AI based on recent code changes.
|
|
42
|
-
|
|
43
|
-
Please review and merge if accurate.
|
|
44
|
-
branch: ai-docs/${{ github.ref_name }}
|
|
45
|
-
base: ${{ github.head_ref || github.ref_name }}
|
|
46
|
-
delete-branch: true
|
|
47
|
-
add-paths: .docs
|
package/mkdocs.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
site_name: test Documentation
|
|
2
|
-
docs_dir: .docs
|
|
3
|
-
theme: readthedocs
|
|
4
|
-
|
|
5
|
-
nav:
|
|
6
|
-
- Home: index.md
|
|
7
|
-
- Getting Started: getting-started.md
|
|
8
|
-
- Architecture: architecture.md
|
|
9
|
-
- Reference:
|
|
10
|
-
- Components: reference/components.md
|
|
11
|
-
- Composables: reference/composables.md
|
|
12
|
-
- Server-routes: reference/server-routes.md
|