How to use fast-glob - 10 common examples

To help you get started, we’ve selected a few fast-glob 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 somewhatabstract / checksync / src / get-files.js View on Github external
export default async function getFiles(
    includeGlobs: Array,
    excludeGlobs: Array,
    log: ILog,
): Promise> {
    const includePatterns = Array.from(turnIgnoresToGlobs(includeGlobs));
    log.verbose(
        () => `Include globs: ${JSON.stringify(includePatterns, null, "    ")}`,
    );
    const excludePatterns = Array.from(turnIgnoresToGlobs(excludeGlobs));
    log.verbose(
        () => `Exclude globs: ${JSON.stringify(excludePatterns, null, "    ")}`,
    );

    // Now let's match the patterns and see what files we get.
    const paths = await glob(includePatterns, {
        onlyFiles: true,
        absolute: true,
        ignore: excludePatterns,
    });
    const sortedPaths = paths.sort();
    log.verbose(
        () => `Discovered paths: ${JSON.stringify(sortedPaths, null, "    ")}`,
    );
    return sortedPaths;
}
github sourcegraph / sourcegraph-typescript / src / server / resources.ts View on Github external
public async *glob(pattern: URL, { ignore = [] }: GlobOptions = {}): AsyncIterable {
        const files = glob.stream(fileURLToPath(pattern), {
            ignore,
            absolute: true,
            markDirectories: true,
            onlyFiles: false,
        })
        // tslint:disable-next-line: await-promise https://github.com/palantir/tslint/issues/3997
        for await (const file of files) {
            yield pathToFileURL(file as string)
        }
    }
github WordPress / gutenberg / bin / packages / build.js View on Github external
stream = new Readable( { encoding: 'utf8' } );
	files.forEach( ( file ) => stream.push( file ) );
	stream.push( null );
	stream = stream
		.pipe( createStyleEntryTransform() )
		.pipe( createBlockJsonEntryTransform() );
} else {
	const bar = new ProgressBar( 'Build Progress: [:bar] :percent', {
		width: 30,
		incomplete: ' ',
		total: 1,
	} );

	bar.tick( 0 );

	stream = glob.stream( [
		`${ PACKAGES_DIR }/*/src/**/*.js`,
		`${ PACKAGES_DIR }/*/src/*.scss`,
	], {
		ignore: [
			`**/test/**`,
			`**/__mocks__/**`,
		],
		onlyFiles: true,
	} );

	// Pause to avoid data flow which would begin on the `data` event binding,
	// but should wait until worker processing below.
	//
	// See: https://nodejs.org/api/stream.html#stream_two_reading_modes
	stream
		.pause()
github atomist / automation-client / lib / project / local / NodeFsLocalProject.ts View on Github external
const toFileTransform = new stream.Transform({ objectMode: true });

        toFileTransform._transform = function(chunk: any, encoding: string, done: (e?: any) => void): void {
            const f = new NodeFsLocalFile(baseDir, chunk);
            this.push(f);
            done();
        };

        const optsToUse: fg.Options = {
            // We can override these defaults...
            onlyFiles: true,
            ...opts,
            // ...but we force this one
            cwd: this.baseDir,
        };
        return fg.stream(globPatterns, optsToUse)
            .pipe(toFileTransform);
    }
github stoplightio / spectral / test-harness / codegen / index.ts View on Github external
(async () => {
  const stream = fg.stream('**/*.scenario', { cwd: SCENARIOS_ROOT });

  for await (const entry of stream) {
    const scenarioPath = join(SCENARIOS_ROOT, entry as string);
    const source = await fs.promises.readFile(scenarioPath, 'utf8');
    const scenario = parseScenarioFile(source);
    const assets = scenario.assets === void 0 ? [] : await writeAssets(entry as string, scenario.assets);

    const testFilename = `${basename(entry as string, true)}.test.ts`;
    const testRoot = await getDirectory(entry as string, TESTS_ROOT);

    const code = generate({
      assets,
      scenario,
      scenarioName: entry as string,
    });
github mrmlnc / fast-glob / src / benchmark / suites / regression / stream / fast-glob-previous.ts View on Github external
import * as fg from 'fast-glob';

import * as utils from '../../../utils';

const options: fg.Options = {
	cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
	unique: false,
	...JSON.parse(process.env.BENCHMARK_OPTIONS as string)
};

const entries: string[] = [];

const timeStart = utils.timeStart();

const stream = fg.stream(process.env.BENCHMARK_PATTERN as string, options);

stream.once('error', () => process.exit(0));
stream.on('data', (entry: string) => entries.push(entry));
stream.once('end', () => {
	const memory = utils.getMemory();
	const time = utils.timeEnd(timeStart);
	const measures = utils.formatMeasures([...entries].length, time, memory);

	console.info(measures);
});
github airbnb / lunar / scripts / convertMarkdownToStories.js View on Github external
});

    story.unshift(createHeader(packageName, componentName, imports));

    return fs.writeFile(storyPath, story.join(''), 'utf8').then(() => fs.remove(filePath));
  });
}

const cwd = process.argv[2];

if (!cwd) {
  console.error(chalk.red('Please provide a folder path to convert.'));
  process.exit(1);
}

glob
  .async('**/components/*/README.md', {
    absolute: true,
    cwd: path.join(process.cwd(), cwd),
    ignore: ['node_modules'],
  })
  .then(filePaths => Promise.all(filePaths.map(filePath => convertToStory(String(filePath)))));
github astroboy-lab / astroboy / loader / AstroboyControllerLoader.js View on Github external
load() {
    const app = this.app;
    let controllers = {};
    const entries = glob.sync([`${app.ROOT_PATH}${this.config.pattern}`], {
      dot: true,
    });
    entries
      .filter(i => !i.includes('.d.ts'))
      .forEach(entry => {
        const key = this.resolveExtensions(entry.split('controllers/')[1], true);
        controllers[key] = require(entry);
      });
    app.controllers = controllers;
  }
}
github youzan / vant / packages / vant-cli / src / compiler / gen-site-desktop-shared.ts View on Github external
docs.push({
          name: formatName(component, lang),
          path: join(SRC_DIR, component, fileName)
        });
      });
    });
  } else {
    components.forEach(component => {
      docs.push({
        name: formatName(component),
        path: join(SRC_DIR, component, 'README.md')
      });
    });
  }

  const staticDocs = glob.sync(join(DOCS_DIR, '**/*.md')).map(path => {
    const pairs = parse(path).name.split('.');
    return {
      name: formatName(pairs[0], pairs[1] || defaultLang),
      path
    };
  });

  return [...staticDocs, ...docs.filter(item => existsSync(item.path))];
}
github airbnb / lunar / scripts / tasks / generateIcon.ts View on Github external
export default withIcon('${compName}')(${compName});`,
        'utf8',
        error => {
          if (error) {
            reject(error);
          } else {
            console.log(`Generated ${compName}`);
            resolve();
          }
        },
      );
    });
  });
}

glob(filePattern, {
  absolute: true,
  cwd: SVG_ROOT,
})
  .then(svgPaths => Promise.all(svgPaths.map(svgPath => createIcon(svgPath))))
  .catch(error => {
    console.error(chalk.red(`Failed to generate icons: ${error.message}`));
    process.exitCode = 1;
  });

fast-glob

It's a very fast and efficient glob library for Node.js

MIT
Latest version published 1 year ago

Package Health Score

83 / 100
Full package analysis