How to use the node-dir.readFiles 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 SilentCicero / wafr / src / utils / index.js View on Github external
dir.files(dirname, (filesError, files) => {
    if (filesError) {
      throwError(`while while getting input sources ${filesError}`);
    }

    // if no files in directory, then fire callback with empty sources
    if (files.length === 0) {
      callback(null, sources);
    } else {
      // read all files
      dir.readFiles(dirname, (readFilesError, content, filename, next) => {
        if (readFilesError) {
          throwError(`while getting input sources ${readFilesError}`);
        }

        // parsed filename
        const parsedDirName = dirname.replace('./', '');
        const parsedFileName = filename.replace(parsedDirName, '').replace(/^\//, '');
        const onlyFilename = filename.substr(filename.lastIndexOf('/') + 1);

        // add input sources to output
        if (filename.substr(filename.lastIndexOf('.') + 1) === 'sol'
          && filenameInclude(filename, exclude, include)
          && onlyFilename.charAt(0) !== '~'
          && onlyFilename.charAt(0) !== '#'
          && onlyFilename.charAt(0) !== '.') {
          sources[parsedFileName] = content;
github washingtonpost / ans-schema / tests / schema-tests-010.js View on Github external
it("should load all schemas into an object", function(done) {

      dir.readFiles(
        baseDir, {
          match:  /.json$/
        },
        function(err, content, filename, next) {
          if (err) throw err;
          var name = path.relative(baseDir, filename);
          loadedFiles[name] = content;
          next();
        },
        function(err, files) {
          if (err) {
            console.log(err);
            throw err;
          }

          var keys = Object.keys(loadedFiles);
github washingtonpost / ans-schema / tests / schema-tests-07.js View on Github external
it("should load all schemas into an object", function(done) {

      dir.readFiles(
        baseDir, {
          match:  /.json$/
        },
        function(err, content, filename, next) {
          if (err) throw err;
          var name = path.relative(baseDir, filename);
          loadedFiles[name] = content;
          next();
        },
        function(err, files) {
          if (err) {
            console.log(err);
            throw err;
          }

          var keys = Object.keys(loadedFiles);
github washingtonpost / ans-schema / tests / schema-tests-04.js View on Github external
before(function(done) {
        fixtures = {};
        dir.readFiles(
          path.join(path.dirname(module.filename), 'fixtures/schema/' + version),
          function(err, content, filename, next) {
            if (err) throw err;

            fixtures[path.basename(filename, '.json')] = JSON.parse(content);
            next();
          },
          function(err, files) {
            if (err) throw err;
            done();
          }
        );
      });
github limedocs / limedocs-wiki-converter / src / finder.js View on Github external
return new Promise(function(resolve, reject) {

      var mdFiles = {},
          aliases = {},
          dirOpts = { match: /.md/, exclude: /^_/ }

      dir.readFiles(wikiPath, dirOpts, function (err, content, filename, next) {
          if (!err) {
            mdFiles[filename] = content
            var base = path.basename(filename)
            aliases[base.substr(0, base.length - 3)] = filename
          }
          next()
        },
        function (err, files) {
          if (err) {
            return reject(err)
          }
          logger.debug(
            util.format(
              'Found %d markdown files and %d links pointing to them in TOC',
              Object.keys(mdFiles).length,
              Object.keys(aliases).length
github geekwen / hexo-local-admin / module / get-all-data.js View on Github external
function getMdFiles(dirPath, match, callback) {
    let data = [];

    DIR.readFiles(dirPath, match || {match: /.md$/},
        function (err, content, filename, next) {
            if (err) throw err;
            data.push(EXTEND(parseFileContent(filename, content), {page_url: filename.replace(/^.*source\//g, '')}));
            next();
        },
        function (err, files) {
            if (err) throw err;
            callback(data.sort(sortListFromNewToOld));
        });
}
github codius / codius / src / common / codius-state.js View on Github external
const files = await new Promise((resolve, reject) => {
    nodeDir.readFiles(process.cwd(), {
      match: /\.codiusstate\.json$/, recursive: false
    }, (err, content, next) => {
      if (err) throw err
      next()
    }, (err, files) => {
      if (err) reject(err)
      resolve(files)
    })
  })
github jsreport / jsreport / extension / express / lib / routes.js View on Github external
async.eachSeries(paths, function (p, icb) {
            dir.readFiles(p, function (err, content, filePath, nextFile) {
                if (content.charAt(0) === '\uFEFF')
                    content = content.substr(1);

                var filename = path.basename(filePath, '.html');

                if (options.studio !== "embed" || S(filename).startsWith("embed")) {
                    templates.push({
                        name: filename,
                        content: content
                    });
                }
                nextFile();
            }, function () {
                icb();
            });
        }, function () {
github facebook / react-native / website / react-docgen / bin / react-docgen.js View on Github external
function traverseDir(path, result, done) {
  dir.readFiles(
    path,
    {
      match: extensions,
      excludeDir: ignoreDir
    },
    function(error, content, filename, next) {
      if (error) {
        exitWithError(error);
      }
      try {
        result[filename] = parser.parse(content);
      } catch(error) {
        writeError(error, path);
      }
      next();
    },

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