GithubHelp home page GithubHelp logo

findup's Introduction

build status Find-up

Install

npm install -g findup

Usage

Find up a file in ancestor's dir

.
├── config.json
└── f
    └── e
        └── d
            └── c
                ├── b
                │   └── a
                └── config.json

Options

  • maxdepth: (Number, default -1) How far to traverse before giving up. If maxdepth is -1, then there is no limit.

Async

findup(dir, fileName, options, callback) findup(dir, iterator, options, callback) with iterator(dir, cb) where cb only accept true or false

var findup = require('findup');


findup(__dirname + '/f/e/d/c/b/a', 'config.json', function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

or

findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
}, function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

EventEmitter

findup(dir, fileName, options)

var findup = require('findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', 'config.json');

findup(dir, iterator, options) with iterator(dir, cb) where cb only accept true or false

var findup = require('findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
});

findup return an EventEmitter. 3 events are emitted: found, error, end

found event is emitted each time a file is found.

You can stop the traversing by calling stop manually.

fup.on('found', function(dir){
  // dir === '/f/e/d/c'
  fup.stop();
});

error event is emitted when error happens

fup.on('error', function(e){
  // if(e) e === new Error('not found')
});

end event is emitted at the end of the traversing or after stop() is called.

fup.on('end', function(){
  // happy end
});

Sync

findup(dir, fileName) findup(dir, iteratorSync) with iteratorSync return true or false

var findup = require('findup');

try{
  var dir = findup.sync(__dirname + '/f/e/d/c/b/a', 'config.json'); // dir === '/f/e/d/c'
}catch(e){
  // if(e) e === new Error('not found')
}

CLI

npm install -g findup

$ cd test/fixture/f/e/d/c/b/a/
$ findup package.json
/root/findup/package.json

Usage

$ findup -h

Usage: findup [FILE]

    --name, -n       The name of the file to found
    --dir, -d        The directoy where we will start walking up    $PWD
    --help, -h       show usage                                     false
    --verbose, -v    print log                                      false

LICENSE MIT

Read the tests :)

findup's People

Contributors

filirom1 avatar majorbreakfast avatar seapunk avatar yoshuawuyts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

findup's Issues

Endless loop on Windows

function check() {
  console.log(dir);
  return false;
}

findup(process.cwd(), check, cb);

cb is never called. Instead the output is:

C:\
C:\
C:\
C:\
C:\
C:\
...

This also happens if I define the file via string, e.g. 'config.json'.

I didn't test it on Mac but my guess is that this is a Windows thing.

Bump and publish

Could you please bump the package version, and then publish it?

Split CLI from library

Currently findup has a hard dependency on commander just for the CLI tool, which most projects that depend on findup probably don't need. It would be awesome if the CLI tool (or the library code) could be extracted into it's own project so that the commander dependency is only used when installing the CLI tool.

Is findup still being maintained?

Hi I would like to use this library as a dependency but it seems like it has not be maintained in a while - are you planning to continue the development of findup?

.config/file.ext

As more and more tools have become best-practice when authoring npm modules, from package.json to .*rc to *file.js, the root directory of projects has become a very loud place. This dot-noise pushes README content farther and farther down the main page of git repos.

screenshot 2015-05-01 21 41 51

What if the above could optionally be simplified to the following?

screenshot 2015-05-01 21 50 12

This is a simple example and that's already about a 30% vertical space savings. I started the conversation over in the npm repo, but I'm also submitting issues to the findup-sync, karma, travis-ci and zuul repos.

maximum search depth

Is adding an option that lets you choose how far to look up the tree before giving up a good idea? I'd be willing to create a PR for it.

Still maintained?

Hi,

Is findup still being maintained?

There's a lot of small changes that would be really great to have merged.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.