@bfra.me/doc-sync 0.1.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.
Files changed (50) hide show
  1. package/README.md +288 -0
  2. package/lib/chunk-6NKAJT2M.js +1233 -0
  3. package/lib/chunk-DR6UG237.js +1027 -0
  4. package/lib/chunk-G5KKGJYO.js +1560 -0
  5. package/lib/chunk-ROLA7SBB.js +12 -0
  6. package/lib/cli/index.d.ts +1 -0
  7. package/lib/cli/index.js +397 -0
  8. package/lib/generators/index.d.ts +170 -0
  9. package/lib/generators/index.js +76 -0
  10. package/lib/index.d.ts +141 -0
  11. package/lib/index.js +118 -0
  12. package/lib/parsers/index.d.ts +264 -0
  13. package/lib/parsers/index.js +113 -0
  14. package/lib/types.d.ts +388 -0
  15. package/lib/types.js +7 -0
  16. package/package.json +99 -0
  17. package/src/cli/commands/index.ts +3 -0
  18. package/src/cli/commands/sync.ts +146 -0
  19. package/src/cli/commands/validate.ts +151 -0
  20. package/src/cli/commands/watch.ts +74 -0
  21. package/src/cli/index.ts +71 -0
  22. package/src/cli/types.ts +19 -0
  23. package/src/cli/ui.ts +123 -0
  24. package/src/generators/api-reference-generator.ts +268 -0
  25. package/src/generators/code-example-formatter.ts +313 -0
  26. package/src/generators/component-mapper.ts +383 -0
  27. package/src/generators/content-merger.ts +295 -0
  28. package/src/generators/frontmatter-generator.ts +277 -0
  29. package/src/generators/index.ts +56 -0
  30. package/src/generators/mdx-generator.ts +289 -0
  31. package/src/index.ts +131 -0
  32. package/src/orchestrator/index.ts +21 -0
  33. package/src/orchestrator/package-scanner.ts +276 -0
  34. package/src/orchestrator/sync-orchestrator.ts +382 -0
  35. package/src/orchestrator/validation-pipeline.ts +328 -0
  36. package/src/parsers/export-analyzer.ts +335 -0
  37. package/src/parsers/guards.ts +350 -0
  38. package/src/parsers/index.ts +82 -0
  39. package/src/parsers/jsdoc-extractor.ts +313 -0
  40. package/src/parsers/package-info.ts +267 -0
  41. package/src/parsers/readme-parser.ts +334 -0
  42. package/src/parsers/typescript-parser.ts +299 -0
  43. package/src/types.ts +423 -0
  44. package/src/utils/index.ts +13 -0
  45. package/src/utils/safe-patterns.ts +280 -0
  46. package/src/utils/sanitization.ts +164 -0
  47. package/src/watcher/change-detector.ts +138 -0
  48. package/src/watcher/debouncer.ts +168 -0
  49. package/src/watcher/file-watcher.ts +164 -0
  50. package/src/watcher/index.ts +27 -0
package/README.md ADDED
@@ -0,0 +1,288 @@
1
+ # @bfra.me/doc-sync
2
+
3
+ > Intelligent documentation synchronization engine for automatic Astro Starlight site updates
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@bfra.me/doc-sync.svg)](https://www.npmjs.com/package/@bfra.me/doc-sync) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ ## Overview
8
+
9
+ `@bfra.me/doc-sync` monitors package source code, README files, and JSDoc comments to automatically update Astro Starlight documentation sites with zero manual intervention. It bridges the gap between your codebase and documentation, ensuring they stay in sync.
10
+
11
+ ## Features
12
+
13
+ - 📝 **TypeScript/JSDoc Parsing** — Extracts documentation from source files using the TypeScript Compiler API via `ts-morph`
14
+ - 📖 **README Integration** — Parses and incorporates README content into documentation pages
15
+ - 🔄 **Incremental Updates** — Only regenerates documentation for changed packages using content hashing
16
+ - 👁️ **Watch Mode** — Monitors for changes and syncs automatically during development
17
+ - ✨ **MDX Generation** — Creates Starlight-compatible MDX files with proper frontmatter
18
+ - 🛡️ **Content Preservation** — Protects manual content sections using sentinel markers
19
+ - 🎨 **Modern CLI** — Interactive terminal UI powered by `@clack/prompts`
20
+ - 🔒 **Security** — Sanitizes content to prevent XSS and validates file paths
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pnpm add @bfra.me/doc-sync
26
+ ```
27
+
28
+ ## CLI Usage
29
+
30
+ The `doc-sync` CLI provides three main commands for managing documentation synchronization.
31
+
32
+ ### Sync Command
33
+
34
+ Synchronize documentation for all or specific packages:
35
+
36
+ ```bash
37
+ # Sync all packages
38
+ doc-sync sync
39
+
40
+ # Sync specific packages
41
+ doc-sync sync @bfra.me/es @bfra.me/eslint-config
42
+
43
+ # Interactive package selection
44
+ doc-sync sync --interactive
45
+
46
+ # Preview changes without writing files
47
+ doc-sync sync --dry-run
48
+
49
+ # With verbose output
50
+ doc-sync sync --verbose
51
+ ```
52
+
53
+ ### Watch Command
54
+
55
+ Monitor for changes and sync automatically during development:
56
+
57
+ ```bash
58
+ # Watch all packages
59
+ doc-sync watch
60
+
61
+ # Watch specific packages
62
+ doc-sync watch @bfra.me/es
63
+
64
+ # Watch with verbose logging
65
+ doc-sync watch --verbose
66
+ ```
67
+
68
+ ### Validate Command
69
+
70
+ Check documentation freshness and validate MDX syntax:
71
+
72
+ ```bash
73
+ # Validate all packages
74
+ doc-sync validate
75
+
76
+ # Validate specific packages
77
+ doc-sync validate @bfra.me/es
78
+ ```
79
+
80
+ ### Global Options
81
+
82
+ | Option | Alias | Description |
83
+ | --------------- | ----- | ----------------------------------------------- |
84
+ | `--root <dir>` | `-r` | Root directory of the monorepo (default: `cwd`) |
85
+ | `--dry-run` | `-d` | Preview changes without writing files |
86
+ | `--verbose` | `-v` | Enable verbose output |
87
+ | `--quiet` | `-q` | Suppress non-error output |
88
+ | `--interactive` | `-i` | Use interactive package selection |
89
+ | `--watch` | `-w` | Watch for changes (on default command) |
90
+
91
+ ## Programmatic API
92
+
93
+ ### Basic Usage
94
+
95
+ ```typescript
96
+ import {createPackageScanner, createSyncOrchestrator} from '@bfra.me/doc-sync'
97
+
98
+ const scanner = createPackageScanner({
99
+ rootDir: process.cwd(),
100
+ includePatterns: ['packages/*'],
101
+ })
102
+
103
+ const orchestrator = createSyncOrchestrator({
104
+ rootDir: process.cwd(),
105
+ outputDir: 'docs/src/content/docs/packages',
106
+ })
107
+
108
+ const packages = await scanner.scan()
109
+ const result = await orchestrator.sync(packages)
110
+
111
+ if (result.success) {
112
+ console.log(`Synced ${result.data.synced.length} packages`)
113
+ }
114
+ ```
115
+
116
+ ### Parsing APIs
117
+
118
+ ```typescript
119
+ import {extractJSDoc, parseReadme, parseTypeScript} from '@bfra.me/doc-sync/parsers'
120
+
121
+ const tsResult = parseTypeScript('src/index.ts')
122
+ const jsDocResult = extractJSDoc(sourceFile)
123
+ const readmeResult = parseReadme('README.md')
124
+ ```
125
+
126
+ ### Generator APIs
127
+
128
+ ```typescript
129
+ import {
130
+ generateAPIReference,
131
+ generateFrontmatter,
132
+ generateMDXDocument,
133
+ mergeContent,
134
+ } from '@bfra.me/doc-sync/generators'
135
+
136
+ const frontmatter = generateFrontmatter({
137
+ title: '@bfra.me/es',
138
+ description: 'ES utilities package',
139
+ })
140
+
141
+ const apiRef = generateAPIReference(packageAPI)
142
+ const mdx = generateMDXDocument({frontmatter, sections: [apiRef]})
143
+ ```
144
+
145
+ ### File Watching
146
+
147
+ ```typescript
148
+ import {createDocDebouncer, createDocWatcher} from '@bfra.me/doc-sync'
149
+
150
+ const watcher = createDocWatcher({
151
+ rootDir: process.cwd(),
152
+ patterns: ['packages/*/src/**/*.ts', 'packages/*/README.md'],
153
+ })
154
+
155
+ const debouncer = createDocDebouncer({
156
+ delayMs: 300,
157
+ onBatch: async (events) => {
158
+ console.log(`Processing ${events.length} file changes`)
159
+ },
160
+ })
161
+
162
+ watcher.on('change', debouncer.add)
163
+ await watcher.start()
164
+ ```
165
+
166
+ ## Configuration
167
+
168
+ ### Package-Level Configuration
169
+
170
+ Configure documentation generation per package in `package.json`:
171
+
172
+ ```json
173
+ {
174
+ "name": "@bfra.me/example",
175
+ "docs": {
176
+ "title": "Custom Package Title",
177
+ "description": "Override the default description",
178
+ "sidebar": {
179
+ "label": "Short Name",
180
+ "order": 1,
181
+ "hidden": false
182
+ },
183
+ "excludeSections": ["internal-api"],
184
+ "frontmatter": {
185
+ "tableOfContents": {
186
+ "minHeadingLevel": 2,
187
+ "maxHeadingLevel": 3
188
+ }
189
+ }
190
+ }
191
+ }
192
+ ```
193
+
194
+ ### Configuration Fields
195
+
196
+ | Field | Type | Description |
197
+ | ----------------- | ---------- | ---------------------------------------- |
198
+ | `title` | `string` | Custom title for the documentation page |
199
+ | `description` | `string` | Custom description override |
200
+ | `sidebar.label` | `string` | Label shown in sidebar navigation |
201
+ | `sidebar.order` | `number` | Sort order in sidebar (lower = earlier) |
202
+ | `sidebar.hidden` | `boolean` | Whether to hide from sidebar |
203
+ | `excludeSections` | `string[]` | Sections to exclude from auto-generation |
204
+ | `frontmatter` | `object` | Additional frontmatter fields |
205
+
206
+ ## Content Preservation
207
+
208
+ Use sentinel markers to preserve manual content sections during regeneration:
209
+
210
+ ```mdx
211
+ {/* AUTO-GENERATED-START */}
212
+
213
+ This content is automatically generated and will be replaced on sync.
214
+
215
+ {/* AUTO-GENERATED-END */}
216
+
217
+ {/* MANUAL-CONTENT-START */}
218
+
219
+ Your custom content here will be preserved during regeneration.
220
+ Add examples, notes, or any additional documentation.
221
+
222
+ {/* MANUAL-CONTENT-END */}
223
+ ```
224
+
225
+ ### Marker Types
226
+
227
+ - `{/* AUTO-GENERATED-START */}` / `{/* AUTO-GENERATED-END */}` — Marks auto-generated content
228
+ - `{/* MANUAL-CONTENT-START */}` / `{/* MANUAL-CONTENT-END */}` — Marks manually maintained content
229
+
230
+ ## TypeScript Types
231
+
232
+ The package exports comprehensive types for type-safe usage:
233
+
234
+ ```typescript
235
+ import type {
236
+ DocConfig,
237
+ DocConfigSource,
238
+ ExportedFunction,
239
+ ExportedType,
240
+ MDXDocument,
241
+ MDXFrontmatter,
242
+ PackageAPI,
243
+ PackageInfo,
244
+ ParseError,
245
+ ParseResult,
246
+ SyncResult,
247
+ SyncSummary,
248
+ } from '@bfra.me/doc-sync'
249
+ ```
250
+
251
+ ## Subpath Exports
252
+
253
+ The package provides granular imports for tree-shaking:
254
+
255
+ | Export | Description |
256
+ | ------------------------------ | ------------------------------------- |
257
+ | `@bfra.me/doc-sync` | Main entry with all exports |
258
+ | `@bfra.me/doc-sync/generators` | MDX and content generation utilities |
259
+ | `@bfra.me/doc-sync/parsers` | TypeScript, JSDoc, and README parsers |
260
+ | `@bfra.me/doc-sync/types` | Type definitions only |
261
+
262
+ ## Architecture
263
+
264
+ ```plaintext
265
+ doc-sync/
266
+ ├── src/
267
+ │ ├── cli/ # CLI commands and TUI
268
+ │ ├── generators/ # MDX and content generators
269
+ │ ├── orchestrator/ # Sync coordination
270
+ │ ├── parsers/ # Source code and README parsers
271
+ │ ├── watcher/ # File system monitoring
272
+ │ └── types.ts # Core type definitions
273
+ ```
274
+
275
+ ## Requirements
276
+
277
+ - Node.js 20+
278
+ - TypeScript 5.0+
279
+ - pnpm (recommended) or npm
280
+
281
+ ## Related Packages
282
+
283
+ - [`@bfra.me/es`](../es/README.md) — ES utilities including Result types and watcher utilities
284
+ - [`@astrojs/starlight`](https://starlight.astro.build/) — Documentation framework (peer dependency)
285
+
286
+ ## License
287
+
288
+ [MIT](../../license.md)