[Pkg-javascript-commits] [node-findup-sync] 01/01: Initial import of node-findup-sync version 0.1.3

matthew pideil mpideil-guest at moszumanska.debian.org
Sun Mar 30 17:09:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

mpideil-guest pushed a commit to branch master
in repository node-findup-sync.

commit dfbac84510dc9f31898692986ac0cef560c95486
Author: Matthew Pideil <matthewp_debian at teledetection.fr>
Date:   Sun Mar 30 16:58:11 2014 +0000

    Initial import of node-findup-sync version 0.1.3
---
 .gitignore                |  1 +
 .jshintrc                 | 15 +++++++++++++++
 .npmignore                |  0
 .travis.yml               |  5 +++++
 Gruntfile.js              | 25 ++++++++++++++++++++++++
 LICENSE-MIT               | 22 ++++++++++++++++++++++
 README.md                 | 45 ++++++++++++++++++++++++++++++++++++++++++++
 lib/findup-sync.js        | 46 +++++++++++++++++++++++++++++++++++++++++++++
 package.json              | 44 +++++++++++++++++++++++++++++++++++++++++++
 test/findup-sync_test.js  | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 test/fixtures/a.txt       |  0
 test/fixtures/a/b/bar.txt |  0
 test/fixtures/a/foo.txt   |  0
 test/fixtures/aaa.txt     |  0
 14 files changed, 251 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2ccbe46
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules/
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..8718952
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,15 @@
+{
+  "loopfunc": true,
+  "curly": true,
+  "eqeqeq": true,
+  "immed": true,
+  "latedef": true,
+  "newcap": true,
+  "noarg": true,
+  "sub": true,
+  "undef": true,
+  "unused": true,
+  "boss": true,
+  "eqnull": true,
+  "node": true
+}
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..e69de29
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b30fcb7
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - 0.8
+before_script:
+  - npm install -g grunt-cli
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..2f964a5
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,25 @@
+'use strict';
+
+module.exports = function(grunt) {
+
+  // Project configuration.
+  grunt.initConfig({
+    nodeunit: {
+      files: ['test/**/*_test.js'],
+    },
+    jshint: {
+      options: {
+        jshintrc: '.jshintrc'
+      },
+      all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
+    }
+  });
+
+  // Load plugins.
+  grunt.loadNpmTasks('grunt-contrib-jshint');
+  grunt.loadNpmTasks('grunt-contrib-nodeunit');
+
+  // Default task.
+  grunt.registerTask('default', ['jshint', 'nodeunit']);
+
+};
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..bb2aad6
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2013 "Cowboy" Ben Alman
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5459b93
--- /dev/null
+++ b/README.md
@@ -0,0 +1,45 @@
+# findup-sync [![Build Status](https://secure.travis-ci.org/cowboy/node-findup-sync.png?branch=master)](http://travis-ci.org/cowboy/node-findup-sync)
+
+Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
+
+## Getting Started
+Install the module with: `npm install findup-sync`
+
+```js
+var findup = require('findup-sync');
+
+// Start looking in the CWD.
+var filepath1 = findup('{a,b}*.txt');
+
+// Start looking somewhere else, and ignore case (probably a good idea).
+var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true});
+```
+
+## Usage
+
+```js
+findup(patternOrPatterns [, minimatchOptions])
+```
+
+### patternOrPatterns
+Type: `String` or `Array`  
+Default: none
+
+One or more wildcard glob patterns. Or just filenames.
+
+### minimatchOptions
+Type: `Object`  
+Default: `{}`
+
+Options to be passed to [minimatch](https://github.com/isaacs/minimatch).
+
+Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here.
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
+
+## Release History
+2014-03-14 - v0.1.3 - Updated dependencies.  
+2013-03-08 - v0.1.2 - Updated dependencies. Fixed a Node 0.9.x bug. Updated unit tests to work cross-platform.  
+2012-11-15 - v0.1.1 - Now works without an options object.  
+2012-11-01 - v0.1.0 - Initial release.
diff --git a/lib/findup-sync.js b/lib/findup-sync.js
new file mode 100644
index 0000000..742a478
--- /dev/null
+++ b/lib/findup-sync.js
@@ -0,0 +1,46 @@
+/*
+ * 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');
+var _ = require('lodash');
+
+// 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);
+    }).flatten().uniq().value();
+    // 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;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7242b91
--- /dev/null
+++ b/package.json
@@ -0,0 +1,44 @@
+{
+  "name": "findup-sync",
+  "description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.",
+  "version": "0.1.3",
+  "homepage": "https://github.com/cowboy/node-findup-sync",
+  "author": {
+    "name": "\"Cowboy\" Ben Alman",
+    "url": "http://benalman.com/"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/cowboy/node-findup-sync.git"
+  },
+  "bugs": {
+    "url": "https://github.com/cowboy/node-findup-sync/issues"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/cowboy/node-findup-sync/blob/master/LICENSE-MIT"
+    }
+  ],
+  "main": "lib/findup-sync",
+  "engines": {
+    "node": ">= 0.6.0"
+  },
+  "scripts": {
+    "test": "grunt nodeunit"
+  },
+  "dependencies": {
+    "glob": "~3.2.9",
+    "lodash": "~2.4.1"
+  },
+  "devDependencies": {
+    "grunt": "~0.4.4",
+    "grunt-contrib-jshint": "~0.9.2",
+    "grunt-contrib-nodeunit": "~0.3.3"
+  },
+  "keywords": [
+    "find",
+    "glob",
+    "file"
+  ]
+}
diff --git a/test/findup-sync_test.js b/test/findup-sync_test.js
new file mode 100644
index 0000000..f8baf9e
--- /dev/null
+++ b/test/findup-sync_test.js
@@ -0,0 +1,48 @@
+'use strict';
+
+// Nodejs lib.
+var path = require('path');
+
+var findup = require('../lib/findup-sync.js');
+
+// Get a relative path.
+var rel = function(abspath) {
+  return typeof abspath === 'string' ? path.relative('.', abspath) : abspath;
+};
+
+exports['findup'] = {
+  setUp: function(done) {
+    this.cwd = process.cwd();
+    done();
+  },
+  tearDown: function(done) {
+    process.chdir(this.cwd);
+    done();
+  },
+  'simple': function(test) {
+    test.expect(8);
+    var opts = {cwd: 'test/fixtures/a/b'};
+    test.equal(rel(findup('foo.txt', opts)), path.normalize('test/fixtures/a/foo.txt'), 'should find files');
+    test.equal(rel(findup('bar.txt', opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find files');
+    test.equal(rel(findup('a.txt', opts)), path.normalize('test/fixtures/a.txt'), 'should find files');
+    test.equal(rel(findup('?.txt', opts)), path.normalize('test/fixtures/a.txt'), 'should support glob patterns');
+    test.equal(rel(findup('*.txt', opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches the glob pattern');
+    test.equal(rel(findup(['b*.txt', 'f*.txt'], opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches any of the glob patterns');
+    test.equal(rel(findup(['f*.txt', 'b*.txt'], opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches any of the glob patterns');
+    test.equal(findup('not-gonna-exist-i-hope.txt', opts), null, 'should returning null if no files found');
+    test.done();
+  },
+  'cwd': function(test) {
+    test.expect(8);
+    process.chdir('test/fixtures/a/b');
+    test.equal(rel(findup('foo.txt')), path.normalize('../foo.txt'), 'should find files');
+    test.equal(rel(findup('bar.txt')), 'bar.txt', 'should find files');
+    test.equal(rel(findup('a.txt')), path.normalize('../../a.txt'), 'should find files');
+    test.equal(rel(findup('?.txt')), path.normalize('../../a.txt'), 'should support glob patterns');
+    test.equal(rel(findup('*.txt')), 'bar.txt', 'should find the first thing that matches the glob pattern');
+    test.equal(rel(findup(['b*.txt', 'f*.txt'])), 'bar.txt', 'should find the first thing that matches any of the glob patterns');
+    test.equal(rel(findup(['f*.txt', 'b*.txt'])), 'bar.txt', 'should find the first thing that matches any of the glob patterns');
+    test.equal(findup('not-gonna-exist-i-hope.txt'), null, 'should returning null if no files found');
+    test.done();
+  },
+};
diff --git a/test/fixtures/a.txt b/test/fixtures/a.txt
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/a/b/bar.txt b/test/fixtures/a/b/bar.txt
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/a/foo.txt b/test/fixtures/a/foo.txt
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/aaa.txt b/test/fixtures/aaa.txt
new file mode 100644
index 0000000..e69de29

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-findup-sync.git



More information about the Pkg-javascript-commits mailing list