findup
Advanced tools
Comparing version 0.1.3 to 0.1.4
#!/usr/bin/env node | ||
var findup = require('..'), | ||
Path = require('path'), | ||
nopt = require('nopt'), | ||
knownOpts = { | ||
name : String, | ||
dir : Path, | ||
help : Boolean, | ||
verbose : Boolean | ||
}, | ||
description = { | ||
name : "The name of the file to found", | ||
dir : "The directoy where we will start walking up", | ||
help : "show usage", | ||
verbose : "print log" | ||
path = require('path'), | ||
pkg = require('../package'), | ||
program = require('commander'), | ||
options = {}, | ||
optionKeys = ['name', 'dir', 'verbose'], | ||
EXIT_FAILURE = -1; | ||
program | ||
.version(pkg.version) | ||
.option('--name <name>', 'The name of the file to find', String) | ||
.option('--dir <dir>', 'The directoy where we will start walking up', process.cwd(), path) | ||
.option('--verbose', 'print log', false, Boolean) | ||
.parse(process.argv); | ||
}, | ||
defaults = { | ||
dir : process.cwd(), | ||
help : false, | ||
verbose : false | ||
}, | ||
shortHands = { | ||
d : "--dir", | ||
n : "--name", | ||
h : "--help", | ||
v : "--verbose" | ||
}, | ||
options = nopt(knownOpts, shortHands, process.argv, 2), | ||
argvRemain = options.argv.remain; | ||
// defaults value | ||
Object.keys(defaults).forEach(function(key){ | ||
var value = defaults[key]; | ||
options[key] = options[key] || value; | ||
optionKeys.forEach(function(optionKey){ | ||
options[optionKey] = program[optionKey]; | ||
}); | ||
if(argvRemain && argvRemain.length >=1 ) options.name = argvRemain[0]; | ||
if(program.args && program.args.length >=1 && !options.name){ | ||
options.name = program.args[0]; | ||
} | ||
if(!options.name || options.help) { | ||
console.error('Usage: findup [FILE]'); | ||
console.error(''); | ||
console.error(nopt.usage(knownOpts, shortHands, description, defaults)); | ||
process.exit(-1); | ||
if(!options.name) { | ||
program.outputHelp(); | ||
process.exit(EXIT_FAILURE); | ||
} | ||
var file = options.name; | ||
findup(process.cwd(), file, options, function(err, dir){ | ||
if(err) return console.error(err.message ? err.message : err); | ||
console.log(Path.join(dir, file)); | ||
console.log(path.join(dir, file)); | ||
}); |
@@ -5,3 +5,5 @@ var fs = require('fs'), | ||
colors = require('colors'), | ||
EE = require('events').EventEmitter; | ||
EE = require('events').EventEmitter, | ||
fsExists = fs.exists ? fs.exists : Path.exists, | ||
fsExistsSync = fs.existsSync ? fs.existsSync : Path.existsSync; | ||
@@ -30,3 +32,3 @@ module.exports = function(dir, iterator, options, callback){ | ||
iterator = function(dir, cb){ | ||
return fs.exists(Path.join(dir, file), cb); | ||
return fsExists(Path.join(dir, file), cb); | ||
}; | ||
@@ -84,3 +86,3 @@ } | ||
iteratorSync = function(dir){ | ||
return fs.existsSync(Path.join(dir, file)); | ||
return fsExistsSync(Path.join(dir, file)); | ||
}; | ||
@@ -87,0 +89,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Walk up ancester's dir up to root", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"repository": { | ||
@@ -18,4 +18,4 @@ "type": "git", | ||
"dependencies": { | ||
"nopt": "https://github.com/Filirom1/nopt/tarball/master#pull-request-in-progress", | ||
"colors": "~0.6.0-1" | ||
"colors": "~0.6.0-1", | ||
"commander": "~2.1.0" | ||
}, | ||
@@ -28,3 +28,3 @@ "devDependencies": { | ||
"engines": { | ||
"node": ">0.8.x" | ||
"node": ">=0.6" | ||
}, | ||
@@ -31,0 +31,0 @@ "licenses": [ |
@@ -7,6 +7,7 @@ var assert = require('chai').assert, | ||
describe('find-up', function(){ | ||
var fixtureDir = Path.join(__dirname, 'fixture', 'f', 'e', 'd', 'c', 'b', 'a'); | ||
var fixtureDir = Path.join(__dirname, 'fixture', 'f', 'e', 'd', 'c', 'b', 'a'), | ||
fsExists = fs.exists ? fs.exists : Path.exists; | ||
it('accept a function', function(done){ | ||
findup(fixtureDir, function(dir, cb){ | ||
return fs.exists(Path.join(dir, 'config.json'), cb); | ||
return fsExists(Path.join(dir, 'config.json'), cb); | ||
}, function(err, file){ | ||
@@ -13,0 +14,0 @@ assert.ifError(err); |
Sorry, the diff of this file is not supported yet
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
0
10440
204
+ Addedcommander@~2.1.0
+ Addedcommander@2.1.0(transitive)
- Removednopt@https://github.com/Filirom1/nopt/tarball/master#pull-request-in-progress