Below is a breakdown of the LiveDirectory
component which is an extended EventEmitter
instance for events support.
- See
> [EventEmitter]
for more information on additional methods and properties available.
static
[Boolean
]: Whether the instance will watch and automatically reload files on changes.- Default:
false
- Default:
watcher
[Chokidar.WatchOptions
]: Watcher constructor options for thechokidar
instance.- See
> [Chokidar]
for all available constructor options.
- See
cache
[Object
]: The options for internal caching of file contents.max_file_count
[Number
]: The maximum number of files to cache. Default:250
.max_file_size
[Number
]: The maximum size of a file to cache inbytes
. Default:1024 * 1024 aka. 1 mb
.- Note you can calculate the maximum cache memory by multipliying the
count * size
options above.
filter
[Object
]: The options for filtering files.keep
[Function | Object
]: The ONLY files you would like to include.ignore
[Function | Object
]: The files to ALWAYS ignore and not include.- Function Example:
(string, fs.stats) => boolean
.- See
> [fs.Stats]
for all available properties. - Note you must return a boolean of
true
to ignore a value and vice versa.
- See
- Object Schema: You can specify the below properties as an object.
names
[Array
]: The names of the files to filter.extensions
[Array
]: The extensions of the files to filter.
Property | Type | Description |
---|---|---|
path |
String |
The system path of this instance directory. |
static |
Boolean |
Whether this instance will watch and reload on changes. |
watcher |
Chokidar.FSWatcher |
The underlying chokidar instance. (Only available when not static) |
files |
Map<string, LiveFile> |
Map of all files identified by their relative path. |
cached |
Map<string, number> |
Map of all cached files identified by their relative path and last updated timestamp. |
get(String: path)
: Returns the live file at the provided path if it exists.- Returns a
LiveFile
instance orundefined
. - See
> [LiveFile]
for more information on the returned component. - Note The path can be a relative or absolute.
- Examples:
assets/test.js
,/assets/test.js
,C:/projects/something/assets/test.js
, etc etc.
- Examples:
- Returns a
destroy()
: Destroys theLiveDirectory
instance.
- See
> [EventEmitter]
for how to subscribe and listen to the emitted events.- Event
'ready'
: Emitted once the instance has loaded all files from the directory / sub-directories. - Event
'destroy'
: Emitted once this instance has been destroyed. - Event(s)
'add', 'update'
: Emitted when a file is created or updated in the directory / sub-directories.- Example Handler:
(String: path, LiveFile: file) => void
- Note the
path
will be a relative path and you can view the absolute / system path withLiveFile.path
.
- Example Handler:
- Event
'delete'
: Emitted when a file is deleted in the directory / sub-directories.- Example Handler:
(String: path) => void
- Note the
path
will be a relative path and you can view the absolute / system path withLiveFile.path
.
- Example Handler:
- Event