You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/components/plugins.md
+64-54Lines changed: 64 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,7 +161,17 @@ In this example, the entry handler method passed to `handleEntry` will manage th
161
161
162
162
This example is heavily simplified, but it demonstrates how the different key parts of `scope` can be used together to provide a performant and reactive application experience.
This is the only method a plugin module must export. It can be async and is awaited by the component loader. The `scope` argument provides access to the relative application's configuration, resources, and other APIs.
Emitted after the scope is closed via the `close()` method.
181
191
182
-
### Event: `'error'`
192
+
####Event: `'error'`
183
193
184
194
-`error` - `unknown` - The error that occurred.
185
195
186
-
### Event: `'ready'`
196
+
####Event: `'ready'`
187
197
188
198
Emitted when the Scope is ready to be used after loading the associated config file. It is awaited by the component loader, so it is not necessary to await it within the `handleApplication()` method.
189
199
190
-
### `scope.close()`
200
+
####`scope.close()`
191
201
192
202
Returns: `this` - The current `Scope` instance.
193
203
194
204
Closes all associated entry handlers, the associated `scope.options` instance, emits the `'close'` event, and then removes all other listeners on the instance.
195
205
196
-
### `scope.handleEntry([files][, handler])`
206
+
####`scope.handleEntry([files][, handler])`
197
207
198
208
Parameters:
199
209
@@ -247,23 +257,23 @@ customPlugin:
247
257
248
258
Then the default `EntryHandler` instances would be created to handle all entries within the `web` directory.
249
259
250
-
### `scope.requestRestart()`
260
+
#### `scope.requestRestart()`
251
261
252
262
Returns: `void`
253
263
254
264
Request a Harper restart. This **does not** restart the instance immediately, but rather indicates to the user that a restart is required. This should be called when the plugin cannot handle the entry event and wants to indicate to the user that the Harper instance should be restarted.
255
265
256
266
This method is called automatically by the `scope` instance if the user has not defined an `scope.options.on('change')` handler or if an event handler exists and is missing a necessary handler method.
257
267
258
-
### `scope.resources`
268
+
#### `scope.resources`
259
269
260
270
Returns: `Map<string, Resource>`- A map of the currently loaded [Resource](../globals#resource) instances.
261
271
262
-
### `scope.server`
272
+
#### `scope.server`
263
273
264
274
Returns: `server`- A reference to the [server](../globals#server) global API.
265
275
266
-
### `scope.options`
276
+
#### `scope.options`
267
277
268
278
Returns: [`OptionsWatcher`](#class-optionswatcher) - An instance of the `OptionsWatcher` class that provides access to the application's configuration options. Emits `'change'` events when the respective plugin part of the component's config file is modified.
269
279
@@ -293,39 +303,39 @@ Then modifying the `files` option in the `config.yaml` to `bar.js` would log the
293
303
Files option changed to: bar.js
294
304
```
295
305
296
-
### `scope.logger`
306
+
####`scope.logger`
297
307
298
308
Returns: `logger` - A scoped instance of the [`logger`](../globals#logger) class that provides logging capabilities for the plugin.
299
309
300
310
It is recommended to use this instead of the `logger` global.
301
311
302
-
### `scope.name`
312
+
####`scope.name`
303
313
304
314
Returns: `string` - The name of the plugin as configured in the `config.yaml` file. This is the key under which the plugin is configured.
305
315
306
-
### `scope.directory`
316
+
####`scope.directory`
307
317
308
318
Returns: `string` - The directory of the application. This is the root directory of the component where the `config.yaml` file is located.
-`source` - `string` | `string[]` - _required_ - The glob pattern string or array of strings.
317
327
-`ignore` - `string` | `string[]` - _optional_ - An array of glob patterns to exclude from matches. This is an alternative way to use negative patterns. Defaults to `[]`.
318
328
319
-
## Interface: `FileAndURLPathConfig`
329
+
###Interface: `FileAndURLPathConfig`
320
330
321
331
-`files` - [`FilesOption`](#interface-filesoption) - _required_ - A glob pattern string, array of glob pattern strings, or a more expressive glob options object determining the set of files and directories to be resolved for the plugin.
322
332
-`urlPath` - `string` - _optional_ - A base URL path to prepend to the resolved `files` entries.
Emitted when the `OptionsWatcher` is closed via the `close()` method. The watcher is not usable after this event is emitted.
360
370
361
-
### Event: `'error'`
371
+
#### Event: `'error'`
362
372
363
373
- `error`- `unknown` - The error that occurred.
364
374
365
-
### Event: `'ready'`
375
+
#### Event: `'ready'`
366
376
367
377
- `config`- [`ConfigValue`](#interface-configvalue) | `undefined` - The configuration object of the plugin, if present.
368
378
369
379
This event can be emitted multiple times. It is first emitted upon the initial load, but will also be emitted after restoring a configuration file or configuration object after a `'remove'` event.
370
380
371
-
### Event: `'remove'`
381
+
#### Event: `'remove'`
372
382
373
383
The configuration was removed. This can happen if the configuration file was deleted, the configuration object within the file is deleted, or if the configuration file fails to parse. Once restored, the `'ready'` event will be emitted again.
374
384
375
-
### `options.close()`
385
+
#### `options.close()`
376
386
377
387
Returns: `this`- The current `OptionsWatcher` instance.
378
388
379
389
Closes the options watcher, removing all listeners and preventing any further events from being emitted. The watcher is not usable after this method is called.
If the config is defined it will attempt to retrieve the value of the option at the specified key. If the key does not exist, it will return `undefined`.
Returns the root configuration object of the application. This is the entire configuration object, basically the parsed form of the `config.yaml`. If the config is not defined, it will return `undefined`.
Created by calling [`scope.handleEntry()`](#scopehandleentry) method.
420
430
421
-
### Event: `'all'`
431
+
#### Event: `'all'`
422
432
423
433
- `entry`- [`FileEntry`](#interface-fileentry) | [`DirectoryEntry`](#interface-directoryentry) - The entry that was added, changed, or removed.
424
434
@@ -450,67 +460,67 @@ async function handleApplication(scope) {
450
460
}
451
461
```
452
462
453
-
### Event: `'add'`
463
+
#### Event: `'add'`
454
464
455
465
- `entry`- [`AddFileEvent`](#interface-addfileevent) - The file entry that was added.
456
466
457
467
The `'add'` event is emitted when a file is created (or the watcher sees it for the first time). The event handler receives an `AddFileEvent` object that contains the file contents, URL path, absolute path, and other metadata.
458
468
459
-
### Event: `'addDir'`
469
+
#### Event: `'addDir'`
460
470
461
471
- `entry`- [`AddDirectoryEvent`](#interface-adddirectoryevent) - The directory entry that was added.
462
472
463
473
The `'addDir'` event is emitted when a directory is created (or the watcher sees it for the first time). The event handler receives an `AddDirectoryEvent` object that contains the URL path and absolute path of the directory.
464
474
465
-
### Event: `'change'`
475
+
#### Event: `'change'`
466
476
467
477
- `entry`- [`ChangeFileEvent`](#interface-changefileevent) - The file entry that was changed.
468
478
469
479
The `'change'` event is emitted when a file is modified. The event handler receives a `ChangeFileEvent` object that contains the updated file contents, URL path, absolute path, and other metadata.
470
480
471
-
### Event: `'close'`
481
+
#### Event: `'close'`
472
482
473
483
Emitted when the entry handler is closed via the [`entryHandler.close()`](#entryhandlerclose) method.
474
484
475
-
### Event: `'error'`
485
+
#### Event: `'error'`
476
486
477
487
- `error`- `unknown` - The error that occurred.
478
488
479
-
### Event: `'ready'`
489
+
#### Event: `'ready'`
480
490
481
491
Emitted when the entry handler is ready to be used. This is not automatically awaited by the component loader, but also is not required. Calling `scope.handleEntry()` is perfectly sufficient. This is generally useful if you need to do something _after_ the entry handler is absolutely watching and handling entries.
482
492
483
-
### Event: `'unlink'`
493
+
#### Event: `'unlink'`
484
494
485
495
- `entry`- [`UnlinkFileEvent`](#interface-unlinkfileevent) - The file entry that was deleted.
486
496
487
497
The `'unlink'` event is emitted when a file is deleted. The event handler receives an `UnlinkFileEvent` object that contains the URL path and absolute path of the deleted file.
488
498
489
-
### Event: `'unlinkDir'`
499
+
#### Event: `'unlinkDir'`
490
500
491
501
- `entry`- [`UnlinkDirectoryEvent`](#interface-unlinkdirectoryevent) - The directory entry that was deleted.
492
502
493
503
The `'unlinkDir'` event is emitted when a directory is deleted. The event handler receives an `UnlinkDirectoryEvent` object that contains the URL path and absolute path of the deleted directory.
494
504
495
-
### `entryHandler.name`
505
+
#### `entryHandler.name`
496
506
497
507
Returns: `string`- The name of the plugin as configured in the `config.yaml` file. This is the key under which the plugin is configured.
498
508
499
509
The name of the plugin.
500
510
501
-
### `entryHandler.directory`
511
+
#### `entryHandler.directory`
502
512
503
513
Returns: `string`
504
514
505
515
The directory of the application. This is the root directory of the component where the `config.yaml` file is located.
506
516
507
-
### `entryHandler.close()`
517
+
#### `entryHandler.close()`
508
518
509
519
Returns: `this`- The current `EntryHandler` instance.
510
520
511
521
Closes the entry handler, removing all listeners and preventing any further events from being emitted. The handler can be started again using the [`entryHandler.update()`](#entryhandlerupdateconfig) method.
512
522
513
-
### `entryHandler.update(config)`
523
+
#### `entryHandler.update(config)`
514
524
515
525
Parameters:
516
526
@@ -520,7 +530,7 @@ This method will update an existing entry handler to watch new entries. It will
520
530
521
531
This method returns a promise associated with the ready event of the updated handler.
522
532
523
-
### Interface: `BaseEntry`
533
+
#### Interface: `BaseEntry`
524
534
525
535
- `stats`- [`fs.Stats`](https://nodejs.org/docs/latest/api/fs.html#class-fsstats) | `undefined` - The file system stats for the entry.
526
536
- `urlPath`- `string` - The recommended URL path of the entry.
@@ -532,7 +542,7 @@ The `urlPath` is resolved based on the configured pattern (`files:` option) comb
532
542
533
543
The `absolutePath` is the file system path for the entry.
534
544
535
-
### Interface: `FileEntry`
545
+
#### Interface: `FileEntry`
536
546
537
547
Extends [`BaseEntry`](#interface-baseentry)
538
548
@@ -542,7 +552,7 @@ A specific extension of the `BaseEntry` interface representing a file entry. We
542
552
543
553
There is no `DirectoryEntry` since there is no other important metadata aside from the `BaseEntry` properties. If a user wants the contents of a directory, they should adjust the pattern to resolve files instead.
A union type representing the file entry events. These events are emitted when a file is created, modified, or deleted. The `FileEntry` interface provides the file contents and other metadata.
0 commit comments