How to use the readdirp.promise function in readdirp

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 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 netlify / build / packages / build / src / plugins / functions / index.js View on Github external
const logResults = async function(FUNCTIONS_DIST) {
  const files = await readdirp.promise(FUNCTIONS_DIST)

  if (files.length === 0) {
    console.log('No functions were packaged')
    return
  }

  const paths = files.map(getLoggedPath)
  console.log(`Functions packaged in ${FUNCTIONS_DIST}
${serializeList(paths)}`)
}
github netlify / build / packages / build / src / plugins_core / functions.js View on Github external
const logResults = async function(FUNCTIONS_DIST) {
  const files = await readdirp.promise(FUNCTIONS_DIST)

  if (files.length === 0) {
    console.log('No functions were packaged')
    return
  }

  const paths = files.map(getLoggedPath)
  console.log(`Functions packaged in ${FUNCTIONS_DIST}
${serializeList(paths)}`)
}
github hashicorp / boundary / website / components / temporary_docs-page / server.js View on Github external
export async function getStaticMdxPaths(root) {
  const files = await readdirp.promise(root, { fileFilter: ['*.mdx'] })

  return files.map(({ path: p }) => {
    return {
      params: {
        page: p
          .replace(/\.mdx$/, '')
          .split('/')
          .filter((p) => p !== 'index'),
      },
    }
  })
}
github riyacchi / chariot.js / structures / ChariotClient.js View on Github external
async _registerChariotEvents() {
        const directory = path.dirname(require.main.filename);
        const readFiles = await readdirp.promise(directory, { fileFilter: '*.js', directoryFilter: ['!.git', '!*modules'] });

        this.eventFiles = readFiles.map(file => file.path);

        for (const chariotEventFile of this.eventFiles) {
            const chariotEvent = require(path.join(directory, chariotEventFile));

            chariotEvent.client = this;

            if (chariotEvent instanceof Event) {
                if (!Constants.EVENTS.EVENT_NAMES.includes(chariotEvent._eventName)) {
                    throw new Error(`Unknown event called "${chariotEvent._eventName}" in file "${chariotEventFile}". Event names are case sensitive! Check https://abal.moe/Eris/docs/Client for an event overview.`)
                }

                if (typeof chariotEvent.execute === 'undefined') {
                    throw new Error(`Couldn't find main executor "execute" in event file "${chariotEventFile}"!`);
                }
github netlify / build / packages / cache-utils / src / hash.js View on Github external
const hashDir = async function(dirPath, fileStat, base) {
  const files = await readdirp.promise(dirPath, { fileFilter, alwaysStat: true })
  const dirHashInfo = getHashInfo(dirPath, fileStat, base)
  const hashInfos = await pMap(files, ({ fullPath, stats }) => getFileInfo(fullPath, stats, base), {
    concurrency: MAX_CONCURRENCY,
  })
  const hash = await computeHash([dirHashInfo, ...hashInfos])
  return hash
}

readdirp

Recursive version of fs.readdir with streaming API.

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular readdirp functions