fs-tree
Builds hierarchies of directories and files
Last updated 5 years ago by refractalize .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fs-tree 
SYNC missed versions from official npm registry.

fs-tree

Builds a hierarchy of directories and files as a single asynchronous operation.

Install

npm install fs-tree

Usage

fsTree = require 'fs-tree'

fsTree! {
  ideas = {
    colours = {
      "green.txt" = "apples, pears"
      "white.txt" = "snow"
    }
  }
}

...creates these directories and files:

./ideas/
./ideas/colours/
./ideas/colours/green.txt  (apples, pears)
./ideas/colours/white.txt  (snow)

Each entry can be a string, a Buffer or a node stream (anything that has a .pipe() method).

The root directory

By default the hierarchy is created in the current working directory.

Make a hierarchy under another directory like this:

fsTree! '/your/root/directory' {
  subdir = {
    file = "contents"
  }
}

Deleting the files you created

Retain a reference to the original tree to destroy it later:

tree = fsTree! {
  subdir = {
    file = "contents"
  }
}

// then later...
tree.destroy()!

Destroying the tree is equivalent to

rm -rf <root directory>

JavaScript?

The examples above are in PogoScript because it's pretty. There is no dependency on PogoScript, so you can use pure JavaScript if you prefer. It returns a promise:

var fsTree = require('fs-tree');

fsTree({
  ideas: {
    colours: {
      "green.txt": "apples, pears",
      "white.txt": "snow"
    }
  }
}).then(function() {
  console.log("Tree created!");
}, function (error) {
  console.log("uh oh", error);
});

License

BSD

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

4 Versions

  • 1.0.0                                ...           5 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.1                                ...           7 years ago
Downloads
Today 0
This Week 1
This Month 4
Last Day 0
Last Week 0
Last Month 8
Dependencies (2)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |