Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
// 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);
}
};
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();
}
});
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/');
});
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/');
});
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));
});
});
}
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()
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()
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
}
glob: function( pattern, options ) {
options = options || {};
return new Glob( pattern, extend( { sync: true }, options ) ).found;
},