From 6ef6b495c52344632663baadd7c6131e1f56af9d Mon Sep 17 00:00:00 2001 From: David Marchena Date: Wed, 27 May 2015 20:19:50 +0200 Subject: [PATCH] Usage info and license --- LICENSE | 22 +++++++++++ README.md | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..549dafc --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 David Marchena + +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 index 86e5bdb..40e653d 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,113 @@ Get your project dependency tree from NPM as well as from bower -Current state: Under early development +## Install + + npm install dependency-info + +## Usage + +First af all, you have to retrieve your dependency tree. + +### The async way + + var dependencyInfo = require('dependency-info'); + dependencyInfo.readTree({ + manager: 'npm' + }) + .then(function (tree) { + ... + }) + .catch(function (err) { + ... + }); + +### Of course, you can also get it synchronously + + var dependencyInfo = require('dependency-info') + list, + tree; + tree = dependencyInfo.readTreeSync({ + manager: 'npm' + }); + +### Parameters +`readTree`and `readTreeSync` accept the same `options` param: + +``` +{ +path: {String} path to module whose dependencies will be fetched. + Default: process.cwd() +manager: {String} Package manager: 'npm' or 'bower' +type: {String} All dependencies: 'all' (default) + or + {Array} Accepted values: 'dependencies' and 'devDependencies' +deep: {Boolean} If true it search for all dependencies, not only the direct ones. + Default value: false +filterBy: + { + keyword: {Array} List of keywords the dependency must have + } +} +``` + +## How to use this info + +`Tree` object provides you a method to get a sorted Array of the information you need. + +### tree.list(fields, order) + +This method looks over the tree and returns an ordered array of key value objects filled with the specified fields, which will be taken from each dependency json file. + +`fields` {Array} The fields to get from json files +`order` {String} Sort dependencies in ascending ('asc') or descending order ('desc') + +## Examples + +### Logging asynchronously + +``` +var dependencyInfo = require('dependency-info'); +dependencyInfo.readTree({ + manager: 'npm' +}) +.then(function (tree) { + var list = tree.list(['name', 'version'], 'asc'); + console.log(list); +}) +``` + +### Logging synchronously + +``` +var dependencyInfo = require('dependency-info') + list, + tree; +tree = dependencyInfo.readTreeSync({ + manager: 'npm' +}); +list = tree.list(['name', 'version'], 'asc'); +console.log(list); +``` + +### Result + +Both of them will output a message like this: + +``` +[ { name: 'connect-livereload', version: '0.5.3' }, + { name: 'express', version: '4.12.3' }, + { name: 'gulp', version: '3.8.11' }, + { name: 'gulp-autoprefixer', version: '2.2.0' }, + { name: 'gulp-copy', version: '0.0.2' }, + { name: 'gulp-kit', version: '0.1.1' }, + { name: 'gulp-minify-css', version: '1.1.0' }, + { name: 'gulp-prettify', version: '0.3.0' }, + { name: 'gulp-rename', version: '1.2.2' }, + { name: 'gulp-sass', version: '1.3.3' }, + { name: 'gulp-strip-css-comments', version: '1.1.0' }, + { name: 'tiny-lr', version: '0.1.5' } ] +``` + +## License +MIT. See [LICENSE](https://github.com/dmarchena/dependency-info/blob/master/LICENSE) for details.