├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── cli.js ├── index.js ├── lib └── ls.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jake Trent 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Unmaintained] We had a good run. It was such a good idea, now `npm run` does this natively. Use that instead. 2 | 3 | npm-ls-scripts 4 | ============== 5 | 6 | **List runnable npm scripts** 7 | 8 | Inspired by `rake -T`, which will show you all the tasks runnable by rake, this script will show you all the runnable scripts that npm's package.json knows about. 9 | 10 | ### Usage 11 | 12 | Npm lets you define [scripts](https://www.npmjs.org/doc/misc/npm-scripts.html) that npm can run. Your `package.json` will include: 13 | 14 | ``` 15 | { 16 | "scripts": { 17 | "start": "node app.js", 18 | "job": "node my/one-off/job.js" 19 | } 20 | } 21 | ``` 22 | 23 | You could cat `package.json`, but that's lame. Instead, install `npm-ls-scripts`: 24 | 25 | ``` 26 | npm install npm-ls-scripts --save 27 | ``` 28 | 29 | And run: 30 | 31 | ``` 32 | ls-scripts 33 | ``` 34 | 35 | And see the scripts in a nice list: 36 | 37 | ``` 38 | NPM - ls scripts 39 | --- 40 | start - node app.js 41 | job - node my/one-off/job.js 42 | --- 43 | ``` 44 | 45 | Note: `ls-scripts` is the binary that comes with this package. To use, adjust your path to include: 46 | 47 | ``` 48 | export PATH=./node_modules/.bin:$PATH 49 | ``` 50 | 51 | Alternately, after installation, you could type: 52 | 53 | ``` 54 | node_modules/.bin/ls-scripts 55 | ``` 56 | 57 | Or different still, you make a script to run `npm-ls-scripts` in your `package.json`: 58 | 59 | ``` 60 | { 61 | "scripts": { 62 | "ls": "node_modules/.bin/ls-scripts" 63 | } 64 | } 65 | ``` 66 | 67 | And run with: 68 | 69 | ``` 70 | npm run ls 71 | ``` 72 | 73 | ### Config 74 | 75 | You can make the output even nice by adding a verbal description to scripts that may be helped by it. Add config via your `package.json`: 76 | 77 | ``` 78 | { 79 | "config": { 80 | "scripts": { 81 | "job": "I would gladly do the job" 82 | } 83 | }, 84 | "scripts": { 85 | "start": "node app.js", 86 | "job": "node my/one-off/job.js" 87 | } 88 | } 89 | ``` 90 | 91 | Make sure the script names match between `config` and `scripts`. 92 | 93 | Run with this config, and you should see: 94 | 95 | ``` 96 | NPM - ls scripts 97 | --- 98 | start - node app.js 99 | job - I would gladly do the job 100 | --- 101 | ``` 102 | 103 | Note that you do not need to specify a description for all scripts if it's not useful or your fingers are tired. 104 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/ls')() -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/ls') -------------------------------------------------------------------------------- /lib/ls.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | 3 | var preface = 'NPM - ls scripts\n---\n' 4 | 5 | // from underscore#max 6 | var max = function (obj, iterator, context) { 7 | var result = {computed : -Infinity, value: -Infinity} 8 | obj.forEach(function(value, index, list) { 9 | var computed = iterator ? iterator.call(context, value, index, list) : value 10 | computed > result.computed && (result = { value : value, computed : computed }) 11 | }) 12 | return result.value 13 | } 14 | 15 | // from underscore.string#strRepeat 16 | var strRepeat = function(str, qty){ 17 | if (qty < 1) return '' 18 | var result = '' 19 | while (qty > 0) { 20 | if (qty & 1) result += str 21 | qty >>= 1, str += str 22 | } 23 | return result 24 | } 25 | 26 | // from underscore.string#pad 27 | var rpad = function (str, length, padStr) { 28 | str = str == null ? '' : String(str) 29 | length = ~~length 30 | 31 | if (!padStr) 32 | padStr = ' ' 33 | else if (padStr.length > 1) 34 | padStr = padStr.charAt(0) 35 | 36 | var padlen = length - str.length 37 | return str + strRepeat(padStr, padlen) 38 | } 39 | 40 | var formatName = function (name, longest) { 41 | return rpad(name, longest, ' ') 42 | } 43 | 44 | var bestDesc = function (scriptName, pkg) { 45 | var cmd = pkg.scripts[scriptName] 46 | var desc = pkg.config && pkg.config.scripts ? pkg.config.scripts[scriptName] : null 47 | return desc ? desc : cmd 48 | } 49 | 50 | var ls = function () { 51 | fs.readFile('package.json', 'utf8', function (err, data) { 52 | if (err) throw err 53 | 54 | var pkg = JSON.parse(data) 55 | var scriptNames = Object.keys(pkg.scripts) 56 | var longest = max(scriptNames, function (name) { return name.length }).length 57 | var str = preface + scriptNames.map(function (name) { 58 | return formatName(name, longest) + ' - ' + bestDesc(name, pkg) 59 | }).sort().join('\n') 60 | 61 | console.log(str + '\n---\n') 62 | }) 63 | } 64 | 65 | module.exports = ls -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-ls-scripts", 3 | "version": "0.1.2", 4 | "description": "List runnable npm scripts in package.json", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/jaketrent/npm-ls-scripts.git" 9 | }, 10 | "keywords": [ 11 | "npm", 12 | "npm scripts", 13 | "package.json", 14 | "rake -T" 15 | ], 16 | "author": "jaketrent", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/jaketrent/npm-ls-scripts/issues" 20 | }, 21 | "homepage": "https://github.com/jaketrent/npm-ls-scripts", 22 | "bin": { 23 | "ls-scripts": "./bin/cli.js" 24 | } 25 | } 26 | --------------------------------------------------------------------------------