@ui-doc/rollup 0.3.1 → 0.3.2

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 CHANGED
@@ -1,10 +1,22 @@
1
- # UI-Doc rollup plugin
1
+ # @ui-doc/rollup
2
2
 
3
- This plugin integrates UI-Doc into rollup.
3
+ A Rollup plugin that integrates UI-Doc into your Rollup build process. Generate interactive UI documentation from JSDoc-style comment blocks in your source files (CSS, JS, TS) as part of your build.
4
4
 
5
- ## Install
5
+ ## Overview
6
6
 
7
- ```sh
7
+ The UI-Doc Rollup plugin:
8
+
9
+ - Watches source files for documentation blocks during development
10
+ - Parses JSDoc-style comments into structured documentation
11
+ - Generates HTML documentation pages with live examples
12
+ - Manages assets (styles, scripts, highlight.js) automatically
13
+ - Integrates seamlessly with your existing Rollup configuration
14
+
15
+ ## Installation
16
+
17
+ Install the plugin along with the required peer dependencies:
18
+
19
+ ```bash
8
20
  # npm
9
21
  npm install --save-dev @ui-doc/rollup @ui-doc/html-renderer @highlightjs/cdn-assets
10
22
 
@@ -15,83 +27,485 @@ yarn add --dev @ui-doc/rollup @ui-doc/html-renderer @highlightjs/cdn-assets
15
27
  pnpm install --save-dev @ui-doc/rollup @ui-doc/html-renderer @highlightjs/cdn-assets
16
28
  ```
17
29
 
18
- ## Setup
30
+ **Note:** `@highlightjs/cdn-assets` is only required if you want code highlighting in your documentation (which is the default). You can disable it by setting `assets.highlightScript` and `assets.highlightStyle` to `false`.
31
+
32
+ ## Quick Start
33
+
34
+ ```js
35
+ // rollup.config.js
36
+ import uidoc from '@ui-doc/rollup'
37
+
38
+ export default {
39
+ input: 'src/index.js',
40
+ output: {
41
+ dir: 'dist',
42
+ format: 'es',
43
+ },
44
+ plugins: [
45
+ uidoc({
46
+ source: ['src/**/*.css', 'src/**/*.js'],
47
+ settings: {
48
+ texts: {
49
+ title: 'My Component Library',
50
+ },
51
+ },
52
+ }),
53
+ ],
54
+ }
55
+ ```
56
+
57
+ This basic setup will:
58
+
59
+ 1. Search for documentation blocks in all CSS and JS files in `src/`
60
+ 2. Generate documentation in `dist/` (the same directory as your Rollup output)
61
+ 3. Include default styles and syntax highlighting
62
+
63
+ ## Configuration
64
+
65
+ ### Basic Example
19
66
 
20
67
  ```js
21
68
  import uidoc from '@ui-doc/rollup'
22
69
  import postcss from 'rollup-plugin-postcss'
23
70
 
24
- export default [
25
- {
26
- input: {
27
- app: 'css/index.css',
28
- },
29
- output: {
30
- dir: 'dist',
31
- },
32
- plugins: [
33
- postcss({
34
- extract: 'app.css',
35
- }),
36
- uidoc({
37
- settings: {
38
- generate: {
39
- logo: () => 'Rollup',
40
- },
41
- texts: {
42
- title: 'Rollup Example',
43
- },
71
+ export default {
72
+ input: {
73
+ app: 'css/index.css',
74
+ },
75
+ output: {
76
+ dir: 'dist',
77
+ },
78
+ plugins: [
79
+ postcss({
80
+ extract: 'app.css',
81
+ }),
82
+ uidoc({
83
+ source: ['css/**/*.css'],
84
+ settings: {
85
+ generate: {
86
+ logo: () => '<img src="logo.svg" alt="Logo">',
87
+ },
88
+ texts: {
89
+ title: 'Design System',
90
+ copyright: '© 2025 Your Company',
44
91
  },
45
- source: ['css/**/*.css'],
46
- assets: {
47
- example: {
92
+ },
93
+ assets: {
94
+ static: 'public',
95
+ example: [
96
+ {
48
97
  name: 'app',
49
- input: true,
98
+ fromInput: true,
50
99
  },
51
- },
52
- }),
53
- ],
100
+ ],
101
+ },
102
+ }),
103
+ ],
104
+ }
105
+ ```
106
+
107
+ ### Advanced Example with Custom Assets
108
+
109
+ ```js
110
+ import uidoc from '@ui-doc/rollup'
111
+
112
+ export default {
113
+ input: {
114
+ app: 'src/index.js',
115
+ theme: 'src/theme.css',
116
+ },
117
+ output: {
118
+ dir: 'dist',
54
119
  },
55
- ]
120
+ plugins: [
121
+ uidoc({
122
+ source: ['src/**/*.css', 'src/**/*.js'],
123
+ output: {
124
+ dir: 'docs',
125
+ baseUri: '/docs/',
126
+ },
127
+ settings: {
128
+ texts: {
129
+ title: 'Component Library',
130
+ },
131
+ },
132
+ assets: {
133
+ highlightTheme: 'github',
134
+ example: [
135
+ {
136
+ name: 'theme',
137
+ fromInput: true,
138
+ },
139
+ {
140
+ name: 'custom.js',
141
+ file: 'src/docs/custom.js',
142
+ },
143
+ ],
144
+ },
145
+ }),
146
+ ],
147
+ }
56
148
  ```
57
149
 
58
150
  ## Options
59
151
 
152
+ ### Core Options
153
+
60
154
  | Name | Required | Type | Description |
61
155
  | --- | --- | --- | --- |
62
- | blockParser | no | BlockParser | Give a custom BlockParser instance to change the block parsing. |
63
- | renderer | no | Renderer | Instance of renderer. Per default a instance of [@ui-doc/html-renderer](../html-renderer/README.md) will be created. |
64
- | source | yes | string[] | List of glob patterns to find source files. Please see [picomatch](https://github.com/micromatch/picomatch) how to define patterns. |
65
- | outputDir | no | string | Change output directory to create the UI-Doc in a subfolder of your application. |
66
- | templatePath | no | string | When using the default renderer you can override default templates from the renderer or add custom templates for generation. |
67
- | output | no | object | Change output settings |
68
- | output.dir | no | string | path where you wan't to put the ui-doc. Will be relativ to rollup's output dir |
69
- | output.baseUri | no | string | Change the base URI of you UI-Kit useful if you wan't to place the UI-Doc somewhere else then the output folder. If `output.dir` is given and no `output.baseUri` the dir will be used. You can give '.' so all URLs will be relative. |
70
- | settings | no | object | UI-Doc specific settings. |
71
- | settings.generate | no | object | UI-Doc core generate setting |
72
- | settings.texts | no | object | UI-Doc core texts setting |
73
- | assets | no | object | Change asset usage |
74
- | assets.static | no | string | ive a static assets folder (path relativ to your working directory), files and sub folders will be copied to the UI-Doc output dir. |
75
- | assets.styleAsset | no | false / string | With false prevent including the UI-Doc style. With string change the included style name. |
76
- | assets.highlightStyle | no | false / string | With false prevent including highlight.js style. With string change name of included style. |
77
- | assets.highlightTheme | no | string | Change highlight.js style theme (default is `default`). Please look into the [highlight.js repository](https://github.com/highlightjs/highlight.js/tree/main/src/styles) to see available themes. |
78
- | assets.highlightScript | no | false / string | With false prevent including highlight.js. With string change name of included script. |
79
- | assets.page | no | AssetOption[] | Include custom scripts and styles for UI-Doc pages |
80
- | assets.example | no | AssetOption[] | Include custom scripts and styles for UI-Doc examples |
156
+ | source | **Yes** | `string[]` | Glob patterns to find source files. Uses [picomatch](https://github.com/micromatch/picomatch) syntax. |
157
+ | renderer | No | `Renderer` | Custom renderer instance. Defaults to `HtmlRenderer` from `@ui-doc/html-renderer`. |
158
+ | blockParser | No | `BlockParser` | Custom block parser instance. Defaults to `CommentBlockParser`. |
159
+ | templatePath | No | `string` | Path to custom templates directory for overriding or extending default renderer templates. |
160
+
161
+ ### Output Options
162
+
163
+ | Name | Type | Default | Description |
164
+ | --- | --- | --- | --- |
165
+ | output.dir | `string` | `''` | Subdirectory within Rollup's output directory for UI-Doc files. |
166
+ | output.baseUri | `string` | Same as `output.dir` | Base URI for all UI-Doc links. Use `'.'` for relative URLs. |
167
+
168
+ **Example:**
169
+
170
+ ```js
171
+ uidoc({
172
+ source: ['src/**/*.css'],
173
+ output: {
174
+ dir: 'ui-doc', // Creates documentation in dist/ui-doc/
175
+ baseUri: '/styleguide/', // All links use /styleguide/ prefix
176
+ },
177
+ })
178
+ ```
179
+
180
+ ### Settings Options
181
+
182
+ UI-Doc specific settings that control content generation.
183
+
184
+ | Name | Type | Description |
185
+ | --- | --- | --- |
186
+ | settings.generate | `object` | Functions that generate content. See [Core Documentation](../core/README.md#generate-functions). |
187
+ | settings.texts | `object` | Text strings for title, copyright, etc. |
188
+
189
+ **Example:**
190
+
191
+ ```js
192
+ uidoc({
193
+ source: ['src/**/*.css'],
194
+ settings: {
195
+ generate: {
196
+ logo: () => '<strong>MyBrand</strong>',
197
+ footerText: () => 'Powered by UI-Doc',
198
+ homeLink: () => '/',
199
+ },
200
+ texts: {
201
+ title: 'Design System Documentation',
202
+ copyright: '© 2025 MyCompany',
203
+ },
204
+ },
205
+ })
206
+ ```
207
+
208
+ ### Assets Options
209
+
210
+ Control which assets are included in documentation pages and examples.
211
+
212
+ #### Built-in Assets
213
+
214
+ | Name | Type | Default | Description |
215
+ | --- | --- | --- | --- |
216
+ | assets.static | `string` | - | Path to static assets folder. Files are copied to UI-Doc output directory. |
217
+ | assets.styleAsset | `false \| string` | `'ui-doc.css'` | Name of UI-Doc stylesheet. Set to `false` to disable. |
218
+ | assets.highlightStyle | `false \| string` | `'highlight.css'` | Name of highlight.js stylesheet. Set to `false` to disable. |
219
+ | assets.highlightTheme | `string` | `'default'` | Highlight.js theme name. See [available themes](https://github.com/highlightjs/highlight.js/tree/main/src/styles). |
220
+ | assets.highlightScript | `false \| string` | `'highlight.js'` | Name of highlight.js script. Set to `false` to disable. |
221
+
222
+ **Example - Custom Highlighting:**
223
+
224
+ ```js
225
+ uidoc({
226
+ source: ['src/**/*.css'],
227
+ assets: {
228
+ highlightTheme: 'github-dark',
229
+ },
230
+ })
231
+ ```
232
+
233
+ **Example - Disable Highlighting:**
234
+
235
+ ```js
236
+ uidoc({
237
+ source: ['src/**/*.css'],
238
+ assets: {
239
+ highlightStyle: false,
240
+ highlightScript: false,
241
+ },
242
+ })
243
+ ```
244
+
245
+ #### Custom Assets
246
+
247
+ | Name | Type | Description |
248
+ | --- | --- | --- |
249
+ | assets.page | `AssetOption[]` | Custom scripts and styles for documentation pages. |
250
+ | assets.example | `AssetOption[]` | Custom scripts and styles for example previews. |
251
+
252
+ **AssetOption Interface:**
253
+
254
+ ```text
255
+ interface AssetOption {
256
+ // Asset name or file name
257
+ name: string | (() => string)
258
+
259
+ // Load from Rollup input (requires name to match input key)
260
+ fromInput?: boolean | ((asset: AssetResolved) => boolean)
261
+
262
+ // Load from file system
263
+ file?: string | (() => string)
264
+
265
+ // Load from node_modules package
266
+ dependency?: string | (() => string)
267
+
268
+ // Provide source directly
269
+ source?: string | Uint8Array | (() => string)
270
+
271
+ // HTML attributes to add to the asset tag
272
+ attrs?: Record<string, string>
273
+ }
274
+ ```
275
+
276
+ **Example - Load from Rollup Input:**
277
+
278
+ ```js
279
+ // rollup.config.js
280
+ export default {
281
+ input: {
282
+ app: 'src/index.js',
283
+ theme: 'src/theme.css',
284
+ },
285
+ plugins: [
286
+ uidoc({
287
+ source: ['src/**/*.js'],
288
+ assets: {
289
+ example: [
290
+ {
291
+ name: 'app', // Matches input key
292
+ fromInput: true,
293
+ },
294
+ {
295
+ name: 'theme', // Matches input key
296
+ fromInput: true,
297
+ },
298
+ ],
299
+ },
300
+ }),
301
+ ],
302
+ }
303
+ ```
304
+
305
+ **Example - Load from File:**
306
+
307
+ ```js
308
+ uidoc({
309
+ source: ['src/**/*.css'],
310
+ assets: {
311
+ example: [
312
+ {
313
+ name: 'custom-example.css',
314
+ file: 'src/docs/example-styles.css',
315
+ },
316
+ ],
317
+ page: [
318
+ {
319
+ name: 'custom-page.js',
320
+ file: 'src/docs/page-script.js',
321
+ attrs: {
322
+ type: 'module',
323
+ },
324
+ },
325
+ ],
326
+ },
327
+ })
328
+ ```
329
+
330
+ **Example - Load from Package:**
331
+
332
+ ```js
333
+ uidoc({
334
+ source: ['src/**/*.css'],
335
+ assets: {
336
+ example: [
337
+ {
338
+ name: 'normalize.css',
339
+ dependency: 'normalize.css',
340
+ },
341
+ ],
342
+ },
343
+ })
344
+ ```
345
+
346
+ **Example - Inline Source:**
347
+
348
+ ```js
349
+ uidoc({
350
+ source: ['src/**/*.css'],
351
+ assets: {
352
+ page: [
353
+ {
354
+ name: 'analytics.js',
355
+ source: 'console.log("Page loaded")',
356
+ },
357
+ ],
358
+ },
359
+ })
360
+ ```
361
+
362
+ ## Plugin API
363
+
364
+ The plugin exposes an API that can be accessed from other Rollup plugins:
365
+
366
+ ```js
367
+ // In another Rollup plugin
368
+ const myPlugin = {
369
+ name: 'my-plugin',
370
+ buildStart() {
371
+ const uidocPlugin = this.meta.plugins.find(p => p.name === 'ui-doc')
372
+ if (uidocPlugin?.api) {
373
+ // Register a custom asset
374
+ uidocPlugin.api.uidocAsset('my-asset.css', 'example', {
375
+ type: 'style',
376
+ attrs: { media: 'screen' },
377
+ })
378
+ }
379
+ },
380
+ }
381
+ ```
382
+
383
+ **API Methods:**
384
+
385
+ | Property | Type | Description |
386
+ | --- | --- | --- |
387
+ | version | `string` | Plugin version |
388
+ | fileFinder | `FileFinder` | File finder instance for searching source files |
389
+ | fileSystem | `FileSystem` | File system abstraction |
390
+ | options | `ResolvedOptions` | Resolved plugin options |
391
+ | uidoc | `UIDoc` | UI-Doc instance |
392
+ | uidocAsset | `Function` | Register an asset for documentation pages or examples |
393
+ | isAssetFromInput | `Function` | Check if an asset was marked as coming from input |
394
+ | addAssetFromInput | `Function` | Mark an asset as coming from input |
395
+
396
+ ## Watch Mode
397
+
398
+ The plugin fully supports Rollup's watch mode. Source files are automatically watched, and documentation is regenerated when:
399
+
400
+ - A source file is created, updated, or deleted
401
+ - The file matches the `source` glob patterns
402
+ - The file contains documentation blocks
403
+
404
+ ## Integration with Other Plugins
405
+
406
+ The UI-Doc plugin works seamlessly with other Rollup plugins. It's recommended to place it after plugins that transform your source files:
407
+
408
+ ```js
409
+ import babel from '@rollup/plugin-babel'
410
+ import uidoc from '@ui-doc/rollup'
411
+ import postcss from 'rollup-plugin-postcss'
412
+
413
+ export default {
414
+ plugins: [
415
+ // Transform plugins first
416
+ postcss({ extract: true }),
417
+ babel({ babelHelpers: 'bundled' }),
418
+
419
+ // Then generate documentation
420
+ uidoc({
421
+ source: ['src/**/*.css', 'src/**/*.js'],
422
+ }),
423
+ ],
424
+ }
425
+ ```
426
+
427
+ ## Documentation Syntax
428
+
429
+ UI-Doc uses JSDoc-style comment blocks with special tags. Here's a quick example:
430
+
431
+ ```js
432
+ /**
433
+ * Creates a page for button documentation.
434
+ *
435
+ * @page buttons Buttons
436
+ */
437
+
438
+ /**
439
+ * Primary button with blue background.
440
+ *
441
+ * @location buttons.primary Primary Button
442
+ * @example
443
+ * <button class="btn btn-primary">Click me</button>
444
+ */
445
+ ```
446
+
447
+ For complete documentation syntax and available tags, see the [@ui-doc/core documentation](../core/README.md).
448
+
449
+ ## TypeScript Support
450
+
451
+ The plugin is written in TypeScript and includes full type definitions:
81
452
 
82
453
  ```ts
83
- export interface AssetOption {
84
- name: string | (() => string) // name or relative file name of the asset
85
- fromInput?: boolean | ((asset: AssetResolved) => boolean) // try to get asset information from rollup's input option. Eg. if you configure the input as object you can give the asset key as name and UI-Doc will try to resolve the asset file for you
86
- file?: string | (() => string) // load asset from file
87
- dependency?: string | (() => string) // load the asset from dependency
88
- source?: string | Uint8Array | (() => string) // give the asset source directly
89
- attrs?: Record<string, string> // give asset html attributes that should be rendered into the output
454
+ import type { Options } from '@ui-doc/rollup'
455
+ import uidoc from '@ui-doc/rollup'
456
+
457
+ const config: Options = {
458
+ source: ['src/**/*.ts'],
459
+ settings: {
460
+ texts: {
461
+ title: 'TypeScript Components',
462
+ },
463
+ },
464
+ }
465
+
466
+ export default {
467
+ plugins: [uidoc(config)],
90
468
  }
91
469
  ```
92
470
 
93
- # Upcoming Features
471
+ ## Troubleshooting
472
+
473
+ ### Documentation Not Generated
474
+
475
+ - Verify `source` patterns match your files
476
+ - Check that files contain valid JSDoc-style comment blocks
477
+ - Enable Rollup's verbose logging to see UI-Doc output messages
478
+
479
+ ### Assets Not Loading
480
+
481
+ - If using `fromInput: true`, ensure the asset name matches a key in Rollup's `input` object
482
+ - Check browser console for 404 errors and verify `output.baseUri` is correct
483
+ - When using `output.dir`, assets from input are automatically copied to the UI-Doc directory
484
+
485
+ ### Custom Templates Not Applied
486
+
487
+ - Verify `templatePath` points to an existing directory
488
+ - Check that template files have the correct names (see [@ui-doc/html-renderer](../html-renderer/README.md))
489
+ - Templates should use the HTML renderer's template syntax
490
+
491
+ ## Known Issues
492
+
493
+ - When creating assets exclusively for UI-Doc through Rollup input, the asset will be generated first in Rollup's output directory and then copied to the UI-Doc output directory.
494
+
495
+ ## Examples
496
+
497
+ See the [demos directory](../../demos) in the repository for complete working examples:
498
+
499
+ - Basic Rollup setup: `demos/rollup.config.mjs`
500
+ - Advanced configurations with custom assets and templates
501
+
502
+ ## Related Packages
503
+
504
+ - [@ui-doc/core](../core/README.md) - Core parsing and rendering engine
505
+ - [@ui-doc/node](../node/README.md) - Node.js file system operations
506
+ - [@ui-doc/html-renderer](../html-renderer/README.md) - Default HTML renderer
507
+ - [@ui-doc/vite](../vite/README.md) - Vite plugin (wraps this Rollup plugin)
94
508
 
95
- # Known Issues
509
+ ## License
96
510
 
97
- - When creating assets over rollup input exclusive for UI-Doc the asset will be generated first to roleup's output directory and then be copied to the UI-Doc output.
511
+ See [LICENSE.md](../../LICENSE.md) for license information.