├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .verb.md ├── LICENSE ├── README.md ├── bin └── cli.js ├── index.js └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | 29 | examples/*/dist 30 | examples/*/site 31 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | Once installed globally, there will be a `dependents` command that can be run from the command line. 4 | 5 | To see all the dependents for a module, specify the module name after the `dependents` command like this: 6 | 7 | ```sh 8 | $ dependents base 9 | ``` 10 | 11 | This will output a JavaScript array containing each dependent as an object with `name` and dependency version properties. The dependency version property key will be the specified module name with `-version` after it. So `base-version` for the command specified above. 12 | 13 | Example output from running `$ dependents base`: 14 | 15 | ![image](https://cloud.githubusercontent.com/assets/995160/17226161/01775114-54d6-11e6-9c41-313a2b6eaf74.png) 16 | 17 | ## Formatting 18 | 19 | Use the `--format` option to format the results as a table (this is the default). 20 | 21 | Run the following command to the dependents formatted as a table: 22 | 23 | ```sh 24 | $ dependents base --format 25 | ``` 26 | 27 | ![image](https://cloud.githubusercontent.com/assets/995160/17226161/01775114-54d6-11e6-9c41-313a2b6eaf74.png) 28 | 29 | You can also include the download counts when using formatting: 30 | 31 | ```sh 32 | $ dependents base --downloads --format 33 | ``` 34 | 35 | ![image](https://cloud.githubusercontent.com/assets/995160/17226185/235b8b88-54d6-11e6-93f8-4b6e686e932d.png) 36 | 37 | If you need to use the results as a JSON object, use the `--format` command with `json` after it: 38 | 39 | ```sh 40 | $ dependents base --format json 41 | ``` 42 | 43 | ```json 44 | [ 45 | { "name": "base-app", "base-version": "^0.11.1" }, 46 | { "name": "base-reporter", "base-version": "^0.11.0" }, 47 | { "name": "benchmarked", "base-version": "^0.8.1" }, 48 | { "name": "boilerplate", "base-version": "^0.11.1" }, 49 | { "name": "expand-files", "base-version": "^0.11.1" }, 50 | { "name": "expand-target", "base-version": "^0.11.1" }, 51 | { "name": "npm-api", "base-version": "^0.8.1" }, 52 | { "name": "saffronapp", "base-version": "file:packages/base" }, 53 | { "name": "scaffold", "base-version": "^0.11.1" }, 54 | { "name": "templates", "base-version": "^0.11.1" }, 55 | { "name": "verbiage", "base-version": "^0.8.1" }, 56 | { "name": "vinyl-collection", "base-version": "^0.11.0" }, 57 | { "name": "vinyl-item", "base-version": "^0.8.1" } 58 | ] 59 | ``` 60 | 61 | This can be output to a json file using the `bash` `>` character: 62 | 63 | ```sh 64 | $ dependents base --format json > base-dependents.json 65 | ``` 66 | 67 | Use this with the `--downloads` option to be able to use the json data and do your own sorting and filtering if necessary. 68 | 69 | ```sh 70 | $ dependents base --format json --downloads > base-dependents.json 71 | ``` 72 | ### Downloads 73 | 74 | To include the download counts of each of the dependents, use the `--downloads` option. This will add a `downloads` object to each dependent with the `total` and `last30` (last 30 days) download counts: 75 | 76 | ```sh 77 | $ dependents base --downloads --format json 78 | ``` 79 | 80 | ```json 81 | [ 82 | { "name": "templates", "base-version": "^0.11.1", "downloads": { "total": 124383, "last30": 14517 } }, 83 | { "name": "benchmarked", "base-version": "^0.8.1", "downloads": { "total": 528830, "last30": 5301 } }, 84 | { "name": "vinyl-item", "base-version": "^0.8.1", "downloads": { "total": 6045, "last30": 5019 } }, 85 | { "name": "expand-target", "base-version": "^0.11.1", "downloads": { "total": 4341, "last30": 577 } }, 86 | { "name": "scaffold", "base-version": "^0.11.1", "downloads": { "total": 4212, "last30": 532 } }, 87 | { "name": "boilerplate", "base-version": "^0.11.1", "downloads": { "total": 8845, "last30": 478 } }, 88 | { "name": "base-app", "base-version": "^0.11.1", "downloads": { "total": 1091, "last30": 471 } }, 89 | { "name": "expand-files", "base-version": "^0.11.1", "downloads": { "total": 7235, "last30": 399 } }, 90 | { "name": "npm-api", "base-version": "^0.8.1", "downloads": { "total": 629, "last30": 52 } }, 91 | { "name": "base-reporter", "base-version": "^0.11.0", "downloads": { "total": 103, "last30": 16 } }, 92 | { "name": "vinyl-collection", "base-version": "^0.11.0", "downloads": { "total": 101, "last30": 15 } }, 93 | { "name": "verbiage", "base-version": "^0.8.1", "downloads": { "total": 77, "last30": 7 } }, 94 | { "name": "saffronapp", "base-version": "file:packages/base", "downloads": { "total": 112, "last30": 5 } } 95 | ] 96 | ``` 97 | 98 | When using the `--downloads` option, the list is sorted by the `downloads.last30` property so the most used dependents will be found at the top. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017, Brian Woodward 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dependents-cli [![NPM version](https://img.shields.io/npm/v/dependents-cli.svg?style=flat)](https://www.npmjs.com/package/dependents-cli) [![NPM monthly downloads](https://img.shields.io/npm/dm/dependents-cli.svg?style=flat)](https://npmjs.org/package/dependents-cli) [![NPM total downloads](https://img.shields.io/npm/dt/dependents-cli.svg?style=flat)](https://npmjs.org/package/dependents-cli) 2 | 3 | > CLI for listing an npm module's dependent projects and their download stats. 4 | 5 | You might also be interested in [module-dependents](https://github.com/doowb/module-dependents). 6 | 7 | ## Install 8 | 9 | Install globally with [npm](https://www.npmjs.com/) 10 | 11 | ```sh 12 | $ npm install --global dependents-cli 13 | ``` 14 | 15 | ## Usage 16 | 17 | Once installed globally, there will be a `dependents` command that can be run from the command line. 18 | 19 | To see all the dependents for a module, specify the module name after the `dependents` command like this: 20 | 21 | ```sh 22 | $ dependents base 23 | ``` 24 | 25 | This will output a JavaScript array containing each dependent as an object with `name` and dependency version properties. The dependency version property key will be the specified module name with `-version` after it. So `base-version` for the command specified above. 26 | 27 | Example output from running `$ dependents base`: 28 | 29 | ![image](https://cloud.githubusercontent.com/assets/995160/17226161/01775114-54d6-11e6-9c41-313a2b6eaf74.png) 30 | 31 | ## Formatting 32 | 33 | Use the `--format` option to format the results as a table (this is the default). 34 | 35 | Run the following command to the dependents formatted as a table: 36 | 37 | ```sh 38 | $ dependents base --format 39 | ``` 40 | 41 | ![image](https://cloud.githubusercontent.com/assets/995160/17226161/01775114-54d6-11e6-9c41-313a2b6eaf74.png) 42 | 43 | You can also include the download counts when using formatting: 44 | 45 | ```sh 46 | $ dependents base --downloads --format 47 | ``` 48 | 49 | ![image](https://cloud.githubusercontent.com/assets/995160/17226185/235b8b88-54d6-11e6-93f8-4b6e686e932d.png) 50 | 51 | If you need to use the results as a JSON object, use the `--format` command with `json` after it: 52 | 53 | ```sh 54 | $ dependents base --format json 55 | ``` 56 | 57 | ```json 58 | [ 59 | { "name": "base-app", "base-version": "^0.11.1" }, 60 | { "name": "base-reporter", "base-version": "^0.11.0" }, 61 | { "name": "benchmarked", "base-version": "^0.8.1" }, 62 | { "name": "boilerplate", "base-version": "^0.11.1" }, 63 | { "name": "expand-files", "base-version": "^0.11.1" }, 64 | { "name": "expand-target", "base-version": "^0.11.1" }, 65 | { "name": "npm-api", "base-version": "^0.8.1" }, 66 | { "name": "saffronapp", "base-version": "file:packages/base" }, 67 | { "name": "scaffold", "base-version": "^0.11.1" }, 68 | { "name": "templates", "base-version": "^0.11.1" }, 69 | { "name": "verbiage", "base-version": "^0.8.1" }, 70 | { "name": "vinyl-collection", "base-version": "^0.11.0" }, 71 | { "name": "vinyl-item", "base-version": "^0.8.1" } 72 | ] 73 | ``` 74 | 75 | This can be output to a json file using the `bash` `>` character: 76 | 77 | ```sh 78 | $ dependents base --format json > base-dependents.json 79 | ``` 80 | 81 | Use this with the `--downloads` option to be able to use the json data and do your own sorting and filtering if necessary. 82 | 83 | ```sh 84 | $ dependents base --format json --downloads > base-dependents.json 85 | ``` 86 | 87 | ### Downloads 88 | 89 | To include the download counts of each of the dependents, use the `--downloads` option. This will add a `downloads` object to each dependent with the `total` and `last30` (last 30 days) download counts: 90 | 91 | ```sh 92 | $ dependents base --downloads --format json 93 | ``` 94 | 95 | ```json 96 | [ 97 | { "name": "templates", "base-version": "^0.11.1", "downloads": { "total": 124383, "last30": 14517 } }, 98 | { "name": "benchmarked", "base-version": "^0.8.1", "downloads": { "total": 528830, "last30": 5301 } }, 99 | { "name": "vinyl-item", "base-version": "^0.8.1", "downloads": { "total": 6045, "last30": 5019 } }, 100 | { "name": "expand-target", "base-version": "^0.11.1", "downloads": { "total": 4341, "last30": 577 } }, 101 | { "name": "scaffold", "base-version": "^0.11.1", "downloads": { "total": 4212, "last30": 532 } }, 102 | { "name": "boilerplate", "base-version": "^0.11.1", "downloads": { "total": 8845, "last30": 478 } }, 103 | { "name": "base-app", "base-version": "^0.11.1", "downloads": { "total": 1091, "last30": 471 } }, 104 | { "name": "expand-files", "base-version": "^0.11.1", "downloads": { "total": 7235, "last30": 399 } }, 105 | { "name": "npm-api", "base-version": "^0.8.1", "downloads": { "total": 629, "last30": 52 } }, 106 | { "name": "base-reporter", "base-version": "^0.11.0", "downloads": { "total": 103, "last30": 16 } }, 107 | { "name": "vinyl-collection", "base-version": "^0.11.0", "downloads": { "total": 101, "last30": 15 } }, 108 | { "name": "verbiage", "base-version": "^0.8.1", "downloads": { "total": 77, "last30": 7 } }, 109 | { "name": "saffronapp", "base-version": "file:packages/base", "downloads": { "total": 112, "last30": 5 } } 110 | ] 111 | ``` 112 | 113 | When using the `--downloads` option, the list is sorted by the `downloads.last30` property so the most used dependents will be found at the top. 114 | 115 | ## About 116 | 117 | ### Related projects 118 | 119 | * [download-stats](https://www.npmjs.com/package/download-stats): Get and calculate npm download stats for npm modules. | [homepage](https://github.com/doowb/download-stats "Get and calculate npm download stats for npm modules.") 120 | * [module-dependents](https://www.npmjs.com/package/module-dependents): Retrieve list of dependents for an npm module. | [homepage](https://github.com/doowb/module-dependents "Retrieve list of dependents for an npm module.") 121 | * [npm-api-dependents](https://www.npmjs.com/package/npm-api-dependents): npm-api plugin for getting module dependents. | [homepage](https://github.com/doowb/npm-api-dependents "npm-api plugin for getting module dependents.") 122 | * [npm-api](https://www.npmjs.com/package/npm-api): Base class for retrieving data from the npm registry. | [homepage](https://github.com/doowb/npm-api "Base class for retrieving data from the npm registry.") 123 | 124 | ### Contributing 125 | 126 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 127 | 128 | ### Contributors 129 | 130 | | **Commits** | **Contributor** | 131 | | --- | --- | 132 | | 18 | [doowb](https://github.com/doowb) | 133 | | 1 | [panva](https://github.com/panva) | 134 | 135 | ### Building docs 136 | 137 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 138 | 139 | To generate the readme, run the following command: 140 | 141 | ```sh 142 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 143 | ``` 144 | 145 | ### Running tests 146 | 147 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 148 | 149 | ```sh 150 | $ npm install && npm test 151 | ``` 152 | 153 | ### Author 154 | 155 | **Brian Woodward** 156 | 157 | * [github/doowb](https://github.com/doowb) 158 | * [twitter/doowb](https://twitter.com/doowb) 159 | 160 | ### License 161 | 162 | Copyright © 2017, [Brian Woodward](https://github.com/doowb). 163 | Released under the [MIT License](LICENSE). 164 | 165 | *** 166 | 167 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 21, 2017._ -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var argv = require('minimist')(process.argv.slice(2), { 4 | boolean: ['downloads'], 5 | default: { 6 | downloads: true, 7 | format: 'table' 8 | }, 9 | alias: { 10 | downloads: 'd', 11 | format: 'f' 12 | } 13 | }); 14 | 15 | var Table = require('cli-table'); 16 | var cli = require('../'); 17 | 18 | var options = argv; 19 | if (argv._.length) { 20 | options.repo = argv._[0]; 21 | } 22 | 23 | cli(options, function(err, dependents) { 24 | if (err) { 25 | console.error('error getting dependents for [' + options.repo + ']', err); 26 | console.error(err.message); 27 | process.exit(1); 28 | return; 29 | } 30 | 31 | var format = (typeof options.format === 'string') ? options.format.toLowerCase() : options.format; 32 | var formatFn = formatters[format] || formatters.noop; 33 | console.log(formatFn(dependents)); 34 | process.exit(0); 35 | }); 36 | 37 | var formatters = { 38 | table: function(dependents) { 39 | return createTable(dependents); 40 | }, 41 | json: function(dependents) { 42 | return JSON.stringify(dependents, null, 2); 43 | }, 44 | noop: function(dependents) { 45 | return dependents; 46 | } 47 | }; 48 | 49 | function createTable(dependents) { 50 | var head = ['module', `${options.repo}\nversion`]; 51 | var colWidths = [40, Math.max(15, options.repo.length + 2)]; 52 | var colAligns = ['left', 'left']; 53 | if (options.downloads) { 54 | head.push('downloads in the\nlast 30 days', 'total downloads'); 55 | colWidths.push(20, 20); 56 | colAligns.push('right', 'right'); 57 | } 58 | 59 | var table = new Table({ 60 | style: {compact: true}, 61 | head: head, 62 | colWidths: colWidths, 63 | colAligns: colAligns 64 | }); 65 | 66 | var total = 0; 67 | var last30 = 0; 68 | var versions = []; 69 | for (var i = 0; i < dependents.length; i++) { 70 | var repo = dependents[i]; 71 | var version = repo[`${options.repo}-version`]; 72 | if (versions.indexOf(version) === -1) { 73 | versions.push(version); 74 | } 75 | 76 | var row = [repo.name, version]; 77 | if (options.downloads) { 78 | total += repo.downloads.total; 79 | last30 += repo.downloads.last30; 80 | row.push(repo.downloads.last30.toLocaleString(), repo.downloads.total.toLocaleString()); 81 | } 82 | table.push(row); 83 | } 84 | 85 | // empty row to separate summary 86 | table.push([]); 87 | 88 | // summary row 89 | var summary = [`${dependents.length} dependents`, `${versions.length} versions`]; 90 | if (options.downloads) { 91 | summary.push(last30.toLocaleString(), total.toLocaleString()); 92 | } 93 | table.push(summary); 94 | 95 | return table.toString(); 96 | } 97 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var co = require('co'); 4 | var dependents = require('module-dependents'); 5 | 6 | module.exports = function(options, cb) { 7 | if (typeof options === 'function') { 8 | cb = options; 9 | options = {}; 10 | } 11 | options = options || {}; 12 | 13 | var name = options.repo; 14 | if (!name) { 15 | var msg = [ 16 | 'Usage:', 17 | '', 18 | ' $ dependents [options]', 19 | '' 20 | ].join('\n'); 21 | 22 | cb(new Error(msg)); 23 | return; 24 | } 25 | 26 | options.transform = function(pkgName, pkg, npm) { 27 | return co(function*() { 28 | var res ={name: pkgName}; 29 | res[`${name}-version`] = pkg.dependencies[name]; 30 | if (options.downloads) { 31 | res.downloads = {}; 32 | res.downloads.total = yield npm.repo(pkgName).total(); 33 | res.downloads.last30 = yield npm.repo(pkgName).last(30); 34 | } 35 | return res; 36 | }); 37 | }; 38 | 39 | co(function*() { 40 | return yield dependents(name, options); 41 | }) 42 | .then(function(results) { 43 | if (options.downloads) { 44 | results.sort(function(a, b) { 45 | if (a.downloads.last30 > b.downloads.last30) return -1; 46 | if (a.downloads.last30 < b.downloads.last30) return 1; 47 | return 0; 48 | }); 49 | } 50 | return cb(null, results); 51 | }, function(err) { 52 | cb(err); 53 | }); 54 | }; 55 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dependents-cli", 3 | "description": "CLI for listing an npm module's dependent projects and their download stats.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/doowb/dependents-cli", 6 | "author": "Brian Woodward (https://github.com/doowb)", 7 | "contributors": [ 8 | "Brian Woodward (https://twitter.com/doowb)", 9 | "Filip Skokan (https://github.com/panva)" 10 | ], 11 | "repository": "doowb/dependents-cli", 12 | "bugs": { 13 | "url": "https://github.com/doowb/dependents-cli/issues" 14 | }, 15 | "license": "MIT", 16 | "files": [ 17 | "bin", 18 | "index.js" 19 | ], 20 | "main": "index.js", 21 | "bin": { 22 | "dependents": "bin/cli.js" 23 | }, 24 | "engines": { 25 | "node": ">=0.10.0" 26 | }, 27 | "scripts": { 28 | "test": "mocha" 29 | }, 30 | "dependencies": { 31 | "cli-table": "^0.3.1", 32 | "co": "^4.6.0", 33 | "minimist": "^1.2.0", 34 | "module-dependents": "^0.1.4" 35 | }, 36 | "devDependencies": { 37 | "gulp-format-md": "^0.1.12" 38 | }, 39 | "keywords": [ 40 | "api", 41 | "cli", 42 | "dependents", 43 | "downloads", 44 | "module", 45 | "module-dependents", 46 | "npm", 47 | "npm-api", 48 | "npm-dependents", 49 | "package", 50 | "package-dependents" 51 | ], 52 | "verb": { 53 | "layout": "global", 54 | "tasks": [ 55 | "readme" 56 | ], 57 | "plugins": [ 58 | "gulp-format-md" 59 | ], 60 | "lint": { 61 | "reflinks": true 62 | }, 63 | "related": { 64 | "highlight": "module-dependents", 65 | "list": [ 66 | "download-stats", 67 | "module-dependents", 68 | "npm-api", 69 | "npm-api-dependents" 70 | ] 71 | }, 72 | "reflinks": [ 73 | "verb", 74 | "verb-generate-readme" 75 | ] 76 | } 77 | } 78 | --------------------------------------------------------------------------------