node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »



Build status

Make directory trees.
Clean option can be provided. You can use this both as gruntjs plugin and as a library for nodejs.


Install with npm:

npm install grunt-tree-prepare --save-dev


- as JavaScript library.

var emitter = require('grunt-tree-prepare')(tree, options)
emitter.on('error', ... ).on('end', ... );

- Use in your Gruntfile.js task with tree object.

module.exports = function(grunt) {
  // make directory tree below: 
  // process.cwd() 
  //  |- foo  -       <= create if not exist 
  //  |       |- var  <= create if not exist 
  //  |- hoge -       <= create if not exist 
  //          |- fuga <= cleanup and create new 
  grunt.config.set('tree-prepare', {
    tree: {
      'foo': ['var'],
      'hoge': { branch: 'fuga', clean: true }
  grunt.registerTask('default', ['tree-prepare']);


  • options(Object)
    "clean"(Boolean) default: false
    Setup clean default for directory.
    (not truely/falsy)
    "autoDone"(Boolean) default: true
    Flag for task end signal auto call.
    If specified false, "tree-prepare.end" event leads "done" argument as an first argument to grunt.event. See test/basic.js.

  • tree(Object)
    "(Object key)(String)"
    Relative path from parent directory. Parent of tree is process.cwd().
    Create directories with the same status included in the object that belongs.
    "chmod(Number|String)" default: 777 //TODO
    Set directory mode. String representation (e.g. "rw-rw-rw-" as 666) can be given.
    "clean(Boolean)" default: false | options.clean
    Crean up ( use rimraf ) directory contents and itself, create new.