js.plated_files
Manage the files that we read from and watch or write to.
This module only exposes one function, which is used to create the actual module with bound state data.
plated_files = require("./plated_files.js").create(opts,plated)
This is called automatically when the plated module is created and the return value is made available in plated.chunks note that all of these modules are bound together and operate as a group with shared data.
In the future when we talk about this module and its available functions we are referring to the return value from this create function.
js.plated_files.base_files_to_chunks
chunks = await plated_files.base_files_to_chunks(fname)
Check this directory and all directories above for generic chunks build all of these into the current chunk namespace for this file.
js.plated_files.build
plated_files.build()
Build all files found in the source dir into the output dir.
js.plated_files.build_file
plated_files.build_file(fname)
Build the given source filename, using chunks or maybe just a raw copy from source into the output.
js.plated_files.empty_cache
plated_files.empty_cache()
Empty the current file cache, we fill it up as read files.
js.plated_files.empty_folder
plated_files.empty_folder(path)
Empty the (output) folder or make it if it does not exist. This is rather dangerous so please be careful.
js.plated_files.exists
await plated_files.exists(path)
Returns true if a file or dir at the given path exists.
js.plated_files.file_to_chunks
chunks = plated_files.file_to_chunks(root,fname,chunks)
Load root/fname or get it from the cache and then turn it into chunks using plated_chunks.fill_chunks(date,chunks) chunks is returned.
js.plated_files.filename_fixup
filename = plated_files.filename_fixup(filename)
Fix the filename, so it becomes an empty string rather than a "." or "/." or "/" this makes it easier to use in urls.
js.plated_files.filename_is_basechunk
bool = plated_files.filename_is_basechunk(filename)
Is this filename part of the basechunks for a dir?
A base chunk is something like ^.html or ^.css all of these files get merged into the base chunks for the directory they are found in. Their extension is ignored and just to help syntax highlighting when the file is viewed.
js.plated_files.filename_is_plated
bool = plated_files.filename_is_plated(filename)
Is this filename something we need to run through plated. Returns true if filename contains the ^ trigger string. This string can be changed by altering opts.hashfile from "^" to something else.
js.plated_files.filename_to_dirname
dirname = plated_files.filename_to_dirname(filename)
Get the dirname of this filename.
js.plated_files.filename_to_output
filename = plated_files.filename_to_output(filename)
Work out the output filename from an input filename, the trigger string "^." gets removed as we process a file.
js.plated_files.find_dirs
plated_files.find_dirs(root,name,func)
Call func(name) with every directory we find inside the root/name directory. We follow symlinks into other directories.
js.plated_files.find_files
plated_files.find_files(root,name)
REturn an array with every file we find inside the root/name directory. We follow symlinks into other directories.
js.plated_files.joinpath
await plated_files.joinpath(...)
join components into a full path.
js.plated_files.lstat
await plated_files.lstat(path)
Return the lstat of this path
js.plated_files.mkdir
plated_files.mkdir(dir)
Create the given dir and recursively create its parent dirs as well if necessary.
js.plated_files.prepare_namespace
plated_files.prepare_namespace(fname)
Check this directory and all directories above for generic chunks then build all of these into the current chunk namespace for this file.
js.plated_files.readdir
await plated_files.readdir(path)
Return the readdir of this path
js.plated_files.set_source
plated_files.set_source(dir)
Fill in _source and related chunks such as.
_sourcename the file that this set of chunks came from.
_filename the output filename.
_dirname the output dirname.
_root the root of the site, normally a relative path to the current directory, eg ../ since some things such as github pages need to exist in a directory rather than the root of a site. This should always be used in html paths, {_root} instead of / to make sure that you always get to the right place and can find your files.
_filename the url path of the filename, eg /dirname/filename
_dirname the url path of the dir this file exists in, eg /dirname
js.plated_files.source_to_output
filename = plated_files.source_to_output(filename)
Convert a source path into an output path.
js.plated_files.stat
await plated_files.stat(path)
Return the stat of this path
js.plated_files.trimpath
plated_files.trimpath(path)
Remove a trailing / from the path
js.plated_files.watch
plated_files.watch()
Build all files found in the source dir into the output dir and then sit watching for changes to these files that would trigger rebuilds.
This does not return, instead the user is expected to ctrl+c when finished.
js.plated_files.write
plated_files.write(filename,data)
Create parent dir if necessary and write the data into this file.