How to use readdirp - 10 common examples

To help you get started, we’ve selected a few readdirp 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 adobe / jsonschema2md / test / testUtils.js View on Github external
async function loadschemas(dir) {
  const schemaloader = loader();
  const schemadir = path.resolve(__dirname, 'fixtures', dir);
  const schemas = await readdirp.promise(schemadir, { fileFilter: '*.schema.json' });


  return traverse(schemas
    .map(({ fullPath }) => schemaloader(
      // eslint-disable-next-line global-require, import/no-dynamic-require
      require(fullPath), fullPath,
    )));
}
github alibaba / funcraft / lib / nas / path.js View on Github external
async function readDirRecursive(dirPath) {
  const files = await readdirp.promise(dirPath, { type: 'files' });
  const dirs = await readdirp.promise(dirPath, { type: 'directories' });

  const relativePaths = [];
  // windows 下需要将压缩文件路径住转换为 POXIS 路径
  if (process.platform === 'win32') {
    files.map(file => relativePaths.push((file.path).split(path.sep).join('/')));
    for (let dir of dirs) {
      if (await isEmptyDir(dir.fullPath)) {
        relativePaths.push(`${(dir.path).split(path.sep).join('/')}/`);
      }
    }
  } else {
    files.map(file => relativePaths.push(file.path));
    for (let dir of dirs) {
      if (await isEmptyDir(dir.fullPath)) {
        relativePaths.push(`${dir.path}/`);
github paulmillr / readdirp / examples / types.ts View on Github external
const read = async (directory: string) => {
  const stream = readdirp(directory, { type: 'all' });
  let i = 0;
  for await (const chunk of stream) {
    // Check memory usage with this line. It should be 10MB or so.
    // Comment it out if you simply want to list files.
    await new Promise(resolve => setTimeout(resolve, 500));
    console.log(`${++i}: ${chunk.path}`);
  }
  console.log('Stream done', i);

  const entries = await readdirp.promise(directory);
  console.log('Promise done', entries.map(e => e.path));
};
github paulmillr / readdirp / examples / types.ts View on Github external
const read = async (directory: string) => {
  const stream = readdirp(directory, { type: 'all' });
  let i = 0;
  for await (const chunk of stream) {
    // Check memory usage with this line. It should be 10MB or so.
    // Comment it out if you simply want to list files.
    await new Promise(resolve => setTimeout(resolve, 500));
    console.log(`${++i}: ${chunk.path}`);
  }
  console.log('Stream done', i);

  const entries = await readdirp.promise(directory);
  console.log('Promise done', entries.map(e => e.path));
};
github oaeproject / Hilary / packages / oae-ui / lib / api.js View on Github external
const cacheWidgetManifests = function(done) {
  widgetManifestCache = {};

  readdirp(
    // Cache all of the widget config files under packages
    path.join(uiDirectory, 'packages'),
    {
      // Only recurse in folders that contain widgets
      directoryFilter: _widgetDirectoryFilter,

      // We're only interested in the manifest files
      fileFilter: 'manifest.json'
    }
  )
    .on('data', entry => {
      // Extract the widget id from the path
      const widgetId = entry.path
        .split(path.sep)
        .splice(1, 1)
        .join();
github ananas-analytics / ananas-desktop / ui / src / common / model / MetadataLoader.js View on Github external
loadFromDir(dir: string) :Promise<{[string]: PlainNodeMetadata}> {
    return readdirp.promise(dir, {
      fileFilter: ['*.yaml', '*.yml'],
    }) 
    .then(entries => {
      let tasks = entries.map(entry => {
        return util.promisify(fs.readFile)(entry.fullPath) 
      })
      // FIXIT: Promise.all fails when one task fails
      return Promise.all(tasks)
    })
    .then(contents => {
      let output = {}
      contents.map(content => {
        return YAML.parse(content.toString())
      })
      .forEach(meta => {
        output = { ... output, ... meta }
github jeffbski / pkglink / src / link.js View on Github external
const dstPackInode = lnkModSrcDst.dstPackInode;
  const dstPackMTimeEpoch = lnkModSrcDst.dstPackMTimeEpoch;

  if (updatePackRefs) {
    let packRefs = rtenv.updatedPackRefs[devNameVer] || [];
    if (!packRefs.length) {
      packRefs.push(buildPackRef(srcRoot, srcPackInode, srcPackMTimeEpoch));
    }
    packRefs = packRefs.filter(packRef => packRef[0] !== dstRoot);
    if (packRefs.length < config.refSize) {
      packRefs.push(buildPackRef(dstRoot, dstPackInode, dstPackMTimeEpoch));
    }
    rtenv.updatedPackRefs[devNameVer] = packRefs;
  }

  const fstream = readdirp({
    root: lnkModSrcDst.src,
    entryType: 'files',
    lstat: true,  // want actual files not symlinked
    fileFilter: ['!.*'],
    directoryFilter: ['!.*', '!node_modules']
  });
  fstream.once('end', () => {
    rtenv.completedPackages += 1;
    logUpdate();
  });
  rtenv.cancelled$.subscribe(() => fstream.destroy()); // stop reading

  return Observable.fromEvent(fstream, 'data')
                   .takeWhile(() => !rtenv.cancelled)
                   .takeUntil(Observable.fromEvent(fstream, 'close'))
                   .takeUntil(Observable.fromEvent(fstream, 'end'))
github hashicorp / boundary / website / components / temporary_docs-page / server.js View on Github external
return new Promise((resolve) => {
    const fm = []
    readdirp(p, { fileFilter: '*.mdx' })
      .on('data', (entry) => {
        let lineNum = 0
        const content = []
        fm.push(
          new Promise((resolve2, reject2) => {
            lineReader.eachLine(
              entry.fullPath,
              (line) => {
                // if it has any content other than `---`, the file doesn't have front matter, so we close
                if (lineNum === 0 && !line.match(/^---$/)) return false
                // if it's not the first line and we have a bottom delimiter, exit
                if (lineNum !== 0 && line.match(/^---$/)) return false
                // now we read lines until we match the bottom delimiters
                content.push(line)
                // increment line number
                lineNum++
github jeffbski / pkglink / src / find-packages.js View on Github external
startDir => {
      const readdirpOptions = {
        root: startDir,
        entryType: 'files',
        lstat: true,  // want actual files not symlinked
        fileFilter: ['package.json'],
        directoryFilter: filterDirsNodeModPacks
      };
      if (config.treeDepth) { readdirpOptions.depth = config.treeDepth; }
      const fstream = readdirp(readdirpOptions);
      rtenv.cancelled$.subscribe(() => fstream.destroy()); // stop reading
      return Observable.fromEvent(fstream, 'data')
                       .takeWhile(() => !rtenv.cancelled)
                       .takeUntil(Observable.fromEvent(fstream, 'close'))
                       .takeUntil(Observable.fromEvent(fstream, 'end'));
    },
    config.concurrentOps
github NativeScript / NativeScript / build / clear-private-definitions.ts View on Github external
let blockCommentPrivate = /\/\*\*([^](?!\*\/))*@module([^](?!\*\/))*@private[^]*?\*\//g;
    if (blockCommentPrivate.test(content)) {
        return { shouldDelete: true };
    }

    let newContent = content;
    newContent = newContent.replace(/\/\/[\/\s]*@private[^]*?\/\/[\/\s]*?@endprivate/gm, "");

    if (newContent !== content) {
        return { shouldReplace: true, newContent: newContent };
    }

    return { shouldReplace: false, shouldDelete: false };
}

readdirp(inputFolder, {
    fileFilter: ["*.d.ts"],
    directoryFilter: function (di) { return !di.path.includes("node_modules"); }
}).on("data", (entry: EntryInfo) => {
    const { fullPath } = entry;
    const content = fs.readFileSync(fullPath, "utf8");
    const { shouldDelete, shouldReplace, newContent } = filterTypeScriptFiles(content);

    if (shouldDelete) {
        console.log("[Delete]", fullPath);
        fs.unlinkSync(fullPath);
    } else if (shouldReplace) {
        console.log("[Cleared]", fullPath);
        try {
            fs.writeFileSync(fullPath, newContent, "utf8");
        } catch (error) {
            console.log("ERROR writing file: " + fullPath, error);

readdirp

Recursive version of fs.readdir with streaming API.

MIT
Latest version published 3 months ago

Package Health Score

86 / 100
Full package analysis

Popular readdirp functions