├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package-lock.json ├── package.json ├── screenshot.js ├── screenshot.png └── screenshot.svg /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Siddharth Kshetrapal 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | Pretty print messages on the terminal 5 |

6 |

7 | 8 | #### Usage 9 | 10 | ```js 11 | 12 | // Require what you need from prettycli 13 | 14 | const {info, warn} = require('prettycli'); 15 | 16 | /* 17 | 18 | There are 6 functions: 19 | 20 | Print to stdout: 21 | 1. info: (label, message) 22 | 2. loading: (label, message) 23 | 3. warn: (message) 24 | 4. error: (message) 25 | 26 | Returns pretty string (does not print) 27 | 5. command: (command) 28 | 6. link: (url) 29 | 30 | */ 31 | 32 | if (!process.env.PRODUCTION) info('BUILD', 'Running dev stuff'); 33 | else warn('This is production mode! Are you sure?'); 34 | 35 | ``` 36 | 37 |   38 | 39 | #### license 40 | 41 | MIT © [siddharthkp](https://github.com/siddharthkp) -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk') 2 | 3 | const colorMap = { 4 | info: 'green', 5 | warn: 'yellow', 6 | loading: 'blue', 7 | error: 'red' 8 | } 9 | 10 | const print = (type, label, message) => { 11 | const color = colorMap[type] 12 | console.log( 13 | chalk.inverse.bold[color](` ${label} `), 14 | chalk[color](message), 15 | '\n' 16 | ) 17 | } 18 | 19 | const info = (label, message) => print('info', label, message) 20 | const warn = message => print('warn', 'WARN', message) 21 | const loading = (label, message) => print('loading', label, message) 22 | 23 | const command = command => chalk.blue(command) 24 | const link = url => chalk.blue(url) 25 | 26 | const error = (err, options) => { 27 | const label = 'ERROR' 28 | if (!options) options = { exit: true, silent: false, label } 29 | print('error', options.label || label, err) 30 | if (options.silent) process.exit(1) 31 | if (options.exit) throw new Error(err) 32 | } 33 | 34 | module.exports = { info, loading, warn, error, command, link } 35 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettycli", 3 | "version": "1.4.3", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "chalk": { 8 | "version": "2.1.0", 9 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz", 10 | "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==", 11 | "requires": { 12 | "ansi-styles": "3.2.0", 13 | "escape-string-regexp": "1.0.5", 14 | "supports-color": "4.2.1" 15 | }, 16 | "dependencies": { 17 | "ansi-styles": { 18 | "version": "3.2.0", 19 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", 20 | "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", 21 | "requires": { 22 | "color-convert": "1.9.0" 23 | } 24 | }, 25 | "supports-color": { 26 | "version": "4.2.1", 27 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.2.1.tgz", 28 | "integrity": "sha512-qxzYsob3yv6U+xMzPrv170y8AwGP7i74g+pbixCfD6rgso8BscLT2qXIuz6TpOaiJZ3mFgT5O9lyT9nMU4LfaA==", 29 | "requires": { 30 | "has-flag": "2.0.0" 31 | } 32 | } 33 | } 34 | }, 35 | "color-convert": { 36 | "version": "1.9.0", 37 | "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.0.tgz", 38 | "integrity": "sha1-Gsz5fdc5uYO/mU1W/sj5WFNkG3o=", 39 | "requires": { 40 | "color-name": "1.1.3" 41 | } 42 | }, 43 | "color-name": { 44 | "version": "1.1.3", 45 | "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", 46 | "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" 47 | }, 48 | "escape-string-regexp": { 49 | "version": "1.0.5", 50 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 51 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" 52 | }, 53 | "has-flag": { 54 | "version": "2.0.0", 55 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", 56 | "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettycli", 3 | "version": "1.4.3", 4 | "description": "Pretty print messages on the terminal", 5 | "main": "index.js", 6 | "author": "siddharthkp", 7 | "bugs": { 8 | "url": "https://github.com/practo/prettycli/issues" 9 | }, 10 | "license": "MIT", 11 | "repository": "siddharthkp/prettycli", 12 | "homepage": "https://github.com/siddharthkp/prettycli", 13 | "dependencies": { 14 | "chalk": "2.1.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /screenshot.js: -------------------------------------------------------------------------------- 1 | const log = require('.'); 2 | 3 | console.log(''); 4 | 5 | log.loading('TEST', 'Running unit tests...'); 6 | 7 | log.info('READY', `Server running on ${log.link('http://localhost:3000')}`); 8 | 9 | log.warn('This feature will be deprecated soon.'); 10 | 11 | log.error('Could not find express. Make sure you have installed it', { 12 | exit: false 13 | }); 14 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siddharthkp/prettycli/415f95017c471baf753a88076182a12c3b2aac9d/screenshot.png -------------------------------------------------------------------------------- /screenshot.svg: -------------------------------------------------------------------------------- 1 | TESTRunningunittests...READYServerrunningonhttp://localhost:3000WARNThisfeaturewillbedeprecatedsoon.ERRORCouldnotfindexpress.Makesureyouhaveinstalledit --------------------------------------------------------------------------------