X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fgrunt%2Fnode_modules%2Ffindup-sync%2Flib%2Ffindup-sync.js;fp=node_modules%2Fgrunt%2Fnode_modules%2Ffindup-sync%2Flib%2Ffindup-sync.js;h=871a7256cabb6ac270451d6129ed0c4b5feca667;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js b/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js new file mode 100644 index 000000000..871a7256c --- /dev/null +++ b/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js @@ -0,0 +1,49 @@ +/* + * findup-sync + * https://github.com/cowboy/node-findup-sync + * + * Copyright (c) 2013 "Cowboy" Ben Alman + * Licensed under the MIT license. + */ + +'use strict'; + +// Nodejs libs. +var path = require('path'); + +// External libs. +var glob = require('glob'); + +// Search for a filename in the given directory or all parent directories. +module.exports = function(patterns, options) { + // Normalize patterns to an array. + if (!Array.isArray(patterns)) { patterns = [patterns]; } + // Create globOptions so that it can be modified without mutating the + // original object. + var globOptions = Object.create(options || {}); + globOptions.maxDepth = 1; + globOptions.cwd = path.resolve(globOptions.cwd || '.'); + + var files, lastpath; + do { + // Search for files matching patterns. + files = patterns.map(function(pattern) { + return glob.sync(pattern, globOptions); + }).reduce(function(a, b) { + return a.concat(b); + }).filter(function(entry, index, arr) { + return index === arr.indexOf(entry); + }); + // Return file if found. + if (files.length > 0) { + return path.resolve(path.join(globOptions.cwd, files[0])); + } + // Go up a directory. + lastpath = globOptions.cwd; + globOptions.cwd = path.resolve(globOptions.cwd, '..'); + // If parentpath is the same as basedir, we can't go any higher. + } while (globOptions.cwd !== lastpath); + + // No files were found! + return null; +};