How to use the node-dir.paths function in node-dir

To help you get started, we’ve selected a few node-dir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / content-and-experience-toolkit / sites / bin / document.js View on Github external
resourceName = inputPath;
				inputPath = '';
			}
		}
		// console.log('argv.folder=' + argv.folder + ' inputPath=' + inputPath + ' resourceName=' + resourceName);
		var folderPath = !argv.folder || argv.folder === '/' || !inputPath ? [] : inputPath.split(path.sep);
		if (folderName) {
			folderPath.push(folderName);
		}
		console.log(' - target folder: ' + (resourceFolder ? (resourceLabel + ' > ' + resourceName) : 'Documents') + ' > ' + folderPath.join(' > '));

		var rootParentFolderLabel = resourceFolder ? resourceName : 'Home folder';

		// get all files to upload
		var folderContent = [];
		dir.paths(srcPath, function (err, paths) {
			if (err) {
				console.log(err);
				return reject();
			} else {
				// the top level folder
				if (folderName) {
					folderContent.push({
						fileFolder: '',
						files: []
					});
				}
				// get all sub folders including empty ones
				var subdirs = paths.dirs;
				for (var i = 0; i < subdirs.length; i++) {
					var subdir = subdirs[i];
					subdir = subdir.substring(srcPath.length + 1);
github opencomponents / oc-template-react / packages / oc-template-react-compiler / __tests__ / compile.js View on Github external
compile(options, (err, result) => {
    if (err) {
      return fs.remove(options.publishPath, () => cb(err));
    }

    result.oc.date = "";
    result.oc.files.template.version = "";
    nodeDir.paths(options.publishPath, (err2, res2) => {
      const files = _.chain(res2.files)
        .map(filePath => {
          const source = fs.readFileSync(filePath, "UTF8");
          return {
            source: !filePath.match(/\.png$/)
              ? source.replace(/"date":\d+/, "")
              : "img-binary",
            path: path.relative(__dirname, filePath)
          };
        })
        .sortBy(["path", "source"])
        .value();
      fs.remove(options.publishPath, () => cb(err, { result, files }));
    });
  });
};
github grantcarthew / node-scalable-blob-store / tests / test-blob-bulk-create.js View on Github external
function recurse () {
      if (i < 1) {
        var endTime = moment()
        var runTime = endTime.diff(startTime)

        return nodeDir.paths(options.blobStoreRoot, (err, paths) => {
          if (err) { return reject(err) }
          var result = {
            'blobStoreRoot': options.blobStoreRoot,
            'idType': options.idType,
            'dirDepth': options.dirDepth,
            'dirWidth': options.dirWidth,
            'runTimeMilliseconds': runTime,
            'totalDirectories': paths.dirs.length,
            'totalFiles': paths.files.length,
            'totalBytes': readTotal
          }
          return resolve(result)
        })
      }
      var readStream = crispyStream.createReadStream(input)
github fireflylearning / pattern-library / src / lib / fileInfoOptions.js View on Github external
function checkIsBlock(dirPath, cb) {
    var hasFiles, hasSubDirs, directAncestorFiles = [],
        isBlock = false;

    dir.paths(dirPath, function(err, paths) {
        if (err) return cb(false);
        hasFiles = paths.files.length > 0;
        hasSubDirs = paths.dirs.length > 0;

        if (hasFiles) {
            if (!hasSubDirs) {
                directAncestorFiles = paths.files;
            } else {
                directAncestorFiles = _.reduce(paths.files, function(result, file, key) {
                    var test = file.replace(dirPath + path.sep, '').split(path.sep);
                    if (test.length === 1) result.push(file);
                    return result;
                }, []);
            }
        }
github oracle / content-and-experience-toolkit / sites / bin / site.js View on Github external
return new Promise(function (resolve, reject) {
		dir.paths(srcPath, function (err, paths) {
			if (err) {
				console.log(err);
				return resolve({
					err: 'err'
				});
			} else {
				try {
					if (paths.files.length === 0 && paths.dirs.length === 0) {
						console.log('ERROR: no file nor folder under ' + srcPath);
						return resolve({
							err: 'err'
						});
					}

					var buildDir = serverUtils.getBuildFolder(projectDir);
					if (!fs.existsSync(buildDir)) {
github opencomponents / oc / src / cli / domain / package-static-files / index.js View on Github external
const copyDir = function(params, cb){
  const staticPath = path.join(params.componentPath, params.staticDir),
    exists = fs.existsSync(staticPath),
    isDir = exists && fs.lstatSync(staticPath).isDirectory();

  if(!exists){
    return cb(format(strings.errors.cli.FOLDER_NOT_FOUND, staticPath));
  } else if(!isDir){
    return cb(format(strings.errors.cli.FOLDER_IS_NOT_A_FOLDER, staticPath));
  } else {

    nodeDir.paths(staticPath, (err, res) => {
      _.forEach(res.files, (filePath) => {

        const fileName = path.basename(filePath),
          fileExt = path.extname(filePath).toLowerCase(),
          fileRelativePath = path.relative(staticPath, path.dirname(filePath)),
          fileDestinationPath = path.join(params.publishPath, params.staticDir, fileRelativePath),
          fileDestination = path.join(fileDestinationPath, fileName);

        fs.ensureDirSync(fileDestinationPath);

        if(params.minify && params.ocOptions.minify !== false && (fileExt === '.js' || fileExt === '.css')){
          const fileContent = fs.readFileSync(filePath).toString(),
            minified = minifyFile(fileExt, fileContent);

          fs.writeFileSync(fileDestination, minified);
        } else {
github opencomponents / oc / src / registry / domain / s3.js View on Github external
const putDir = (dirInput, dirOutput, callback) => {
    nodeDir.paths(dirInput, (err, paths) => {
      async.each(
        paths.files,
        (file, cb) => {
          const relativeFile = file.substr(dirInput.length),
            url = (dirOutput + relativeFile).replace(/\\/g, '/');

          putFile(file, url, relativeFile === '/server.js', cb);
        },
        callback
      );
    });
  };
github opencomponents / oc-template-react / packages / oc-template-react-compiler / lib / to-be-published / compileStatics.js View on Github external
function copyDirectory(options, directoryName, callback) {
  const directoryPath = path.join(options.componentPath, directoryName);
  const directoryExists = fs.existsSync(directoryPath);
  const isDirectory =
    directoryExists && fs.lstatSync(directoryPath).isDirectory();

  if (!directoryExists) {
    return callback(strings.errors.folderNotFound(directoryPath));
  }
  if (!isDirectory) {
    return callback(strings.errors.folderNotValid(directoryPath));
  }

  nodeDir.paths(directoryPath, (err, res) => {
    _.forEach(res.files, filePath => {
      const fileName = path.basename(filePath);
      const fileExtension = path.extname(filePath).toLowerCase();
      const fileRelativePath = path.relative(
        directoryPath,
        path.dirname(filePath)
      );
      const fileDestinationPath = path.join(
        options.publishPath,
        directoryName,
        fileRelativePath
      );
      fs.ensureDirSync(fileDestinationPath);
      const fileDestination = path.join(fileDestinationPath, fileName);
      if (
        options.minify &&
github tjchaplin / mox / lib / mox.js View on Github external
var onEachSource = function(source,onComplete){

        if(!fs.lstatSync(source).isDirectory()){
            allSources.push(source);
            onComplete();
            return;
        }

        dir.paths(source, function(err, paths) {
            if (err) throw err;

            for (var i = 0; i < paths.files.length; i++) {
                allSources.push(paths.files[i]);
            }

            onComplete();
        });
    };

node-dir

asynchronous file and directory operations for Node.js

MIT
Latest version published 7 years ago

Package Health Score

70 / 100
Full package analysis