skrypt-ai 0.7.0 → 0.8.0
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/auth/index.js +3 -3
- package/dist/cli.js +1 -1
- package/dist/commands/cron.js +0 -4
- package/dist/commands/generate/index.d.ts +3 -0
- package/dist/commands/generate/index.js +393 -0
- package/dist/commands/generate/scan.d.ts +41 -0
- package/dist/commands/generate/scan.js +256 -0
- package/dist/commands/generate/verify.d.ts +14 -0
- package/dist/commands/generate/verify.js +122 -0
- package/dist/commands/generate/write.d.ts +25 -0
- package/dist/commands/generate/write.js +120 -0
- package/dist/commands/import.js +4 -1
- package/dist/commands/llms-txt.js +6 -4
- package/dist/config/loader.d.ts +0 -1
- package/dist/config/loader.js +1 -1
- package/dist/generator/agents-md.d.ts +25 -0
- package/dist/generator/agents-md.js +122 -0
- package/dist/generator/index.d.ts +2 -0
- package/dist/generator/index.js +2 -0
- package/dist/generator/mdx-serializer.d.ts +11 -0
- package/dist/generator/mdx-serializer.js +135 -0
- package/dist/generator/organizer.d.ts +1 -16
- package/dist/generator/organizer.js +0 -38
- package/dist/generator/writer.js +5 -4
- package/dist/llm/proxy-client.d.ts +32 -0
- package/dist/llm/proxy-client.js +103 -0
- package/dist/scanner/csharp.d.ts +0 -4
- package/dist/scanner/csharp.js +9 -49
- package/dist/scanner/go.d.ts +0 -3
- package/dist/scanner/go.js +8 -35
- package/dist/scanner/java.d.ts +0 -4
- package/dist/scanner/java.js +9 -49
- package/dist/scanner/kotlin.d.ts +0 -3
- package/dist/scanner/kotlin.js +6 -33
- package/dist/scanner/php.d.ts +0 -10
- package/dist/scanner/php.js +11 -55
- package/dist/scanner/ruby.d.ts +0 -3
- package/dist/scanner/ruby.js +8 -38
- package/dist/scanner/rust.d.ts +0 -3
- package/dist/scanner/rust.js +10 -37
- package/dist/scanner/swift.d.ts +0 -3
- package/dist/scanner/swift.js +8 -35
- package/dist/scanner/utils.d.ts +41 -0
- package/dist/scanner/utils.js +97 -0
- package/dist/template/docs.json +5 -2
- package/dist/template/next.config.mjs +31 -0
- package/dist/template/package.json +5 -3
- package/dist/template/src/app/layout.tsx +13 -13
- package/dist/template/src/app/llms-full.md/route.ts +29 -0
- package/dist/template/src/app/llms.txt/route.ts +29 -0
- package/dist/template/src/app/md/[...slug]/route.ts +174 -0
- package/dist/template/src/app/reference/route.ts +22 -18
- package/dist/template/src/app/sitemap.ts +1 -1
- package/dist/template/src/components/ai-chat-impl.tsx +206 -0
- package/dist/template/src/components/ai-chat.tsx +20 -193
- package/dist/template/src/components/mdx/index.tsx +27 -4
- package/dist/template/src/lib/fonts.ts +135 -0
- package/dist/template/src/middleware.ts +101 -0
- package/dist/template/src/styles/globals.css +28 -20
- package/dist/utils/files.d.ts +0 -8
- package/dist/utils/files.js +0 -33
- package/package.json +1 -1
- package/dist/autofix/autofix.test.d.ts +0 -1
- package/dist/autofix/autofix.test.js +0 -487
- package/dist/commands/generate.d.ts +0 -9
- package/dist/commands/generate.js +0 -739
- package/dist/generator/generator.test.d.ts +0 -1
- package/dist/generator/generator.test.js +0 -259
- package/dist/generator/writer.test.d.ts +0 -1
- package/dist/generator/writer.test.js +0 -411
- package/dist/llm/llm.manual-test.d.ts +0 -1
- package/dist/llm/llm.manual-test.js +0 -112
- package/dist/llm/llm.mock-test.d.ts +0 -4
- package/dist/llm/llm.mock-test.js +0 -79
- package/dist/plugins/index.d.ts +0 -47
- package/dist/plugins/index.js +0 -181
- package/dist/scanner/content-type.test.d.ts +0 -1
- package/dist/scanner/content-type.test.js +0 -231
- package/dist/scanner/integration.test.d.ts +0 -4
- package/dist/scanner/integration.test.js +0 -180
- package/dist/scanner/scanner.test.d.ts +0 -1
- package/dist/scanner/scanner.test.js +0 -210
- package/dist/scanner/typescript.manual-test.d.ts +0 -1
- package/dist/scanner/typescript.manual-test.js +0 -112
- package/dist/template/src/app/docs/auth/page.mdx +0 -589
- package/dist/template/src/app/docs/autofix/page.mdx +0 -624
- package/dist/template/src/app/docs/cli/page.mdx +0 -217
- package/dist/template/src/app/docs/config/page.mdx +0 -428
- package/dist/template/src/app/docs/configuration/page.mdx +0 -86
- package/dist/template/src/app/docs/deployment/page.mdx +0 -112
- package/dist/template/src/app/docs/generator/generator.md +0 -504
- package/dist/template/src/app/docs/generator/organizer.md +0 -779
- package/dist/template/src/app/docs/generator/page.mdx +0 -613
- package/dist/template/src/app/docs/github/page.mdx +0 -502
- package/dist/template/src/app/docs/llm/anthropic-client.md +0 -549
- package/dist/template/src/app/docs/llm/index.md +0 -471
- package/dist/template/src/app/docs/llm/page.mdx +0 -428
- package/dist/template/src/app/docs/plugins/page.mdx +0 -1793
- package/dist/template/src/app/docs/pro/page.mdx +0 -121
- package/dist/template/src/app/docs/quickstart/page.mdx +0 -93
- package/dist/template/src/app/docs/scanner/content-type.md +0 -599
- package/dist/template/src/app/docs/scanner/index.md +0 -212
- package/dist/template/src/app/docs/scanner/page.mdx +0 -307
- package/dist/template/src/app/docs/scanner/python.md +0 -469
- package/dist/template/src/app/docs/scanner/python_parser.md +0 -1056
- package/dist/template/src/app/docs/scanner/rust.md +0 -325
- package/dist/template/src/app/docs/scanner/typescript.md +0 -201
- package/dist/template/src/app/icon.tsx +0 -29
- package/dist/utils/validation.d.ts +0 -1
- package/dist/utils/validation.js +0 -12
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
# Rust.ts
|
|
2
|
-
|
|
3
|
-
## Classes
|
|
4
|
-
|
|
5
|
-
### `RustScanner`
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
class RustScanner implements Scanner
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Use this to scan Rust source files and extract public API elements — functions, structs, enums, impl blocks, and traits — for automated documentation generation.
|
|
12
|
-
|
|
13
|
-
`RustScanner` implements the `Scanner` interface and targets `.rs` files, automatically skipping test files in `/tests/` directories.
|
|
14
|
-
|
|
15
|
-
## Methods
|
|
16
|
-
|
|
17
|
-
### `canHandle(filePath: string): boolean`
|
|
18
|
-
Determines whether this scanner should process a given file.
|
|
19
|
-
|
|
20
|
-
| Name | Type | Required | Description |
|
|
21
|
-
|------|------|----------|-------------|
|
|
22
|
-
| `filePath` | `string` | ✅ | Path to the file to check |
|
|
23
|
-
|
|
24
|
-
**Returns:** `true` if the file ends in `.rs` and is not inside a `/tests/` directory, `false` otherwise.
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
### `scanFile(filePath: string): Promise<ScanResult>`
|
|
29
|
-
Reads and parses a Rust source file, extracting all public API elements.
|
|
30
|
-
|
|
31
|
-
| Name | Type | Required | Description |
|
|
32
|
-
|------|------|----------|-------------|
|
|
33
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the `.rs` file to scan |
|
|
34
|
-
|
|
35
|
-
**Returns:** A `Promise<ScanResult>` containing:
|
|
36
|
-
- `elements` — Array of `APIElement` objects, each representing a discovered `pub fn`, `pub struct`, `pub enum`, `impl` block, or `trait`
|
|
37
|
-
- `filePath` — The original file path that was scanned
|
|
38
|
-
- `language` — `"rust"`
|
|
39
|
-
|
|
40
|
-
**Throws:** If the file cannot be read (e.g. missing permissions or path not found), the promise resolves with an empty elements array rather than rejecting.
|
|
41
|
-
|
|
42
|
-
## Properties
|
|
43
|
-
|
|
44
|
-
| Name | Type | Description |
|
|
45
|
-
|------|------|-------------|
|
|
46
|
-
| `languages` | `string[]` | Always `['rust']` — used by scanner registries to route files |
|
|
47
|
-
|
|
48
|
-
## Notes
|
|
49
|
-
- Test files (paths containing `/tests/`) are explicitly excluded via `canHandle`
|
|
50
|
-
- Only **public** (`pub`) items are extracted — private implementation details are ignored
|
|
51
|
-
- Useful as part of a multi-language documentation pipeline alongside scanners for TypeScript, Python, etc.
|
|
52
|
-
|
|
53
|
-
### Methods
|
|
54
|
-
|
|
55
|
-
#### `canHandle`
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
canHandle(filePath: string): boolean
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Use this to quickly determine whether a given file path should be processed by the Rust scanner before committing to a full file scan.
|
|
62
|
-
|
|
63
|
-
`canHandle` returns `true` only when **both** conditions are met:
|
|
64
|
-
- The file path ends with `.rs`
|
|
65
|
-
- The file path does **not** contain `/tests/`
|
|
66
|
-
|
|
67
|
-
This acts as a fast pre-flight check, letting you skip incompatible files without reading them from disk.
|
|
68
|
-
|
|
69
|
-
### Parameters
|
|
70
|
-
|
|
71
|
-
| Name | Type | Required | Description |
|
|
72
|
-
|------|------|----------|-------------|
|
|
73
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the file being evaluated |
|
|
74
|
-
|
|
75
|
-
### Returns
|
|
76
|
-
|
|
77
|
-
| Value | Condition |
|
|
78
|
-
|-------|-----------|
|
|
79
|
-
| `true` | File ends in `.rs` **and** path does not include `/tests/` |
|
|
80
|
-
| `false` | File is not a `.rs` file, or lives inside a `/tests/` directory |
|
|
81
|
-
|
|
82
|
-
**Example:**
|
|
83
|
-
|
|
84
|
-
```typescript example.ts
|
|
85
|
-
// Inline implementation matching RustScanner.canHandle behavior
|
|
86
|
-
class RustScanner {
|
|
87
|
-
languages = ['rust']
|
|
88
|
-
|
|
89
|
-
canHandle(filePath: string): boolean {
|
|
90
|
-
return /\.rs$/.test(filePath) && !filePath.includes('/tests/')
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const scanner = new RustScanner()
|
|
95
|
-
|
|
96
|
-
const filePaths = [
|
|
97
|
-
'src/main.rs', // ✅ valid Rust source
|
|
98
|
-
'src/lib.rs', // ✅ valid Rust source
|
|
99
|
-
'src/models/user.rs', // ✅ valid Rust source
|
|
100
|
-
'src/tests/integration.rs', // ❌ inside /tests/ directory
|
|
101
|
-
'src/handlers/auth.ts', // ❌ not a .rs file
|
|
102
|
-
'README.md', // ❌ not a .rs file
|
|
103
|
-
'/home/user/project/tests/utils.rs', // ❌ inside /tests/ directory
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
console.log('RustScanner.canHandle() results:\n')
|
|
108
|
-
|
|
109
|
-
for (const filePath of filePaths) {
|
|
110
|
-
const result = scanner.canHandle(filePath)
|
|
111
|
-
const status = result ? '✅ WILL scan' : '❌ SKIP'
|
|
112
|
-
console.log(` ${status} ${filePath}`)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Practical usage: filter a list of files before scanning
|
|
116
|
-
const scannable = filePaths.filter(fp => scanner.canHandle(fp))
|
|
117
|
-
console.log(`\nFiles queued for scanning: ${scannable.length}/${filePaths.length}`)
|
|
118
|
-
console.log(scannable)
|
|
119
|
-
|
|
120
|
-
// Expected output:
|
|
121
|
-
// ✅ WILL scan src/main.rs
|
|
122
|
-
// ✅ WILL scan src/lib.rs
|
|
123
|
-
// ✅ WILL scan src/models/user.rs
|
|
124
|
-
// ❌ SKIP src/tests/integration.rs
|
|
125
|
-
// ❌ SKIP src/handlers/auth.ts
|
|
126
|
-
// ❌ SKIP README.md
|
|
127
|
-
// ❌ SKIP /home/user/project/tests/utils.rs
|
|
128
|
-
// Files queued for scanning: 3/7
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error('Unexpected error during file filtering:', error)
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
#### `scanFile`
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
async scanFile(filePath: string): Promise<ScanResult>
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Use this to extract API elements from a Rust source file, parsing its contents into a structured result containing discovered elements and any errors encountered during scanning.
|
|
141
|
-
|
|
142
|
-
Handles `.rs` files outside of test directories (`/tests/`). Reads the file synchronously and returns a promise resolving to a structured scan result.
|
|
143
|
-
|
|
144
|
-
## Parameters
|
|
145
|
-
|
|
146
|
-
| Name | Type | Required | Description |
|
|
147
|
-
|------|------|----------|-------------|
|
|
148
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the `.rs` file to scan. Must not be inside a `/tests/` directory. |
|
|
149
|
-
|
|
150
|
-
## Returns
|
|
151
|
-
|
|
152
|
-
Returns `Promise<ScanResult>` with the following shape:
|
|
153
|
-
|
|
154
|
-
| Field | Type | Description |
|
|
155
|
-
|-------|------|-------------|
|
|
156
|
-
| `elements` | `APIElement[]` | Parsed API elements (functions, structs, enums, etc.) found in the file |
|
|
157
|
-
| `errors` | `string[]` | Non-fatal parsing errors encountered during the scan |
|
|
158
|
-
|
|
159
|
-
Rejects with an error if the file cannot be read (e.g., file not found, permission denied).
|
|
160
|
-
|
|
161
|
-
## Notes
|
|
162
|
-
- Use `canHandle(filePath)` first to verify the file is eligible before calling `scanFile`
|
|
163
|
-
- Files matching `/tests/` in their path are intentionally excluded — scanning them will produce no results or unexpected behavior
|
|
164
|
-
|
|
165
|
-
**Example:**
|
|
166
|
-
|
|
167
|
-
```typescript example.ts
|
|
168
|
-
import { readFileSync } from 'fs'
|
|
169
|
-
import { writeFileSync, mkdirSync } from 'fs'
|
|
170
|
-
import { join } from 'path'
|
|
171
|
-
import { tmpdir } from 'os'
|
|
172
|
-
|
|
173
|
-
// --- Inline types (mirrors the real library's types) ---
|
|
174
|
-
interface Parameter {
|
|
175
|
-
name: string
|
|
176
|
-
type: string
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
interface APIElement {
|
|
180
|
-
name: string
|
|
181
|
-
kind: 'function' | 'struct' | 'enum' | 'trait'
|
|
182
|
-
parameters?: Parameter[]
|
|
183
|
-
isPublic: boolean
|
|
184
|
-
lineNumber: number
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
interface ScanResult {
|
|
188
|
-
elements: APIElement[]
|
|
189
|
-
errors: string[]
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// --- Inline RustScanner implementation (mirrors real behavior) ---
|
|
193
|
-
class RustScanner {
|
|
194
|
-
canHandle(filePath: string): boolean {
|
|
195
|
-
return /\.rs$/.test(filePath) && !filePath.includes('/tests/')
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async scanFile(filePath: string): Promise<ScanResult> {
|
|
199
|
-
const source = readFileSync(filePath, 'utf-8')
|
|
200
|
-
const elements: APIElement[] = []
|
|
201
|
-
const errors: string[] = []
|
|
202
|
-
const lines = source.split('\n')
|
|
203
|
-
|
|
204
|
-
const fnRegex = /^(pub\s+)?fn\s+(\w+)\s*\(([^)]*)\)/
|
|
205
|
-
const structRegex = /^(pub\s+)?struct\s+(\w+)/
|
|
206
|
-
const enumRegex = /^(pub\s+)?enum\s+(\w+)/
|
|
207
|
-
const traitRegex = /^(pub\s+)?trait\s+(\w+)/
|
|
208
|
-
|
|
209
|
-
lines.forEach((line, index) => {
|
|
210
|
-
const trimmed = line.trim()
|
|
211
|
-
|
|
212
|
-
const fnMatch = trimmed.match(fnRegex)
|
|
213
|
-
if (fnMatch) {
|
|
214
|
-
const rawParams = fnMatch[3].split(',').map(p => p.trim()).filter(Boolean)
|
|
215
|
-
const parameters: Parameter[] = rawParams.map(p => {
|
|
216
|
-
const [name, type] = p.split(':').map(s => s.trim())
|
|
217
|
-
return { name: name || 'unknown', type: type || 'unknown' }
|
|
218
|
-
})
|
|
219
|
-
elements.push({
|
|
220
|
-
name: fnMatch[2],
|
|
221
|
-
kind: 'function',
|
|
222
|
-
parameters,
|
|
223
|
-
isPublic: !!fnMatch[1],
|
|
224
|
-
lineNumber: index + 1,
|
|
225
|
-
})
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const structMatch = trimmed.match(structRegex)
|
|
230
|
-
if (structMatch) {
|
|
231
|
-
elements.push({ name: structMatch[2], kind: 'struct', isPublic: !!structMatch[1], lineNumber: index + 1 })
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const enumMatch = trimmed.match(enumRegex)
|
|
236
|
-
if (enumMatch) {
|
|
237
|
-
elements.push({ name: enumMatch[2], kind: 'enum', isPublic: !!enumMatch[1], lineNumber: index + 1 })
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const traitMatch = trimmed.match(traitRegex)
|
|
242
|
-
if (traitMatch) {
|
|
243
|
-
elements.push({ name: traitMatch[2], kind: 'trait', isPublic: !!traitMatch[1], lineNumber: index + 1 })
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
return { elements, errors }
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// --- Create a temporary .rs file to scan ---
|
|
252
|
-
const tmpDir = tmpdir()
|
|
253
|
-
const sampleRustFile = join(tmpDir, 'sample_lib.rs')
|
|
254
|
-
|
|
255
|
-
writeFileSync(sampleRustFile, `
|
|
256
|
-
pub struct UserProfile {
|
|
257
|
-
pub id: u64,
|
|
258
|
-
pub name: String,
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
pub enum Status {
|
|
262
|
-
Active,
|
|
263
|
-
Inactive,
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
pub trait Describable {
|
|
267
|
-
fn describe(&self) -> String;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
pub fn create_user(id: u64, name: String) -> UserProfile {
|
|
271
|
-
UserProfile { id, name }
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
fn internal_helper(value: u32) -> bool {
|
|
275
|
-
value > 0
|
|
276
|
-
}
|
|
277
|
-
`.trim())
|
|
278
|
-
|
|
279
|
-
// --- Run the scanner ---
|
|
280
|
-
async function main() {
|
|
281
|
-
const scanner = new RustScanner()
|
|
282
|
-
const targetFile = process.env.RUST_FILE_PATH || sampleRustFile
|
|
283
|
-
|
|
284
|
-
if (!scanner.canHandle(targetFile)) {
|
|
285
|
-
console.error(`Cannot handle file: ${targetFile} (must be a .rs file outside /tests/)`)
|
|
286
|
-
process.exit(1)
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
const result: ScanResult = await scanner.scanFile(targetFile)
|
|
291
|
-
|
|
292
|
-
console.log(`Scanned: ${targetFile}`)
|
|
293
|
-
console.log(`Found ${result.elements.length} API elements:\n`)
|
|
294
|
-
|
|
295
|
-
result.elements.forEach(el => {
|
|
296
|
-
const visibility = el.isPublic ? 'pub' : 'private'
|
|
297
|
-
const params = el.parameters?.map(p => `${p.name}: ${p.type}`).join(', ') ?? ''
|
|
298
|
-
const detail = el.kind === 'function' ? ` (${params})` : ''
|
|
299
|
-
console.log(` [${el.kind.padEnd(8)}] ${visibility.padEnd(7)} ${el.name}${detail} — line ${el.lineNumber}`)
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
if (result.errors.length > 0) {
|
|
303
|
-
console.warn('\nErrors encountered:')
|
|
304
|
-
result.errors.forEach(e => console.warn(` ⚠ ${e}`))
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Expected output:
|
|
308
|
-
// Scanned: /tmp/sample_lib.rs
|
|
309
|
-
// Found 5 API elements:
|
|
310
|
-
//
|
|
311
|
-
// [struct ] pub UserProfile — line 1
|
|
312
|
-
// [enum ] pub Status — line 6
|
|
313
|
-
// [trait ] pub Describable — line 11
|
|
314
|
-
// [function] pub create_user (id: u64, name: String) — line 15
|
|
315
|
-
// [function] private internal_helper (value: u32) — line 19
|
|
316
|
-
|
|
317
|
-
} catch (error) {
|
|
318
|
-
console.error('Failed to scan file:', error instanceof Error ? error.message : error)
|
|
319
|
-
process.exit(1)
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
main()
|
|
324
|
-
```
|
|
325
|
-
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# Typescript.ts
|
|
2
|
-
|
|
3
|
-
## Classes
|
|
4
|
-
|
|
5
|
-
### `TypeScriptScanner`
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
class TypeScriptScanner implements Scanner
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Use this to scan TypeScript and JavaScript source files and extract API elements (functions, classes, parameters, and signatures) for automatic documentation generation.
|
|
12
|
-
|
|
13
|
-
`TypeScriptScanner` implements the `Scanner` interface and handles `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, and `.cjs` files. It skips declaration files (`.d.ts`) automatically.
|
|
14
|
-
|
|
15
|
-
## Properties
|
|
16
|
-
|
|
17
|
-
| Property | Type | Description |
|
|
18
|
-
|---|---|---|
|
|
19
|
-
| `languages` | `string[]` | Always `['typescript', 'javascript']` — the languages this scanner supports |
|
|
20
|
-
|
|
21
|
-
## Methods
|
|
22
|
-
|
|
23
|
-
### `canHandle(filePath)`
|
|
24
|
-
|
|
25
|
-
Use this to check whether a given file path is supported before scanning.
|
|
26
|
-
|
|
27
|
-
| Name | Type | Required | Description |
|
|
28
|
-
|---|---|---|---|
|
|
29
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the source file |
|
|
30
|
-
|
|
31
|
-
**Returns:** `boolean` — `true` if the file extension matches `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, or `.cjs` AND the path does not contain `.d.ts`.
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
### `scanFile(filePath)`
|
|
36
|
-
|
|
37
|
-
Use this to extract all API elements from a source file — classes, functions, parameters, return types, and JSDoc comments.
|
|
38
|
-
|
|
39
|
-
| Name | Type | Required | Description |
|
|
40
|
-
|---|---|---|---|
|
|
41
|
-
| `filePath` | `string` | ✅ | Path to the source file to scan. File must exist and be readable. |
|
|
42
|
-
|
|
43
|
-
**Returns:** `Promise<ScanResult>` — resolves with an object containing:
|
|
44
|
-
|
|
45
|
-
| Field | Type | Description |
|
|
46
|
-
|---|---|---|
|
|
47
|
-
| `filePath` | `string` | The scanned file path |
|
|
48
|
-
| `language` | `string` | Either `'typescript'` or `'javascript'` |
|
|
49
|
-
| `elements` | `APIElement[]` | Extracted API elements (functions, classes, etc.) |
|
|
50
|
-
| `errors` | `string[]` | Any non-fatal parse errors encountered |
|
|
51
|
-
|
|
52
|
-
**Throws:** If the file cannot be read from disk.
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## Notes
|
|
57
|
-
|
|
58
|
-
- Declaration files (`.d.ts`) are explicitly excluded — `canHandle()` returns `false` for them.
|
|
59
|
-
- Language is inferred from the file extension: `.ts`/`.tsx` → `'typescript'`, everything else → `'javascript'`.
|
|
60
|
-
- Use `canHandle()` as a guard before calling `scanFile()` to avoid unsupported file errors.
|
|
61
|
-
|
|
62
|
-
### Methods
|
|
63
|
-
|
|
64
|
-
#### `canHandle`
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
canHandle(filePath: string): boolean
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Use this to quickly check whether a file path is a TypeScript/JavaScript source file that the scanner can process — filtering out declaration files (`.d.ts`) automatically.
|
|
71
|
-
|
|
72
|
-
Returns `true` for `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, and `.cjs` files. Returns `false` for `.d.ts` declaration files and any other file types.
|
|
73
|
-
|
|
74
|
-
### Parameters
|
|
75
|
-
|
|
76
|
-
| Name | Type | Required | Description |
|
|
77
|
-
|------|------|----------|-------------|
|
|
78
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the file being evaluated |
|
|
79
|
-
|
|
80
|
-
### Returns
|
|
81
|
-
|
|
82
|
-
| Value | Condition |
|
|
83
|
-
|-------|-----------|
|
|
84
|
-
| `true` | File extension is `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, or `.cjs` **and** path does not contain `.d.ts` |
|
|
85
|
-
| `false` | File is a declaration file (`.d.ts`), or has an unsupported extension (e.g. `.py`, `.json`, `.css`) |
|
|
86
|
-
|
|
87
|
-
### Notes
|
|
88
|
-
- Declaration files (`.d.ts`) are explicitly excluded even though they end in `.ts`
|
|
89
|
-
- Works with both absolute paths (`/src/utils.ts`) and relative paths (`./lib/index.js`)
|
|
90
|
-
- Does not check whether the file actually exists on disk
|
|
91
|
-
|
|
92
|
-
**Example:**
|
|
93
|
-
|
|
94
|
-
```typescript example.ts
|
|
95
|
-
// Inline implementation matching TypeScriptScanner.canHandle behavior
|
|
96
|
-
class TypeScriptScanner {
|
|
97
|
-
languages = ['typescript', 'javascript']
|
|
98
|
-
|
|
99
|
-
canHandle(filePath: string): boolean {
|
|
100
|
-
return /\.(ts|tsx|js|jsx|mjs|cjs)$/.test(filePath) && !filePath.includes('.d.ts')
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const scanner = new TypeScriptScanner()
|
|
105
|
-
|
|
106
|
-
const testFiles = [
|
|
107
|
-
// Expected: true
|
|
108
|
-
'/project/src/index.ts',
|
|
109
|
-
'./components/Button.tsx',
|
|
110
|
-
'lib/utils.js',
|
|
111
|
-
'app/routes.jsx',
|
|
112
|
-
'server/loader.mjs',
|
|
113
|
-
'legacy/module.cjs',
|
|
114
|
-
|
|
115
|
-
// Expected: false
|
|
116
|
-
'/project/dist/index.d.ts', // declaration file — excluded
|
|
117
|
-
'styles/main.css', // wrong extension
|
|
118
|
-
'config/settings.json', // wrong extension
|
|
119
|
-
'README.md', // wrong extension
|
|
120
|
-
'script.py', // wrong extension
|
|
121
|
-
]
|
|
122
|
-
|
|
123
|
-
console.log('File compatibility check:\n')
|
|
124
|
-
|
|
125
|
-
for (const filePath of testFiles) {
|
|
126
|
-
const supported = scanner.canHandle(filePath)
|
|
127
|
-
const icon = supported ? '✅' : '❌'
|
|
128
|
-
console.log(`${icon} ${filePath}`)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Expected output:
|
|
132
|
-
// ✅ /project/src/index.ts
|
|
133
|
-
// ✅ ./components/Button.tsx
|
|
134
|
-
// ✅ lib/utils.js
|
|
135
|
-
// ✅ app/routes.jsx
|
|
136
|
-
// ✅ server/loader.mjs
|
|
137
|
-
// ✅ legacy/module.cjs
|
|
138
|
-
// ❌ /project/dist/index.d.ts
|
|
139
|
-
// ❌ styles/main.css
|
|
140
|
-
// ❌ config/settings.json
|
|
141
|
-
// ❌ README.md
|
|
142
|
-
// ❌ script.py
|
|
143
|
-
|
|
144
|
-
// Practical usage: filter a list of discovered files before scanning
|
|
145
|
-
const discoveredFiles = [
|
|
146
|
-
'src/api.ts',
|
|
147
|
-
'src/api.d.ts',
|
|
148
|
-
'src/helpers.js',
|
|
149
|
-
'src/styles.css',
|
|
150
|
-
]
|
|
151
|
-
|
|
152
|
-
const scannable = discoveredFiles.filter(f => scanner.canHandle(f))
|
|
153
|
-
console.log('\nFiles queued for scanning:', scannable)
|
|
154
|
-
// Output: [ 'src/api.ts', 'src/helpers.js' ]
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
#### `scanFile`
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
async scanFile(filePath: string): Promise<ScanResult>
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Use this to extract API elements (functions, classes, interfaces, types) from a TypeScript or JavaScript source file, returning structured metadata about each discovered element.
|
|
164
|
-
|
|
165
|
-
`scanFile` analyzes a `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, or `.cjs` file and produces a `ScanResult` containing all documented API surface — parameters, return types, visibility, and more. Use it as the core step in building documentation pipelines, API audits, or code analysis tools.
|
|
166
|
-
|
|
167
|
-
> **Note:** Declaration files (`.d.ts`) are not supported and will be rejected by the scanner.
|
|
168
|
-
|
|
169
|
-
## Parameters
|
|
170
|
-
|
|
171
|
-
| Name | Type | Required | Description |
|
|
172
|
-
|------|------|----------|-------------|
|
|
173
|
-
| `filePath` | `string` | ✅ | Absolute or relative path to the source file to scan. Must match `*.ts`, `*.tsx`, `*.js`, `*.jsx`, `*.mjs`, or `*.cjs`. |
|
|
174
|
-
|
|
175
|
-
## Returns
|
|
176
|
-
|
|
177
|
-
Returns `Promise<ScanResult>` — resolves with a structured object describing all API elements found in the file.
|
|
178
|
-
|
|
179
|
-
| Field | Type | Description |
|
|
180
|
-
|-------|------|-------------|
|
|
181
|
-
| `filePath` | `string` | The path of the scanned file |
|
|
182
|
-
| `language` | `'typescript' \| 'javascript'` | Detected language based on file extension |
|
|
183
|
-
| `elements` | `APIElement[]` | All discovered functions, classes, interfaces, and types |
|
|
184
|
-
| `errors` | `string[]` | Any parse or scan errors encountered |
|
|
185
|
-
|
|
186
|
-
### `APIElement` shape
|
|
187
|
-
|
|
188
|
-
| Field | Type | Description |
|
|
189
|
-
|-------|------|-------------|
|
|
190
|
-
| `name` | `string` | Identifier name |
|
|
191
|
-
| `kind` | `'function' \| 'class' \| 'interface' \| 'type'` | Element category |
|
|
192
|
-
| `parameters` | `Parameter[]` | List of parameters with name and type |
|
|
193
|
-
| `returnType` | `string` | Inferred or declared return type |
|
|
194
|
-
| `isExported` | `boolean` | Whether the element is publicly exported |
|
|
195
|
-
| `jsDoc` | `string \| undefined` | Extracted JSDoc comment, if present |
|
|
196
|
-
|
|
197
|
-
## When It Resolves vs. Rejects
|
|
198
|
-
|
|
199
|
-
- **Resolves** with a `ScanResult` for any supported file, even if parsing produces warnings (errors are captured in `result.errors`)
|
|
200
|
-
- **Rejects** if the file cannot be read (e.g., file not found, permission denied)
|
|
201
|
-
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ImageResponse } from 'next/og'
|
|
2
|
-
|
|
3
|
-
export const size = { width: 32, height: 32 }
|
|
4
|
-
export const contentType = 'image/png'
|
|
5
|
-
|
|
6
|
-
export default function Icon() {
|
|
7
|
-
return new ImageResponse(
|
|
8
|
-
(
|
|
9
|
-
<div
|
|
10
|
-
style={{
|
|
11
|
-
width: 32,
|
|
12
|
-
height: 32,
|
|
13
|
-
borderRadius: 6,
|
|
14
|
-
background: '#3b82f6',
|
|
15
|
-
display: 'flex',
|
|
16
|
-
alignItems: 'center',
|
|
17
|
-
justifyContent: 'center',
|
|
18
|
-
color: 'white',
|
|
19
|
-
fontSize: 20,
|
|
20
|
-
fontWeight: 700,
|
|
21
|
-
fontFamily: 'system-ui, -apple-system, sans-serif',
|
|
22
|
-
}}
|
|
23
|
-
>
|
|
24
|
-
S
|
|
25
|
-
</div>
|
|
26
|
-
),
|
|
27
|
-
{ ...size }
|
|
28
|
-
)
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function validateUrl(input: string): string;
|
package/dist/utils/validation.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function validateUrl(input) {
|
|
2
|
-
try {
|
|
3
|
-
const url = new URL(input);
|
|
4
|
-
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
5
|
-
throw new Error(`Invalid protocol: ${url.protocol}`);
|
|
6
|
-
}
|
|
7
|
-
return url.toString();
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
throw new Error(`Invalid URL: ${input}`);
|
|
11
|
-
}
|
|
12
|
-
}
|