Browse files

Merge pull request #2 from substack/tilde

tilde mode
  • Loading branch information...
2 parents 1a6e0af + aab1900 commit 6edfeb3667f9b9f99c8fbeae08f6c2e0ce36d2c8 @youurayy committed Mar 28, 2013
Showing with 23 additions and 2 deletions.
  1. +14 −0 README.md
  2. +9 −2 lib/npmlv.js
View
14 README.md
@@ -27,6 +27,20 @@ Prints:
}
```
+To print dependencies for floating patch versions:
+
+ npmlv -t
+
+Prints:
+
+```js
+{
+ "async-mini": "~0.1.0",
+ "laeh2": "~0.2.0",
+ "mongodb": "~0.9.7",
+ "underscore": "~1.1.7"
+}
+```
To print dependencies on exact and higher versions (optimistic):
npmlv -n
View
11 lib/npmlv.js
@@ -7,11 +7,14 @@ program
.usage('\List module versions in your project in format easy to copy and paste to your package.json.\nUsage: $0')
.option('-a, --any', 'User any version specifier "*", instead of exact version.')
.option('-n, --newer', 'User equal or newer version specifier ">=", instead of exact version.')
+ .option('-t, --tilde', 'Use tilde "~" for floating patch versions.')
.parse(process.argv);
var res = {};
var base = process.cwd() + '/node_modules';
-var dirs = fs.readdirSync(base);
+var dirs = fs.readdirSync(base)
+ .filter(function (dir) { return !/^\./.test(dir) });
+
for(var i = 0; i < dirs.length; i++) {
var module = dirs[i];
var bdir = base + '/' + module;
@@ -25,7 +28,11 @@ for(var i = 0; i < dirs.length; i++) {
try {
var config = JSON.parse(fs.readFileSync(cfg));
if(config.version)
- res[module] = program.any ? "*" : ((program.newer ? '>=' : '') + config.version);
+ res[module] = (program.any ? "*" :
+ program.newer ? ">=" :
+ program.tilde ? "~" :
+ ""
+ ) + config.version;
else
console.log('No version information for module ' + module);
}

0 comments on commit 6edfeb3

Please sign in to comment.