copy and mutate files by extension
Freud watches directories and copies files between them. It allows you to modify the file information before rendering using callbacks attached to file extensions.
Err that's confusing, here:
var Freud = require'freud'var freud = Freud'/home/me/src' '/home/me/html'md = require'md'freudlisten'md'filedata = mdfiledatafilename = filenamereplace/\.md$/ '.html'return filefreudgo
That will watch
/home/me/src for changes to files with the
When there is one, it will run the file contents through
md, our theoretical
Markdown processor, and change the extension to
.html before dumping the
mutated file into
/home/me/html. Of course the origin file is never modified
in any way.
Listen also accepts '*:before' and '*:after' to apply to all processed files. You can probably guess when they occur. If you add a listener with '*', it will be pushed onto the '*:before' stack. Listen also accepts an array of extensions to listen for, like:
freudlisten'md' 'markdown' 'mkd' parseFileFunction
The file object available within your listen statements is of structure:
name: "example.txt"stats: node fsStats objectdata: "the file contents"write: true
file.write property is set to
false and never reset to
true at any
point in the chain of transformations, Freud will not write it to the
Freud does not watch sub-directories. In order to effectively monitor multiple directories, you will need to construct multiple Freud objects.
Freud also accepts an optional third parameter of an options object. The options available are as follows:
monitorDotto watch for dotfile changes, default is
monitorSquiggleto watch for files with names ending with ~, such as are common for backups. Default is
ignoreCaseto not match case on event/listener matching. Default is
Freud will also emit certain events that may be useful, such as:
startedwhen the service begins watching.
stoppedwhen service is stopped (via
extensionAddedwhenever a new extension is being listened for.
compilingwhenever a valid (ie not blocked by user monitoring options and not a duplicate or temporary file) file change event is caught. The filename will be passed.
compiledafter a file has been processed and written to the target directory. The compiled filename will be passed.
recompiledafter a successful compilation triggered by
blockedwhenever a write to the target has been canceled due to
file.writebeing set to
unlinkedwhen a file has been unlinked due to removal of the file in the source directory.
copyingwhen a file has no rules it will be copied rather than processed for better performance.
copiedwhen copying has occurred.