├── .gitignore ├── LICENSE ├── README.md ├── example.js ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 typicode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShoutJS 2 | 3 | Make your ShellJS commands explicit and get a beautiful output. 4 | 5 | ## Example 6 | 7 | Get this: 8 | 9 | ![](http://i.imgur.com/cS6MTiQ.png) 10 | 11 | With this: 12 | 13 | ```javascript 14 | var shout = require('shoutjs'); 15 | 16 | shout.mkdir('bleach'); 17 | shout.to('bleach/ichigo', 'Bankai!'); 18 | shout.rm('-rf', 'bleach'); 19 | ``` 20 | 21 | ## Commands 22 | 23 | Supported ShellJS commands are: `cp`, `rm`, `mv`, `mkdir`, `to`. 24 | 25 | ShoutJS only wraps ShellJS commands which change the filesystem. 26 | For usage information, you can go here [ShellJS](https://github.com/arturadib/shelljs). 27 | 28 | There's only ```to``` which differs from ShellJS: 29 | 30 | ```javascript 31 | var shell = require('shelljs/global'), 32 | shout = require('shoutjs'); 33 | 34 | 'Bankai!'.to('file'); // ShellJS 35 | shout.to('file', 'Bankai!'); // ShoutJS 36 | ``` 37 | 38 | ## Theming 39 | 40 | ShoutJS supports theming through [Logan](http://typicode.github.com/logan). 41 | So it's possible to customize ShoutJS output pretty much the way you want. 42 | 43 | Here is the default theme: 44 | 45 | ```javascript 46 | // Default theme 47 | shout.logan.set({ 48 | cp : [' copy % to %', 'cyan . cyan .'], 49 | rm : [' remove % ', 'red '], 50 | mv : [' move % to %', 'cyan . cyan .'], 51 | mkdir : [' create % ', 'cyan '], 52 | to : [' create % ', 'cyan '], 53 | exec : [' exec % ', 'blue . '] 54 | }); 55 | ``` 56 | 57 | To override it: 58 | 59 | ```javascript 60 | // A bit more old fashioned theme... 61 | shout.logan.set({ 62 | cp : ['cp % %', 'grey'], 63 | rm : ['rm % ', 'grey'], 64 | // ... 65 | }); 66 | ``` 67 | 68 | ## Adding new messages 69 | 70 | In many cases, you may want to log more than ShellJS commands for your users. 71 | The recommanded way is to use [Logan](http://typicode.github.com/logan). 72 | 73 | Here's an example: 74 | 75 | ```javascript 76 | var shout = require('shoutjs'), 77 | logan = require('logan'); 78 | 79 | logan.set({ 80 | info: [' info %', 'yellow'] 81 | }); 82 | 83 | logan.info('starting script...'); 84 | shout.rm('file.txt'); 85 | logan.info('done'); 86 | ``` 87 | 88 | ## Configuration 89 | 90 | You can disable ShoutJS output using ```logan.silent``` option. 91 | 92 | ```javascript 93 | shout.logan.silent = true; 94 | shout.to('ichigo.txt', 'Bankai!'); // No output 95 | ``` 96 | 97 | ## Issues 98 | 99 | Have a bug or missing a new command introduced in ShellJS? Please create an issue here on GitHub! 100 | 101 | ## Themes 102 | 103 | If you've created a theme for ShellJS feel free to drop me a message [@typicode](https://github.com/typicode). 104 | 105 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | var shell = require('shelljs'), 2 | shout = require('./'); 3 | 4 | console.log(); 5 | 6 | shout.mkdir('bleach'); 7 | shout.to('bleach/ichigo', 'Bankai!'); 8 | shout.rm('-rf', 'bleach'); 9 | 10 | console.log(); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var logan = require('logan'), 2 | shell = require('shelljs'); 3 | 4 | logan.set({ 5 | cp : [' copy % to %', 'cyan . cyan .'], 6 | rm : [' remove % ', 'red '], 7 | mv : [' move % to %', 'cyan . cyan .'], 8 | mkdir : [' create % ', 'cyan '], 9 | to : [' create % ', 'cyan '], 10 | exec : [' exec % ', 'blue . '] 11 | }); 12 | 13 | var __slice = Array.prototype.slice; 14 | 15 | module.exports = { 16 | // expose logan 17 | logan: logan, 18 | 19 | // Flatten an array 20 | _flatten: function(array) { 21 | return [].concat.apply([], array); 22 | }, 23 | 24 | // returns true is string starts with '-'' 25 | _isOption: function(string) { 26 | return string.charAt(0) === '-' 27 | }, 28 | 29 | // Removes items from array which start with '-' 30 | _stripOptions: function() { 31 | var that = this; 32 | return __slice.call(arguments).filter(function(item) { 33 | return !that._isOption(item); 34 | }); 35 | }, 36 | 37 | // Returns "first" part of an array (ie all except last) 38 | // useful for cp or mv functions which can have source(s) and a dest 39 | _getSources: function() { 40 | return this._stripOptions.apply(this, arguments).slice(0, -1); 41 | }, 42 | 43 | // Returns last item of an array 44 | _getDest: function() { 45 | return this._stripOptions.apply(this, arguments).slice(-1)[0]; 46 | }, 47 | 48 | /* 49 | * ShellJS wrapped functions 50 | */ 51 | cp: function() { 52 | var sources = this._getSources.apply(this, arguments), 53 | dest = this._getDest.apply(this, arguments); 54 | 55 | sources.forEach(function(source) { 56 | logan.cp(source, dest); 57 | }); 58 | 59 | shell.cp.apply(this, __slice.call(arguments)); 60 | }, 61 | 62 | rm: function() { 63 | var files = this._stripOptions.apply(this, arguments); 64 | 65 | files.forEach(logan.rm); 66 | 67 | shell.rm.apply(this, __slice.call(arguments)); 68 | }, 69 | 70 | mv: function() { 71 | var sources = this._getSources.apply(this, arguments), 72 | dest = this._getDest.apply(this, arguments); 73 | 74 | sources.forEach(function(source) { 75 | logan.mv(source, dest); 76 | }); 77 | 78 | shell.mv.apply(this, __slice.call(arguments)); 79 | }, 80 | 81 | mkdir: function() { 82 | var dirs = this._stripOptions.apply(this, arguments); 83 | 84 | dirs.forEach(logan.mkdir); 85 | 86 | shell.mkdir.apply(this, __slice.call(arguments)); 87 | }, 88 | 89 | to: function() { 90 | var file = arguments[0], 91 | string = arguments[1]; 92 | 93 | logan.to(file); 94 | 95 | string.to(file); 96 | }, 97 | 98 | exec: function() { 99 | logan.exec(arguments[0]); 100 | 101 | shell.exec.apply(this, __slice.call(arguments)); 102 | } 103 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shoutjs", 3 | "version": "0.0.2", 4 | "description": "Beautiful output for your ShellJS commands", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/typicode/shoutjs.git" 12 | }, 13 | "keywords": [ 14 | "shelljs", 15 | "shell", 16 | "unix", 17 | "output", 18 | "cli", 19 | "command", 20 | "log", 21 | "logs", 22 | "logging" 23 | ], 24 | "author": "Typicode", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/typicode/shoutjs/issues" 28 | }, 29 | "dependencies": { 30 | "logan": "*", 31 | "shelljs": "*" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | shout = require('./index'); 3 | 4 | describe('shout', function() { 5 | describe('_flatten', function() { 6 | it('should flatten array', function() { 7 | assert.deepEqual(shout._flatten([1, [2], 3]), [1, 2, 3]); 8 | }); 9 | }); 10 | 11 | describe('_isOption', function() { 12 | it('should return true if string starts with "-"', function() { 13 | assert(shout._isOption('-a')); 14 | }); 15 | 16 | it('should return false if string starts with something else than "-"', function() { 17 | assert(!shout._isOption('a')); 18 | }); 19 | }); 20 | 21 | describe('_stripOptions', function() { 22 | it('should remove strings starting with "-" from array', function() { 23 | assert.deepEqual(shout._stripOptions('-a', 'b', '-c'), ['b']); 24 | }); 25 | }); 26 | 27 | describe('_getSources', function() { 28 | it('should return the array without the last element (which should be the dest)', function() { 29 | assert.deepEqual(shout._getSources('a', 'b', 'c'), ['a', 'b']); 30 | }); 31 | }); 32 | 33 | describe('_getDest', function() { 34 | it('should return the the last element of the array', function() { 35 | assert.deepEqual(shout._getDest('a', 'b', 'c'), 'c'); 36 | }); 37 | }); 38 | 39 | it('should have properties logan, cp, rm, mv, mkdir, exec', function() { 40 | ['logan', 'cp', 'rm', 'mv', 'mkdir', 'to', 'exec'].forEach(function(property) { 41 | assert(shout.hasOwnProperty(property)); 42 | }); 43 | }); 44 | }); --------------------------------------------------------------------------------