How to use the tiny-glob function in tiny-glob

To help you get started, we’ve selected a few tiny-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 MarcusCemes / responsive-image-builder / src / Preparation.ts View on Github external
public async cleanOutput() {
    if (!(await pathExists(this.config.out))) {
      await ensureDir(this.config.out);
    } else if (this.config.cleanBeforeExport) {
      // Don't require prompt if force is true
      if (!this.config.force) {
        // Scan the output directory for important files, and prompt confirmation if yes
        if (this.terminal) {
          this.terminal.update({ text: `${DynamicTerminal.SPINNER} Checking output directory` });
        }

        // tiny-glob works with UNIX-style paths, even on Windows
        const cwd = isAbsolute(this.config.out) && platform() !== "win32" ? "/" : "";
        const files = await glob(posix.join(this.config.out, "/**/*"), {
          absolute: true,
          filesOnly: true,
          cwd
        });
        const knownExtensions = SUPPORTED_EXTENSIONS.map(ext => `.${ext}`).concat(".json");

        for (const file of files) {
          if (
            knownExtensions.indexOf(posix.parse(file).ext) === -1 &&
            !RegExp(/.rib-[0-9a-zA-Z]*/).test(file)
          ) {
            // Unknown file extension found, prompt clean
            if (this.terminal) {
              await this.terminal.stop(false);
              this.terminal.destroy(); // Worker would block program termination
            }
github smooth-code / smooth.js / packages / smooth / src / graphql / schema / index.js View on Github external
export async function getDefinitionModules({ config }) {
  const schemasExists = await exists(config.schemasPath)
  if (!schemasExists) return []
  const files = await glob('**/*.js', { cwd: config.schemasPath })
  const defs = files.map(relativePath => {
    const absolutePath = path.join(config.schemasPath, relativePath)
    if (!config.cache) {
      delete require.cache[absolutePath]
    }
    // eslint-disable-next-line global-require, import/no-dynamic-require
    return babelRequire(absolutePath)
  })

  return defs
}
github MarcusCemes / responsive-image-builder / src / Preparation.ts View on Github external
result.error = `Not enough permissions to read the directory "${dir}"`;
        return result;
      }
    }

    this.update(line, DynamicTerminal.SPINNER + " Searching for images");

    // tiny-glob requires forward slashes
    // resolve all supported files and append them to the files array as a File object
    for (const dir of this.config.in) {
      try {
        if ((await stat(dir)).isFile()) {
          result.files.push({ base: posix.parse(dir).dir, path: dir });
        } else {
          const cwd = isAbsolute(dir) && platform() !== "win32" ? "/" : "";
          const files = await glob(
            posix.join(dir, "/**/*.{" + SUPPORTED_EXTENSIONS.join(",") + "}"),
            { absolute: true, cwd }
          );
          result.files.push(...files.map(p => ({ base: dir, path: cleanUpPath(p) })));
        }
        this.update(
          line,
          DynamicTerminal.SPINNER + " Searching for images (found " + result.files.length + ")"
        );
      } catch (err) {
        this.update(line, DynamicTerminal.CROSS + " Failed to search for images");
        result.error = "Failed to search for images\n" + chalk.white(err.message || err);
        return result;
      }
    }
github kaisermann / svelte-i18n / src / cli / index.ts View on Github external
.action(async (globStr, output, { shallow, overwrite, config }) => {
    const filesToExtract = (await glob(globStr)).filter(file =>
      file.match(/\.html|svelte$/i)
    )
    const svelteConfig = await import(
      resolve(config, 'svelte.config.js')
    ).catch(() => null)

    let accumulator = {}
    if (output != null && overwrite === false && (await fileExists(output))) {
      accumulator = await readFile(output)
        .then(file => JSON.parse(file.toString()))
        .catch((e: Error) => {
          console.warn(e)
          accumulator = {}
        })
    }
github mvlabs / isomorphic-mithril / src / lib / hash.js View on Github external
const getBuildHashes = () => Promise.all([
  glob('dist/app.*.css'),
  glob('dist/app.*.js'),
  glob('dist/vendors~app.*.js')
])
  .then(([cssFiles, jsFiles, jeVendorsFiles]) => ({
    css: getHash(cssFiles),
    js: getHash(jsFiles),
    jsVendors: getHash(jeVendorsFiles)
  }))
github mvlabs / isomorphic-mithril / src / lib / hash.js View on Github external
const getBuildHashes = () => Promise.all([
  glob('dist/app.*.css'),
  glob('dist/app.*.js'),
  glob('dist/vendors~app.*.js')
])
  .then(([cssFiles, jsFiles, jeVendorsFiles]) => ({
    css: getHash(cssFiles),
    js: getHash(jsFiles),
    jsVendors: getHash(jeVendorsFiles)
  }))
github mvlabs / isomorphic-mithril / src / lib / hash.js View on Github external
const getBuildHashes = () => Promise.all([
  glob('dist/app.*.css'),
  glob('dist/app.*.js'),
  glob('dist/vendors~app.*.js')
])
  .then(([cssFiles, jsFiles, jeVendorsFiles]) => ({
    css: getHash(cssFiles),
    js: getHash(jsFiles),
    jsVendors: getHash(jeVendorsFiles)
  }))
github notable / notable / src / renderer / containers / main / notes.ts View on Github external
refresh = async () => {

    const notesPath = Config.notes.path;

    if ( !notesPath || !await File.exists ( notesPath ) ) return;

    const filePaths = Utils.normalizeFilePaths ( await glob ( Config.notes.glob, { cwd: notesPath, absolute: true, filesOnly: true } ) );

    const notes: NotesObj = {};

    await Promise.all ( filePaths.map ( async filePath => {

      const note = await this.ctx.note.read ( filePath );

      if ( !note ) return;

      notes[filePath] = note;

    }));

    return this.set ( notes );

  }

tiny-glob

Tiny and extremely fast globbing

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular tiny-glob functions