make directory recursively. Sync version

@function mkdirSyncRecursive
@param {String} root - absolute root where append chunks
@param {Array} chunks - directories chunks
@param {Number} mode - directories mode, see Node documentation
@return [{Object}]
350831
function mkdirSyncRecursive(root, chunks, mode) {

  var chunk = chunks.shift();
  if (!chunk) {
    return;
  }
  var root = path.join(root, chunk);

  if (fs.existsSync(root) === true) { // already done
    return mkdirSyncRecursive(root, chunks, mode);
  }
  var err = fs.mkdirSync(root, mode);
  return err ? err : mkdirSyncRecursive(root, chunks, mode); // let's magic
}
33395
function getFoldersRecursive (folder) {
    var fileContents = fs.readdirSync(folder),
        stats,
        folders = [];

    fileContents.forEach(function (fileName) {
        stats = fs.lstatSync(folder + '/' + fileName);

        if (stats.isDirectory()) {
          folders.push(folder + '/' + fileName);
          folders = folders.concat(getFoldersRecursive(folder + '/' + fileName));
        }
    });

    return folders;
}
1228949
function listDirSync (path, originalPath) {
  if (!originalPath) {
    originalPath = path + separator;
  }

  var list = [];

  var files = fs.readdirSync(path);

  files.forEach(function (file) {
    var absolutePath = join(path, file);

    var isDirectory = fs.statSync(absolutePath).isDirectory();

    // if directory, read it
    // and merge results
    if (isDirectory) {
      var subList = listDirSync(absolutePath, originalPath);

      list = list.concat(subList);

      return;
    }

    // return relative paths
    var relativePath = absolutePath.replace(originalPath, '');

    list.push(relativePath);
  });

  return list;
}
1078817
function readDirSync (dir, allFiles = []) {
  const files = fs.readdirSync(dir).map(f => join(dir, f))
  allFiles.push(...files)
  files.forEach(f => {
    fs.statSync(f).isDirectory() && readDirSync(f, allFiles)
  })
  return allFiles
}
350177
async function makeDir(dir) {
    const res = await makePromise(fs.mkdir, dir, dir)
    return res
}
971863
function mkdirSync (path) {
  const dir = Path.resolve(path)
  if (existsSync(dir)) {
    return true
  }

  Fs.mkdirSync(dir)
  return existsSync(dir)
}
907476
function recursiveMkDir(dir) {
    if (!fs.existsSync(dir)) {
        recursiveMkDir(path.dirname(dir));
        fs.mkdirSync(dir);
    }
}
159023
function writeDirectories(result) {
  var deferred = q.defer();
  util.mkdir(result.root)
    .then(function() {return util.mkdir(result.template);})
    .then(function() {return util.mkdir(result.data);})
    .then(function() {return util.mkdir(result.output);})
    .then(function() {return util.mkdir(result.js);})
    .then(function() {return util.mkdir(result.css);})
    .fail(function(err) {
      deferred.reject(new Error(err));
    })
    .done(function(result) {
      deferred.resolve();
    });
  return deferred.promise;
}
188806
function fsReaddirSync(root, files, fp) {
  if (typeof root !== 'string') {
    throw new TypeError('fsReaddir.sync: expect `root` to be string');
  }

  fp = fp || '';
  files = files || [];

  var dir = path.join(root, fp);
  if (fs.statSync(dir).isDirectory()) {
    fs.readdirSync(dir).forEach(function(name) {
      fsReaddirSync(root, files, path.join(dir, name));
    });
  } else {
    files.push(fp);
  }

  return files;
}
637768
function _resyncList() {
  var listKey = this.listKey;
  var parentPath = this.parentPath;
  if (!listKey || !parentPath) return;

  var newContainer = parentPath.node[listKey];
  if (this.container === newContainer) return;

  // container is out of sync. this is likely the result of it being reassigned

  if (newContainer) {
    this.container = newContainer;
  } else {
    this.container = null;
  }
}
894374
function recursiveReaddirSync(path) {
  var list = []
    , files = fs.readdirSync(path)
    , stats
    ;

  files.forEach(function (file) {
    stats = fs.lstatSync(p.join(path, file));
    if(stats.isDirectory()) {
      list = list.concat(recursiveReaddirSync(p.join(path, file)));
    } else {
      list.push(p.join(path, file));
    }
  });

  return list;
}
462413
function traverseRecursiveSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  (function visitNode(node) {
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      visitNode(subnodes[i]);
    }
    options.onNode(node, options.userdata);
  })(rootNode);

  return rootNode;
}
919074
function allJasmineJsFiles(rootDir) {
  var files = [];
  fs.readdirSync(rootDir).filter(function(filename) {

    var fullPath = rootDir + "/" + filename;
    if (fs.statSync(fullPath).isDirectory() && !fullPath.match(/pages/)) {
      var subDirFiles = allJasmineJsFiles(fullPath);
      if (subDirFiles.length > 0) {
        files = files.concat();
        return true;
      }
    } else {
      if (fullPath.match(/\.js$/) && !isExcluded(fullPath)) {
        files.push(fullPath);
        return true;
      }
    }
    return false;
  });

  return files;
}
208690
function mkdirRecursive(dir) {
  var parts = path.normalize(dir).split(path.sep);
  dir = '';
  for (var i = 0; i < parts.length; i++) {
    dir += parts[i] + path.sep;
    if (!existsSync(dir)) {
      fs.mkdirSync(dir, 0x1FD); // 0775 permissions
    }
  }
}
1068008
function _mkdirp (directory, mode, callback) {

			if ("undefined" === typeof directory) {
				throw new ReferenceError("missing \"directory\" argument");
			}
				else if ("string" !== typeof directory) {
					throw new TypeError("\"directory\" argument is not a string");
				}
				else if ("" === directory.trim()) {
					throw new Error("\"directory\" argument is empty");
				}
			else if ("undefined" !== typeof callback && "number" !== typeof mode) {
				throw new TypeError("\"mode\" argument is not a number");
			}
			else if ("undefined" === typeof callback && "undefined" === typeof mode) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof mode) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				let _callback = callback;
				let _mode = mode;

				if ("undefined" === typeof _callback) {
					_callback = mode;
					_mode = DEFAULT_OPTION;
				}

				isDirectoryProm(directory).then((exists) => {

					return exists ? Promise.resolve() : Promise.resolve().then(() => {

						const SUB_DIRECTORY = dirname(directory);

						return isDirectoryProm(SUB_DIRECTORY).then((_exists) => {

							return _exists ? new Promise((resolve, reject) => {

								mkdir(directory, _mode, (err) => {
									return err ? reject(err) : resolve();
								});

							}) : new Promise((resolve, reject) => {

								_mkdirp(SUB_DIRECTORY, _mode, (err) => {

									return err ? reject(err) : mkdir(directory, _mode, (_err) => {
										return _err ? reject(_err) : resolve();
									});

								});

							});

						});

					});

				}).then(() => {
					_callback(null);
				}).catch(callback);

			}

		}
111946
function copyFromDir(starter, root) {
  if (!fs.existsSync(starter)) {
    throw new Error(`starter ${starter} doesn't exist`);
  }

  // Chmod with 755.
  // 493 = parseInt('755', 8)
  return fs.mkdirp(root, {mode: 493}).then(() => {
    console.log(
      `Creating new theme from local starter: ${chalk.green(starter)}`,
    );
    return fs.copy(starter, root, {
      filter: (file) =>
        !/^\.(git|hg)$/.test(path.basename(file)) && !/node_modules/.test(file),
    });
  });
}
422875
function createDirectory(dir) {
    if (!fs.existsSync(dir)) {
        dryRun ? console.log(`...CREATE the '${dir}' folder.`) : fs.mkdirSync(dir);
    }
}