How to use the glob.Glob function in glob

To help you get started, we’ve selected a few 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 bitovi / documentjs / lib / find / files.js View on Github external
module.exports = function(options){
	var pattern;
	var globOptions;
	
	if(typeof options.glob === "string"){
		var pattern = options.glob;
		globOptions = {};
	} else {
		pattern = options.glob.pattern;
		globOptions = _.extend({}, options.glob);
		delete globOptions.pattern;
	}

	var glb = new glob.Glob(pattern, globOptions);
	var ignore = options.glob.ignore;
	
	if(typeof ignore === "string") {
		ignore = [ignore];
	}
	if(ignore) {
		// weave in ignore behavior
		var oldOn = glb.on;
		glb.on = function(event, listener) {
			if(event === "match") {
				var handler = function(filepath){
					for(var i = 0; i < ignore.length; i++) {
						if( minimatch(filepath, ignore[i]) ) {
							return;
						}
					}
github 1-electron / sprite / deploy / node_modules / glob-all / glob-all.js View on Github external
// check whether this is an exclude pattern and
  // strip the leading ! if it is
  if (pattern.charAt(0) === "!") {
    include = false;
    pattern = pattern.substr(1);
  }
  // run
  if (this.opts.sync) {
    // sync - callback straight away
    g = new Glob(pattern, this.opts);
    this.globs.push(g);
    this.globbedOne(null, include, g.found);
  } else {
    // async
    var self = this;
    g = new Glob(pattern, this.opts, function(err, files) {
      self.globbedOne(err, include, files);
    });
    this.globs.push(g);
  }
};
github gulpjs / glob-stream / readable.js View on Github external
var ourNegatives = negatives.map(resolveNegatives);
  ourOpt.ignore = ourNegatives;

  var cwd = ourOpt.cwd;
  var allowEmpty = ourOpt.allowEmpty || false;

  // Extract base path from glob
  var basePath = ourOpt.base || getBasePath(ourGlob, ourOpt);

  // Remove path relativity to make globs make sense
  ourGlob = toAbsoluteGlob(ourGlob, ourOpt);
  // Delete `root` after all resolving done
  delete ourOpt.root;

  var globber = new glob.Glob(ourGlob, ourOpt);
  this._globber = globber;

  var found = false;

  globber.on('match', function(filepath) {
    found = true;
    var obj = {
      cwd: cwd,
      base: basePath,
      path: removeTrailingSeparator(filepath),
    };
    if (!self.push(obj)) {
      globber.pause();
    }
  });
github contra / glob2base / test / main.js View on Github external
it('should get a base name from a nested glob', function() {
    var globber = new glob.Glob('js/**/test/*.js', {cwd: __dirname});
    glob2base(globber).should.equal('js/');
  });
github contra / glob2base / test / main.js View on Github external
it('should get a base name from character class pattern', function() {
    var globber = new glob.Glob('js/t[a-z]st}/*.js', {cwd: __dirname});
    glob2base(globber).should.equal('js/');
  });
github advanced-rest-client / arc-electron / tasks / bower.js View on Github external
return new Promise((resolve, reject) => {
    const promises = [];
    const mg = new Glob(pattern);
    mg.on('match', (file) => {
      console.log('Removing', file);
      promises.push(fs.remove(file));
    });
    mg.on('end', () => {
      Promise.all(promises)
      .then(() => resolve())
      .catch((cause) => reject(cause));
    });
    mg.on('error', (err) => {
      console.error('Error cleaning data', err);
      reject(new Error(err));
    });
  });
}
github mysticatea / cpx / lib / utils / apply-action.js View on Github external
if (lastError == null) {
                    resolve()
                } else {
                    reject(lastError)
                }
            }
        }

        const globOptions = {
            nodir: !options.includeEmptyDirs,
            silent: true,
            follow: Boolean(options.dereference),
            nosort: true,
        }
        try {
            new glob.Glob(pattern, globOptions)
                .on("match", sourcePath => {
                    if (lastError != null) {
                        return
                    }

                    count += 1
                    try {
                        action(sourcePath).then(
                            () => {
                                count -= 1
                                next()
                            },
                            error => {
                                count -= 1
                                lastError = lastError || error
                                next()
github sourcegraph / javascript-typescript-langserver / src / fs.ts View on Github external
return new Observable(subscriber => {
            const globber = new Glob('*', {
                cwd,
                nodir: true,
                matchBase: true,
                follow: true,
            })
            globber.on('match', (file: string) => {
                subscriber.next(file)
            })
            globber.on('error', (err: any) => {
                subscriber.error(err)
            })
            globber.on('end', () => {
                subscriber.complete()
            })
            return () => {
                globber.abort()
github PPIO / pp.io / build / utils.js View on Github external
exports.getLangList = function(lang) {
  const appDir = path.resolve(process.cwd(), 'app/')
  const globInstance = new glob.Glob(`**/translations/${lang}.json`, {
    cwd: appDir,
    sync: true,
  })
  return globInstance.found
}
github jquery / download.jqueryui.com / lib / util.js View on Github external
glob: function( pattern, options ) {
		options = options || {};
		return new Glob( pattern, extend( { sync: true }, options ) ).found;
	},