-
Notifications
You must be signed in to change notification settings - Fork 15
File System
The core module, fileSystem.js
is a wrapper around many of the common node.js file manipulation commands. The API is documented below.
- baseline:
- workingBase:
- file:
Build a local path for a folder or file in a project.
- pathSpec [string] required : Specify a path around which to build a full fileSystem path.
var pathath = anvil.fs.buildPath( "src/lib" );
Clean up a directory, and provide an optional onDeleted
callback to run on deletion.
- pathSpec [string] required : Path to directory being cleaned.
- onDeleted [function]: Optional callback to executed on successful deletion.
Copy a folder or file from the from
to the to
, and fire onComplete
when done.
- from [string] required : Path to directory or file being copied from.
- to [string] required: Path to directory or file being copied to.
- onComplete [function] required: Callback when copying is complete.
Copy a folder from the from
to the to
, and fire onComplete
when done. Actually calls anvil.fs.copyFile
for each file in the directory.
- from [string] required : Path to directory being copied from.
- to [string] required: Path to directory being copied to.
- onComplete [function] required: Callback when copying is complete.
Copy a file from the from
to the to
, and fire onComplete
when done.
- from [string] required : Path to file being copied from.
- to [string] required: Path to file being copied to.
-
onComplete [function] required: Callback when copying is complete. Passed the
to
argument originally passed in.
Delete file or directory defined by pathSpec
and fire the onDelete
callback when complete. Calls anvil.fs.deleteDirectory
or anvil.fs.deleteFile
depending on usage.
- pathSpec [string] required : Path to file or directory being deleted.
- onDelete [function] required: Callback when deleting is complete.
Delete file defined by pathSpec
and fire the onDelete
callback when complete.
- pathSpec [string] required : Path to file being deleted.
-
onDelete [function] required: Callback when deleting is complete. Passed an
error
argument.
Delete directory defined by pathSpec
and fire the onDelete
callback when complete.
- pathSpec [string] required : Path to directory being deleted.
- onDelete [function] required: Callback when deleting is complete.
Unlink a path specified by pathSpec
fires an optional onDelete
callback.
- pathSpec [string] required : Path to directory being deleted.
-
onDelete [function]: Callback when deleting is complete. Passed an
error
argument.
Checks for the existance of the pathSpec
, if not there, it will create the directory.
- pathSpec [string] required : Path to directory being inspected.
-
onDelete [function]: Callback when path has been created or inspected. Passed an
error
argument.
Recursively searches pathSpec
and builds a list a files, and directories which can be filtered by the filters
argument and the limited recursion by the limit
. The results are passed to onFiles
.
- pathSpec [string] required : Path to directory being inspected.
- workingPath [string] required : Path to directory being inspected.
-
onFiles [function] required: Callback when directory has been recursively searched. Passed
files
anddirectories
as arguments. - filters [array]: A list of the file extensions to filter out of the results.
- limit [number] : Limit the amount of recursion.
anvil.fs.getFiles( "src", "src", function( files, directories ) {
console.log( files, directories );
});
Create a symlink of from
to to
, and call the done
callback
- from [string] required : From destination of the symlink.
- to [string] required : To destination of the symlink.
- done [function]: Callback when symlink has been created.
Get metadata on a file from pathSpec
.
- pathSpec [string] required : File to retrieve metadata of.
- onStat [function] required: Callback when stats have been retrieved. Passed back an object with the stats.
Check if a the path given by pathSepc
exists. Will check sync with no callback
, and async with it.
- pathSpec [string] required : Folder to check if exists.
- callback [function]: Optional callback after checking the path.
var fileExists = anvil.fs.pathExists( "spec" );
Read the contents of a file from pathSpec
, and fire onContent
with the contents of the file.
- pathSpec [string] required : File to read.
-
onContent [function] required: Callback once the file is read. If successful, the
content
will be passed to the callback, if not successful, an empty string, and anerror
will be passed.
var contents = anvil.fs.read( "src/index.js", function( content, err ) {
if ( err ) {
anvil.log.error( "An error has occurred": + err );
}
// do something with content
});
Read the contents of a file from pathSpec
synchronously, and directly returns it.
- pathSpec [string] required : File to read.
var contents = anvil.fs.read( "src/index.js" );
// Do something with contents
Read the contents of a file from from
, and pass the contents to a function transform
. The transform function will operate on the contents and write the result to to
, and fire the onComplete
callback.
- from [string] required : File to read.
-
transform [function] required: An operation to run that will be passed the
content
of theto
file, and an callback function to execute that hasmodified
, anderror
arguments. - to [string] required : Once the file has been run through the transform function, it will be written here.
-
onComplete [function]: A callback function to be fired after the file has been transformed and written. Passed an
error
.
anvil.fs.transform( "./src/index.js", function( contents, done ) {
contents = contents.toLowerCase();
done( contents );
}, "./src/index.lc.js");
Watches a folder tree pathSpec
and fires the onEvent
callback when an event occurs.
- pathSpec [string] required : Folder tree to watch.
-
onEvent [function] required : A callback to execute when an event occurs. Passed an
event
object with the details of the event.
Write a file to pathSpec
with content
, and fire the onComplete or simply write the file out synchronously.
- pathSpec [string] required : File to write.
- content [string] required : Content to write.
-
onComplete [function] required : An optional callback to execute once the file is written. Passed an
error
.