Browse files

Set indentation as 2 spaces

  • Loading branch information...
1 parent f0f60ea commit fc4468f2b7d1d951d505dad55da7225490e559e6 @wdavidw committed Nov 13, 2012
View
21 bin/dev
@@ -1,13 +1,14 @@
-#!/usr/bin/env coffee
+#!/usr/bin/env node
-shell = require 'shell'
+var shell = require('shell');
-app = module.exports = shell chdir: true
+var app = module.exports = shell({chdir: true});
-app.configure ->
- app.use shell.history shell: app
- app.use shell.completer shell: app
- app.use shell.cloud9 port: '4102'
- app.use shell.router shell: app
- app.use shell.help {shell: app, introduction: true}
- app.use shell.error shell: app
+app.configure(function(){
+ app.use( shell.history({shell: app}) );
+ app.use( shell.completer({shell: app}) );
+ app.use( shell.cloud9({port: '4102'}) );
+ app.use( shell.router({shell: app}) );
+ app.use( shell.help({shell: app, introduction: true}) );
+ app.use( shell.error({shell: app}) );
+});
View
10 index.js
@@ -20,12 +20,12 @@ Shell.test = require('./lib/plugins/test');
// Routes
Shell.routes = {
- confirm: require('./lib/routes/confirm'),
- prompt: require('./lib/routes/prompt'),
- shellOnly: require('./lib/routes/shellOnly')
+ confirm: require('./lib/routes/confirm'),
+ prompt: require('./lib/routes/prompt'),
+ shellOnly: require('./lib/routes/shellOnly')
};
Shell.Shell = function(settings){
- console.warn('Deprecated, use `shell()` instead of `shell.Shell()`');
- return new Shell( settings );
+ console.warn('Deprecated, use `shell()` instead of `shell.Shell()`');
+ return new Shell( settings );
};
View
28 lib/NullStream.coffee
@@ -2,17 +2,17 @@
events = require 'events'
module.exports = class NullStream extends events.EventEmitter
- # Readable Stream
- readable: true
- pause: ->
- resume: ->
- pipe: ->
- # Writable Stream
- writable: true
- write: (data) ->
- @emit 'data', data
- end: ->
- @emit 'close'
- # Shared API
- destroy: ->
- destroySoon: ->
+ # Readable Stream
+ readable: true
+ pause: ->
+ resume: ->
+ pipe: ->
+ # Writable Stream
+ writable: true
+ write: (data) ->
+ @emit 'data', data
+ end: ->
+ @emit 'close'
+ # Shared API
+ destroy: ->
+ destroySoon: ->
View
110 lib/Request.coffee
@@ -2,58 +2,58 @@
each = require 'each'
module.exports = class Request
- constructor: (shell, command) ->
- @shell = shell
- @command = command
- ###
- Ask one or more questions
- ###
- question: (questions, callback) ->
- isObject = (v) -> typeof v is 'object' and v? and not Array.isArray v
- multiple = true
- answers = {}
- if isObject questions
- questions = for q, v of questions
- v ?= {}
- v = { value: v } unless isObject v
- v.name = q
- v
- else if typeof questions is 'string'
- multiple = false
- questions = [{name: questions, value: ''}]
- each(questions)
- .on 'item', (next, question) =>
- q = "#{question.name} "
- q += "[#{question.value}] " if question.value
- @shell.interface().question q, (answer) ->
- answer = answer.substr(0, answer.length - 1) if answer.substr(-1, 1) is '\n'
- answers[question.name] =
- if answer is '' then question.value else answer
- next()
- .on 'end', ->
- answers = answers[questions[0].name] unless multiple
- return callback answers
- ###
- Ask a question expecting a boolean answer
- ###
- confirm: (msg, defaultTrue, callback) ->
- args = arguments
- unless callback
- callback = defaultTrue
- defaultTrue = true
- @shell.settings.key_true ?= 'y'
- @shell.settings.key_false ?= 'n'
- key_true = @shell.settings.key_true.toLowerCase()
- key_false = @shell.settings.key_false.toLowerCase()
- keyTrue = if defaultTrue then key_true.toUpperCase() else key_true
- keyFalse = if defaultTrue then key_false else key_false.toUpperCase()
- msg += ' '
- msg += "[#{keyTrue}#{keyFalse}] "
- question = @shell.styles.raw( msg, {color: 'green'})
- @shell.interface().question question, (answer) =>
- accepted = ['', key_true, key_false]
- answer = answer.substr(0, answer.length - 1) if answer.substr(-1, 1) is '\n'
- answer = answer.toLowerCase()
- valid = accepted.indexOf(answer) isnt -1
- return @confirm.apply(@, args) unless valid
- callback answer is key_true or (defaultTrue and answer is '')
+ constructor: (shell, command) ->
+ @shell = shell
+ @command = command
+ ###
+ Ask one or more questions
+ ###
+ question: (questions, callback) ->
+ isObject = (v) -> typeof v is 'object' and v? and not Array.isArray v
+ multiple = true
+ answers = {}
+ if isObject questions
+ questions = for q, v of questions
+ v ?= {}
+ v = { value: v } unless isObject v
+ v.name = q
+ v
+ else if typeof questions is 'string'
+ multiple = false
+ questions = [{name: questions, value: ''}]
+ each(questions)
+ .on 'item', (next, question) =>
+ q = "#{question.name} "
+ q += "[#{question.value}] " if question.value
+ @shell.interface().question q, (answer) ->
+ answer = answer.substr(0, answer.length - 1) if answer.substr(-1, 1) is '\n'
+ answers[question.name] =
+ if answer is '' then question.value else answer
+ next()
+ .on 'end', ->
+ answers = answers[questions[0].name] unless multiple
+ return callback answers
+ ###
+ Ask a question expecting a boolean answer
+ ###
+ confirm: (msg, defaultTrue, callback) ->
+ args = arguments
+ unless callback
+ callback = defaultTrue
+ defaultTrue = true
+ @shell.settings.key_true ?= 'y'
+ @shell.settings.key_false ?= 'n'
+ key_true = @shell.settings.key_true.toLowerCase()
+ key_false = @shell.settings.key_false.toLowerCase()
+ keyTrue = if defaultTrue then key_true.toUpperCase() else key_true
+ keyFalse = if defaultTrue then key_false else key_false.toUpperCase()
+ msg += ' '
+ msg += "[#{keyTrue}#{keyFalse}] "
+ question = @shell.styles.raw( msg, {color: 'green'})
+ @shell.interface().question question, (answer) =>
+ accepted = ['', key_true, key_false]
+ answer = answer.substr(0, answer.length - 1) if answer.substr(-1, 1) is '\n'
+ answer = answer.toLowerCase()
+ valid = accepted.indexOf(answer) isnt -1
+ return @confirm.apply(@, args) unless valid
+ callback answer is key_true or (defaultTrue and answer is '')
View
14 lib/Response.coffee
@@ -3,10 +3,10 @@ styles = require './Styles'
pad = require 'pad'
module.exports = class Response extends styles
- constructor: (settings) ->
- @shell = settings.shell
- super settings
- pad: pad
- prompt: ->
- @shell.prompt()
-
+ constructor: (settings) ->
+ @shell = settings.shell
+ super settings
+ pad: pad
+ prompt: ->
+ @shell.prompt()
+
View
270 lib/Shell.coffee
@@ -12,142 +12,142 @@ Response = require './Response'
# Fix readline interface
Interface = require('readline').Interface
Interface.prototype.setPrompt = ( (parent) ->
- (prompt, length) ->
- args = Array.prototype.slice.call arguments
- args[1] = styles.unstyle(args[0]).length if not args[1]
- parent.apply @, args
+ (prompt, length) ->
+ args = Array.prototype.slice.call arguments
+ args[1] = styles.unstyle(args[0]).length if not args[1]
+ parent.apply @, args
)( Interface.prototype.setPrompt )
module.exports = class Shell extends EventEmitter
- constructor: (settings = {}) ->
- return new Shell(settings) if @ not instanceof Shell
- EventEmitter.call @
- @tmp = {}
- @settings = settings
- @settings.prompt ?= '>> '
- @settings.stdin ?= process.stdin
- @settings.stdout ?= process.stdout
- @set 'env', @settings.env ? process.env.NODE_ENV ? 'development'
- @set 'command',
- if typeof settings.command isnt 'undefined'
- then settings.command
- else process.argv.slice(2).join(' ')
- @stack = []
- @styles = styles {stdout: @settings.stdout}
- process.on 'beforeExit', =>
- @emit 'exit'
- process.on 'uncaughtException', (e) =>
- @emit 'exit', [e]
- @styles.red('Internal error, closing...').ln()
- console.error e.message
- console.error e.stack
- process.exit()
- @isShell = this.settings.isShell ? process.argv.length is 2
- @interface() if @isShell
- # Project root directory
- settings.workspace ?= utils.workspace()
- # Current working directory
- process.chdir settings.workspace if settings.chdir is true
- process.chdir settings.chdir if typeof settings.chdir is 'string'
- # Start
- process.nextTick =>
- if @isShell
- command = @set 'command'
- noPrompt = @set 'noPrompt'
- if command
- @run command
- else if not noPrompt
- @prompt()
- else
- command = @set 'command'
- @run command if command
- return @
-
- # Return the readline interface and create it if not yet initialized
- interface: () ->
- return @_interface if @_interface?
- @_interface = readline.createInterface @settings.stdin, @settings.stdout
-
- # Configure callback for the given `env`
- configure: (env, fn) ->
- if typeof env is 'function'
- fn = env
- env = 'all'
- if env is 'all' or env is @settings.env
- fn.call @
- @
-
- # Configure callback for the given `env`
- use: (handle) ->
- # Add the route, handle pair to the stack
- if handle
- @stack.push { route: null, handle: handle }
- # Allow chaining
- @
-
- # Store commands
- cmds: {}
-
- # Run a command
- run: (command) ->
- command = command.trim()
- @emit 'command', [command]
- @emit command, []
- self = @
- req = new Request @, command
- res = new Response {shell: @, stdout: @settings.stdout}
- index = 0
- next = (err) ->
- layer = self.stack[ index++ ]
- if not layer
- return self.emit('error', err) if err
- if command isnt ''
- text = "Command failed to execute #{command}"
- text += ": #{err.message or err.name}" if err
- res.red text
- return res.prompt()
- arity = layer.handle.length
- if err
- if arity is 4
- self.emit('error', err)
- layer.handle err, req, res, next
- else
- next err
- else if arity < 4
- layer.handle req, res, next
- else
- next()
- next()
-
- set: (setting, val) ->
- if not val?
- if @settings.hasOwnProperty setting
- return @settings[setting]
- else if @parent
- # for the future, parent being undefined for now
- return @parent.set setting
- else
- @settings[setting] = val
- @
-
- # Display prompt
- prompt: ->
- if @isShell
- text = @styles.raw( @settings.prompt, {color: 'green'})
- @interface().question text, @run.bind(@)
+ constructor: (settings = {}) ->
+ return new Shell(settings) if @ not instanceof Shell
+ EventEmitter.call @
+ @tmp = {}
+ @settings = settings
+ @settings.prompt ?= '>> '
+ @settings.stdin ?= process.stdin
+ @settings.stdout ?= process.stdout
+ @set 'env', @settings.env ? process.env.NODE_ENV ? 'development'
+ @set 'command',
+ if typeof settings.command isnt 'undefined'
+ then settings.command
+ else process.argv.slice(2).join(' ')
+ @stack = []
+ @styles = styles {stdout: @settings.stdout}
+ process.on 'beforeExit', =>
+ @emit 'exit'
+ process.on 'uncaughtException', (e) =>
+ @emit 'exit', [e]
+ @styles.red('Internal error, closing...').ln()
+ console.error e.message
+ console.error e.stack
+ process.exit()
+ @isShell = this.settings.isShell ? process.argv.length is 2
+ @interface() if @isShell
+ # Project root directory
+ settings.workspace ?= utils.workspace()
+ # Current working directory
+ process.chdir settings.workspace if settings.chdir is true
+ process.chdir settings.chdir if typeof settings.chdir is 'string'
+ # Start
+ process.nextTick =>
+ if @isShell
+ command = @set 'command'
+ noPrompt = @set 'noPrompt'
+ if command
+ @run command
+ else if not noPrompt
+ @prompt()
+ else
+ command = @set 'command'
+ @run command if command
+ return @
+
+ # Return the readline interface and create it if not yet initialized
+ interface: () ->
+ return @_interface if @_interface?
+ @_interface = readline.createInterface @settings.stdin, @settings.stdout
+
+ # Configure callback for the given `env`
+ configure: (env, fn) ->
+ if typeof env is 'function'
+ fn = env
+ env = 'all'
+ if env is 'all' or env is @settings.env
+ fn.call @
+ @
+
+ # Configure callback for the given `env`
+ use: (handle) ->
+ # Add the route, handle pair to the stack
+ if handle
+ @stack.push { route: null, handle: handle }
+ # Allow chaining
+ @
+
+ # Store commands
+ cmds: {}
+
+ # Run a command
+ run: (command) ->
+ command = command.trim()
+ @emit 'command', [command]
+ @emit command, []
+ self = @
+ req = new Request @, command
+ res = new Response {shell: @, stdout: @settings.stdout}
+ index = 0
+ next = (err) ->
+ layer = self.stack[ index++ ]
+ if not layer
+ return self.emit('error', err) if err
+ if command isnt ''
+ text = "Command failed to execute #{command}"
+ text += ": #{err.message or err.name}" if err
+ res.red text
+ return res.prompt()
+ arity = layer.handle.length
+ if err
+ if arity is 4
+ self.emit('error', err)
+ layer.handle err, req, res, next
else
- @styles.ln()
- if process.versions
- @quit()
- else
- # Node v0.6.1 throw error 'process.stdout cannot be closed'
- @settings.stdout.destroySoon();
- @settings.stdout.on 'close', ->
- process.exit()
-
- # Command quit
- quit: (params) ->
- @emit 'quit'
- @interface().close()
- @settings.stdin.destroy()
- #@set 'stdin', null
+ next err
+ else if arity < 4
+ layer.handle req, res, next
+ else
+ next()
+ next()
+
+ set: (setting, val) ->
+ if not val?
+ if @settings.hasOwnProperty setting
+ return @settings[setting]
+ else if @parent
+ # for the future, parent being undefined for now
+ return @parent.set setting
+ else
+ @settings[setting] = val
+ @
+
+ # Display prompt
+ prompt: ->
+ if @isShell
+ text = @styles.raw( @settings.prompt, {color: 'green'})
+ @interface().question text, @run.bind(@)
+ else
+ @styles.ln()
+ if process.versions
+ @quit()
+ else
+ # Node v0.6.1 throw error 'process.stdout cannot be closed'
+ @settings.stdout.destroySoon();
+ @settings.stdout.on 'close', ->
+ process.exit()
+
+ # Command quit
+ quit: (params) ->
+ @emit 'quit'
+ @interface().close()
+ @settings.stdin.destroy()
+ #@set 'stdin', null
View
150 lib/Styles.coffee
@@ -1,116 +1,116 @@
colors =
- black: 30
- red: 31
- green: 32
- yellow: 33
- blue: 34
- magenta: 35
- cyan: 36
- white: 37
+ black: 30
+ red: 31
+ green: 32
+ yellow: 33
+ blue: 34
+ magenta: 35
+ cyan: 36
+ white: 37
bgcolors =
- black: 40
- red: 41
- green: 42
- yellow: 43
- blue: 44
- magenta: 45
- cyan: 46
- white: 47
+ black: 40
+ red: 41
+ green: 42
+ yellow: 43
+ blue: 44
+ magenta: 45
+ cyan: 46
+ white: 47
module.exports = Styles = (settings = {}) ->
- if @ not instanceof Styles
- return new Styles settings
- @settings = settings
- @settings.stdout = settings.stdout ? process.stdout
- # Current state
- @current =
- weight: 'regular'
- # Export colors
- @colors = colors
- @bgcolors = bgcolors
- @
+ if @ not instanceof Styles
+ return new Styles settings
+ @settings = settings
+ @settings.stdout = settings.stdout ? process.stdout
+ # Current state
+ @current =
+ weight: 'regular'
+ # Export colors
+ @colors = colors
+ @bgcolors = bgcolors
+ @
# Color
Styles.prototype.color = (color, text) ->
- @print text, {color: color}
- # Save state if no text
- @current.color = color unless text
- @
+ @print text, {color: color}
+ # Save state if no text
+ @current.color = color unless text
+ @
for color, code of colors
- do (color) ->
- Styles.prototype[color] = (text) ->
- @color color, text
+ do (color) ->
+ Styles.prototype[color] = (text) ->
+ @color color, text
Styles.prototype.nocolor = (text) ->
- @color null, text
+ @color null, text
# bgcolor
Styles.prototype.bgcolor = (bgcolor) ->
- bgcolor ?= 0
- @print '\x1B[' + bgcolor + ';m39'
- @
+ bgcolor ?= 0
+ @print '\x1B[' + bgcolor + ';m39'
+ @
# Font weight
Styles.prototype.weight = (weight, text) ->
- @print text, {weight: weight}
- if not text
- # Save state if no text
- @current.weight = weight
- @
+ @print text, {weight: weight}
+ if not text
+ # Save state if no text
+ @current.weight = weight
+ @
Styles.prototype.bold = (text) ->
- @weight 'bold', text
+ @weight 'bold', text
Styles.prototype.regular = (text) ->
- @weight 'regular', text
+ @weight 'regular', text
# Print
Styles.prototype.print = (text, settings) ->
- @settings.stdout.write @raw(text, settings)
- @
+ @settings.stdout.write @raw(text, settings)
+ @
Styles.prototype.println = (text) ->
- @settings.stdout.write text + '\n'
- @
+ @settings.stdout.write text + '\n'
+ @
Styles.prototype.ln = ->
- @settings.stdout.write '\n'
- @
+ @settings.stdout.write '\n'
+ @
# Others
Styles.prototype.raw = (text, settings) ->
- raw = '';
- settings ?= {}
- if settings.color isnt null and ( settings.color or @current.color )
- raw += '\x1b[' + @colors[settings.color or @current.color] + 'm'
+ raw = '';
+ settings ?= {}
+ if settings.color isnt null and ( settings.color or @current.color )
+ raw += '\x1b[' + @colors[settings.color or @current.color] + 'm'
+ else
+ raw += '\x1b[39m'
+ switch settings.weight or @current.weight
+ when 'bold'
+ raw += '\x1b[1m'
+ when 'regular'
+ raw += '\x1b[22m'
else
- raw += '\x1b[39m'
- switch settings.weight or @current.weight
- when 'bold'
- raw += '\x1b[1m'
- when 'regular'
- raw += '\x1b[22m'
- else
- throw new Error 'Invalid weight "' + weight + '" (expect "bold" or "regular")'
- if text
- # Print text if any
- raw += text
- # Restore state if any
- if @current.color and @current.color isnt settings.color
- raw += @raw null, @current.color
- if @current.weight and @current.weight isnt settings.weight
- raw += @raw null, @current.weight
- raw
+ throw new Error 'Invalid weight "' + weight + '" (expect "bold" or "regular")'
+ if text
+ # Print text if any
+ raw += text
+ # Restore state if any
+ if @current.color and @current.color isnt settings.color
+ raw += @raw null, @current.color
+ if @current.weight and @current.weight isnt settings.weight
+ raw += @raw null, @current.weight
+ raw
Styles.prototype.reset = (text) ->
- @print null,
- color: null
- weight: 'regular'
+ @print null,
+ color: null
+ weight: 'regular'
# Remove style
Styles.unstyle = (text) -> text.replace(/\x1b.*?m/g, '')
View
130 lib/plugins/cloud9.coffee
@@ -25,21 +25,21 @@ Options:
- `stderr` , Writable stream or file path to redirect cloud9 stderr.
Example:
-
+
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
- app.use(shell.cloud9({
- shell: app,
- ip: '0.0.0.0'
- }));
- app.use(shell.help({
- shell: app,
- introduction: true
- }));
+ app.use(shell.router({
+ shell: app
+ }));
+ app.use(shell.cloud9({
+ shell: app,
+ ip: '0.0.0.0'
+ }));
+ app.use(shell.help({
+ shell: app,
+ introduction: true
+ }));
});
```
@@ -56,57 +56,57 @@ npm link
###
module.exports = (settings = {}) ->
- cmd = () ->
- args = []
- args.push '-w'
- args.push settings.workspace
- # Arguments
- if settings.config
- args.push '-c'
- args.push settings.config
- if settings.group
- args.push '-g'
- args.push settings.group
- if settings.user
- args.push '-u'
- args.push settings.user
- if settings.action
- args.push '-a'
- args.push settings.action
- if settings.ip
- args.push '-l'
- args.push settings.ip
- if settings.port
- args.push '-p'
- args.push settings.port
- "cloud9 #{args.join(' ')}"
- (req, res, next) ->
- app = req.shell
- # Caching
- return next() if app.tmp.cloud9
- app.tmp.cloud9 = true
- # Workspace
- settings.workspace ?= app.set 'workspace'
- return next(new Error 'No workspace provided') unless settings.workspace
- settings.cmd = cmd()
- # Register commands
- app.cmd 'cloud9 start', 'Start Cloud9', (req, res, next) ->
- # Launch process
- start_stop.start settings, (err, pid) ->
- return next err if err
- unless pid
- res.cyan('Cloud9 already started').ln()
- return res.prompt()
- ip = settings.ip or '127.0.0.1'
- port = settings.port or 3000
- message = "Cloud9 started http://#{ip}:#{port}"
- res.cyan( message ).ln()
- res.prompt()
- app.cmd 'cloud9 stop', 'Stop Cloud9', (req, res, next) ->
- start_stop.stop settings, (err, success) ->
- if success
- then res.cyan('Cloud9 successfully stoped').ln()
- else res.magenta('Cloud9 was not started').ln()
- res.prompt()
- next()
+ cmd = () ->
+ args = []
+ args.push '-w'
+ args.push settings.workspace
+ # Arguments
+ if settings.config
+ args.push '-c'
+ args.push settings.config
+ if settings.group
+ args.push '-g'
+ args.push settings.group
+ if settings.user
+ args.push '-u'
+ args.push settings.user
+ if settings.action
+ args.push '-a'
+ args.push settings.action
+ if settings.ip
+ args.push '-l'
+ args.push settings.ip
+ if settings.port
+ args.push '-p'
+ args.push settings.port
+ "cloud9 #{args.join(' ')}"
+ (req, res, next) ->
+ app = req.shell
+ # Caching
+ return next() if app.tmp.cloud9
+ app.tmp.cloud9 = true
+ # Workspace
+ settings.workspace ?= app.set 'workspace'
+ return next(new Error 'No workspace provided') unless settings.workspace
+ settings.cmd = cmd()
+ # Register commands
+ app.cmd 'cloud9 start', 'Start Cloud9', (req, res, next) ->
+ # Launch process
+ start_stop.start settings, (err, pid) ->
+ return next err if err
+ unless pid
+ res.cyan('Cloud9 already started').ln()
+ return res.prompt()
+ ip = settings.ip or '127.0.0.1'
+ port = settings.port or 3000
+ message = "Cloud9 started http://#{ip}:#{port}"
+ res.cyan( message ).ln()
+ res.prompt()
+ app.cmd 'cloud9 stop', 'Stop Cloud9', (req, res, next) ->
+ start_stop.stop settings, (err, success) ->
+ if success
+ then res.cyan('Cloud9 successfully stoped').ln()
+ else res.magenta('Cloud9 was not started').ln()
+ res.prompt()
+ next()
View
128 lib/plugins/coffee.coffee
@@ -4,13 +4,13 @@ start_stop = require '../start_stop'
# Sanitize a list of files separated by spaces
enrichFiles = (files) ->
- return files.split(' ').map( (file) ->
- if file.substr(0, 1) isnt '/'
- file = '/' + file
- if file.substr(-1, 1) isnt '/' and fs.statSync(file).isDirectory()
- file += '/'
- file
- ).join ' '
+ return files.split(' ').map( (file) ->
+ if file.substr(0, 1) isnt '/'
+ file = '/' + file
+ if file.substr(-1, 1) isnt '/' and fs.statSync(file).isDirectory()
+ file += '/'
+ file
+ ).join ' '
###
@@ -37,66 +37,66 @@ Example:
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
- app.use(shell.coffee({
- shell: app
- }));
- app.use(shell.help({
- shell: app,
- introduction: true
- }));
+ app.use(shell.router({
+ shell: app
+ }));
+ app.use(shell.coffee({
+ shell: app
+ }));
+ app.use(shell.help({
+ shell: app,
+ introduction: true
+ }));
});
```
###
module.exports = (settings = {}) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Default settings
- settings.workspace ?= shell.set 'workspace'
- throw new Error 'No workspace provided' if not settings.workspace
- cmd = () ->
- args = []
- #
- if settings.join
- args.push '-j'
- args.push enrichFiles(settings.join)
- # Watch the modification times of the coffee-scripts,
- # recompiling as soon as a change occurs.
- args.push '-w'
- if settings.lint
- args.push '-l'
- if settings.require
- args.push '-r'
- args.push settings.require
- # Compile the JavaScript without the top-level function
- # safety wrapper. (Used for CoffeeScript as a Node.js module.)
- args.push '-b'
- if settings.output
- args.push '-o'
- args.push enrichFiles(settings.output)
- if not settings.compile
- settings.compile = settings.workspace
- if settings.compile
- args.push '-c'
- args.push enrichFiles(settings.compile)
- cmd = 'coffee ' + args.join(' ')
- settings.cmd = cmd()
- # Register commands
- shell.cmd 'coffee start', 'Start CoffeeScript', (req, res, next) ->
- start_stop.start settings, (err, pid) ->
- return next err if err
- return res.cyan('Already Started').ln() unless pid
- message = "CoffeeScript started"
- res.cyan( message ).ln()
- res.prompt()
- shell.cmd 'coffee stop', 'Stop CoffeeScript', (req, res, next) ->
- start_stop.stop settings, (err, success) ->
- if success
- then res.cyan('CoffeeScript successfully stoped').ln()
- else res.magenta('CoffeeScript was not started').ln()
- res.prompt()
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Default settings
+ settings.workspace ?= shell.set 'workspace'
+ throw new Error 'No workspace provided' if not settings.workspace
+ cmd = () ->
+ args = []
+ #
+ if settings.join
+ args.push '-j'
+ args.push enrichFiles(settings.join)
+ # Watch the modification times of the coffee-scripts,
+ # recompiling as soon as a change occurs.
+ args.push '-w'
+ if settings.lint
+ args.push '-l'
+ if settings.require
+ args.push '-r'
+ args.push settings.require
+ # Compile the JavaScript without the top-level function
+ # safety wrapper. (Used for CoffeeScript as a Node.js module.)
+ args.push '-b'
+ if settings.output
+ args.push '-o'
+ args.push enrichFiles(settings.output)
+ if not settings.compile
+ settings.compile = settings.workspace
+ if settings.compile
+ args.push '-c'
+ args.push enrichFiles(settings.compile)
+ cmd = 'coffee ' + args.join(' ')
+ settings.cmd = cmd()
+ # Register commands
+ shell.cmd 'coffee start', 'Start CoffeeScript', (req, res, next) ->
+ start_stop.start settings, (err, pid) ->
+ return next err if err
+ return res.cyan('Already Started').ln() unless pid
+ message = "CoffeeScript started"
+ res.cyan( message ).ln()
+ res.prompt()
+ shell.cmd 'coffee stop', 'Stop CoffeeScript', (req, res, next) ->
+ start_stop.stop settings, (err, success) ->
+ if success
+ then res.cyan('CoffeeScript successfully stoped').ln()
+ else res.magenta('CoffeeScript was not started').ln()
+ res.prompt()
View
30 lib/plugins/completer.coffee
@@ -6,21 +6,21 @@ Completer plugin
Provides tab completion. Options passed during creation are:
-- `shell` , (required) A reference to your shell application.
+- `shell` , (required) A reference to your shell application.
###
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Plug completer to interface
- return unless shell.isShell
- shell.interface().completer = (text, cb) ->
- suggestions = []
- routes = shell.routes
- for route in routes
- command = route.command
- if command.substr(0, text.length) is text
- suggestions.push command
- cb(false, [suggestions, text])
- null
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Plug completer to interface
+ return unless shell.isShell
+ shell.interface().completer = (text, cb) ->
+ suggestions = []
+ routes = shell.routes
+ for route in routes
+ command = route.command
+ if command.substr(0, text.length) is text
+ suggestions.push command
+ cb(false, [suggestions, text])
+ null
View
32 lib/plugins/error.coffee
@@ -1,18 +1,18 @@
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Define empty error handler to avoir shell to trow error of no event
- # handler are defined
- shell.on 'error', ->
- # Route
- (err, req, res, next) ->
- res.red(err.message).ln() if err.message
- res.red(err.stack).ln() if err.stack
- for k, v of err
- continue if k is 'message'
- continue if k is 'stack'
- continue if typeof v is 'function'
- res.magenta(k).white(': ').red(v).ln()
- res.prompt()
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Define empty error handler to avoir shell to trow error of no event
+ # handler are defined
+ shell.on 'error', ->
+ # Route
+ (err, req, res, next) ->
+ res.red(err.message).ln() if err.message
+ res.red(err.stack).ln() if err.stack
+ for k, v of err
+ continue if k is 'message'
+ continue if k is 'stack'
+ continue if typeof v is 'function'
+ res.magenta(k).white(': ').red(v).ln()
+ res.prompt()
View
62 lib/plugins/help.coffee
@@ -17,37 +17,37 @@ Options passed during creation are:
Usage
- app = shell()
- app.configure ->
- app.use shell.router shell: app
- app.use shell.help
- shell: app
- introduction: true
+ app = shell()
+ app.configure ->
+ app.use shell.router shell: app
+ app.use shell.help
+ shell: app
+ introduction: true
###
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Register function
- shell.help = (req, res, next) ->
- res.cyan 'Available commands:'
- res.ln()
- routes = shell.routes
- for route in routes
- text = pad route.command, 20
- res
- .cyan(text)
- .white(route.description)
- .ln() if route.description
- res.prompt()
- # Register commands
- shell.cmd 'help', 'Show this message', shell.help.bind shell
- shell.cmd '', shell.help.bind shell
- # Print introduction message
- if shell.isShell and settings.introduction
- text =
- if typeof settings.introduction is 'string'
- then settings.introduction
- else 'Type "help" or press enter for a list of commands'
- shell.styles.println text
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Register function
+ shell.help = (req, res, next) ->
+ res.cyan 'Available commands:'
+ res.ln()
+ routes = shell.routes
+ for route in routes
+ text = pad route.command, 20
+ res
+ .cyan(text)
+ .white(route.description)
+ .ln() if route.description
+ res.prompt()
+ # Register commands
+ shell.cmd 'help', 'Show this message', shell.help.bind shell
+ shell.cmd '', shell.help.bind shell
+ # Print introduction message
+ if shell.isShell and settings.introduction
+ text =
+ if typeof settings.introduction is 'string'
+ then settings.introduction
+ else 'Type "help" or press enter for a list of commands'
+ shell.styles.println text
View
62 lib/plugins/history.coffee
@@ -12,37 +12,37 @@ History plugin
Persistent command history over multiple sessions. Options passed during creation are:
-- `shell` , (required) A reference to your shell application.
-- `name` , Identify your project history file, default to the hash of the exectuted file
-- `dir` , Location of the history files, defaults to `"#{process.env['HOME']}/.node_shell"`
+- `shell` , (required) A reference to your shell application.
+- `name` , Identify your project history file, default to the hash of the exectuted file
+- `dir` , Location of the history files, defaults to `"#{process.env['HOME']}/.node_shell"`
###
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Only in shell mode
- return if not settings.shell.isShell
- # Persist readline history
- settings.dir ?= "#{process.env['HOME']}/.node_shell"
- settings.name ?= hash process.argv[1]
- file = "#{settings.dir}/#{settings.file}"
- # Create store directory
- fs.mkdirSync settings.dir, 0o0700 unless fs.existsSync settings.dir
- # Look for previous history
- if fs.existsSync file
- try
- json = fs.readFileSync(file, 'utf8') or '[]'
- settings.shell.interface().history = JSON.parse json
- catch e
- settings.shell.styles.red('Corrupted history file').ln()
- # Write new history
- stream = fs.createWriteStream file, {flag: 'w'}
- Interface.prototype._addHistory = ((parent) -> ->
- if @history.length
- buffer = new Buffer JSON.stringify( @history )
- fs.write stream.fd, buffer, 0, buffer.length, 0
- parent.apply @, arguments
- ) Interface.prototype._addHistory
- null
-
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Only in shell mode
+ return if not settings.shell.isShell
+ # Persist readline history
+ settings.dir ?= "#{process.env['HOME']}/.node_shell"
+ settings.name ?= hash process.argv[1]
+ file = "#{settings.dir}/#{settings.file}"
+ # Create store directory
+ fs.mkdirSync settings.dir, 0o0700 unless fs.existsSync settings.dir
+ # Look for previous history
+ if fs.existsSync file
+ try
+ json = fs.readFileSync(file, 'utf8') or '[]'
+ settings.shell.interface().history = JSON.parse json
+ catch e
+ settings.shell.styles.red('Corrupted history file').ln()
+ # Write new history
+ stream = fs.createWriteStream file, {flag: 'w'}
+ Interface.prototype._addHistory = ((parent) -> ->
+ if @history.length
+ buffer = new Buffer JSON.stringify( @history )
+ fs.write stream.fd, buffer, 0, buffer.length, 0
+ parent.apply @, arguments
+ ) Interface.prototype._addHistory
+ null
+
View
112 lib/plugins/http.coffee
@@ -32,64 +32,64 @@ Example:
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
- app.use(shell.http({
- shell: app
- }));
- app.use(shell.help({
- shell: app,
- introduction: true
- }));
+ app.use(shell.router({
+ shell: app
+ }));
+ app.use(shell.http({
+ shell: app
+ }));
+ app.use(shell.help({
+ shell: app,
+ introduction: true
+ }));
});
```
###
module.exports = () ->
- settings = {}
- cmd = () ->
- searchs = if settings.path then [settings.path] else ['app', 'server', 'lib/app', 'lib/server']
- for search in searchs
- search = path.resolve settings.workspace, search
- if existsSync "#{search}"
- if search.substr(-4) is '.coffee'
- then return "coffee #{search}"
- else return "node #{search}"
- if existsSync "#{search}.js"
- return "node #{search}.js"
- else if existsSync "#{search}.coffee"
- return "coffee #{search}.coffee"
- throw new Error 'Failed to discover a "server.js" or "app.js" file'
- http = null
- # Register commands
- route = (req, res, next) ->
- app = req.shell
- # Caching
- return next() if app.tmp.http
- app.tmp.http = true
- # Workspace settings
- settings.workspace ?= app.set 'workspace'
- throw new Error 'No workspace provided' if not settings.workspace
- # Messages
- settings.message_start ?= 'HTTP server successfully started'
- settings.message_stop ?= 'HTTP server successfully stopped'
- settings.cmd = cmd() unless settings.cmd
- app.cmd 'http start', 'Start HTTP server', (req, res, next) ->
- http = start_stop.start settings, (err, pid) ->
- return next err if err
- return res.cyan('HTTP server already started').ln() and res.prompt() unless pid
- res.cyan(settings.message_start).ln()
- res.prompt()
- app.cmd 'http stop', 'Stop HTTP server', (req, res, next) ->
- start_stop.stop settings, (err, success) ->
- if success
- then res.cyan(settings.message_stop).ln()
- else res.magenta('HTTP server was not started').ln()
- res.prompt()
- next()
- if arguments.length is 1
- settings = arguments[0]
- return route
- else
- route.apply null, arguments
+ settings = {}
+ cmd = () ->
+ searchs = if settings.path then [settings.path] else ['app', 'server', 'lib/app', 'lib/server']
+ for search in searchs
+ search = path.resolve settings.workspace, search
+ if existsSync "#{search}"
+ if search.substr(-4) is '.coffee'
+ then return "coffee #{search}"
+ else return "node #{search}"
+ if existsSync "#{search}.js"
+ return "node #{search}.js"
+ else if existsSync "#{search}.coffee"
+ return "coffee #{search}.coffee"
+ throw new Error 'Failed to discover a "server.js" or "app.js" file'
+ http = null
+ # Register commands
+ route = (req, res, next) ->
+ app = req.shell
+ # Caching
+ return next() if app.tmp.http
+ app.tmp.http = true
+ # Workspace settings
+ settings.workspace ?= app.set 'workspace'
+ throw new Error 'No workspace provided' if not settings.workspace
+ # Messages
+ settings.message_start ?= 'HTTP server successfully started'
+ settings.message_stop ?= 'HTTP server successfully stopped'
+ settings.cmd = cmd() unless settings.cmd
+ app.cmd 'http start', 'Start HTTP server', (req, res, next) ->
+ http = start_stop.start settings, (err, pid) ->
+ return next err if err
+ return res.cyan('HTTP server already started').ln() and res.prompt() unless pid
+ res.cyan(settings.message_start).ln()
+ res.prompt()
+ app.cmd 'http stop', 'Stop HTTP server', (req, res, next) ->
+ start_stop.stop settings, (err, success) ->
+ if success
+ then res.cyan(settings.message_stop).ln()
+ else res.magenta('HTTP server was not started').ln()
+ res.prompt()
+ next()
+ if arguments.length is 1
+ settings = arguments[0]
+ return route
+ else
+ route.apply null, arguments
View
90 lib/plugins/redis.coffee
@@ -14,55 +14,55 @@ Register two commands, `redis start` and `redis stop`. The following properties
- `stderr` , Writable stream or file path to redirect cloud9 stderr.
Example:
-
+
```javascript
var app = shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
- app.use(shell.redis({
- shell: app,
- config: __dirname+'/redis.conf')
- }));
- app.use(shell.help({
- shell: app,
- introduction: true
- }));
+ app.use(shell.router({
+ shell: app
+ }));
+ app.use(shell.redis({
+ shell: app,
+ config: __dirname+'/redis.conf')
+ }));
+ app.use(shell.help({
+ shell: app,
+ introduction: true
+ }));
});
```
###
module.exports = () ->
- settings = {}
- # Register commands
- redis = null
- route = (req, res, next) ->
- app = req.shell
- # Caching
- return next() if app.tmp.redis
- app.tmp.redis = true
- # Default settings
- settings.workspace ?= app.set 'workspace'
- settings.config ?= ''
- settings.cmd = "redis-server #{settings.config}"
- app.cmd 'redis start', 'Start Redis', (req, res, next) ->
- # Launch process
- redis = start_stop.start settings, (err, pid) ->
- return next err if err
- unless pid
- res.cyan('Redis already started').ln()
- return res.prompt()
- res.cyan('Redis started').ln()
- res.prompt()
- app.cmd 'redis stop', 'Stop Redis', (req, res, next) ->
- start_stop.stop settings, (err, success) ->
- if success
- then res.cyan('Redis successfully stoped').ln()
- else res.magenta('Redis was not started').ln()
- res.prompt()
- next()
- if arguments.length is 1
- settings = arguments[0]
- return route
- else
- route.apply null, arguments
+ settings = {}
+ # Register commands
+ redis = null
+ route = (req, res, next) ->
+ app = req.shell
+ # Caching
+ return next() if app.tmp.redis
+ app.tmp.redis = true
+ # Default settings
+ settings.workspace ?= app.set 'workspace'
+ settings.config ?= ''
+ settings.cmd = "redis-server #{settings.config}"
+ app.cmd 'redis start', 'Start Redis', (req, res, next) ->
+ # Launch process
+ redis = start_stop.start settings, (err, pid) ->
+ return next err if err
+ unless pid
+ res.cyan('Redis already started').ln()
+ return res.prompt()
+ res.cyan('Redis started').ln()
+ res.prompt()
+ app.cmd 'redis stop', 'Stop Redis', (req, res, next) ->
+ start_stop.stop settings, (err, success) ->
+ if success
+ then res.cyan('Redis successfully stoped').ln()
+ else res.magenta('Redis was not started').ln()
+ res.prompt()
+ next()
+ if arguments.length is 1
+ settings = arguments[0]
+ return route
+ else
+ route.apply null, arguments
View
323 lib/plugins/router.coffee
@@ -2,174 +2,173 @@
utils = require '../utils'
querystring =
- unescape: (str) ->
- decodeURIComponent str
- parse: (qs, sep, eq) ->
- sep = sep or '&'
- eq = eq or '='
- obj = {}
- return obj if typeof qs isnt 'string'
- vkps = qs.split sep
- for kvp in vkps
- x = kvp.split eq
- k = querystring.unescape x[0], true
- v = querystring.unescape x.slice(1).join(eq), true
- if not k in obj
- obj[k] = v
- else if not Array.isArray obj[k]
- obj[k] = [obj[k], v]
- else
- obj[k].push v
- obj
+ unescape: (str) ->
+ decodeURIComponent str
+ parse: (qs, sep, eq) ->
+ sep = sep or '&'
+ eq = eq or '='
+ obj = {}
+ return obj if typeof qs isnt 'string'
+ vkps = qs.split sep
+ for kvp in vkps
+ x = kvp.split eq
+ k = querystring.unescape x[0], true
+ v = querystring.unescape x.slice(1).join(eq), true
+ if not k in obj
+ obj[k] = v
+ else if not Array.isArray obj[k]
+ obj[k] = [obj[k], v]
+ else
+ obj[k].push v
+ obj
# produce regular expression from string
normalize = (command, keys, sensitive) ->
- command = command
- .concat('/?')
- .replace(/\/\(/g, '(?:/')
- # regexp factors:
- # 0. match a literal ':'
- # 1. 'key': match 1 or more word characters followed by :
- # 2. 'format': match anything inside (), should be a regexp factor
- # ie ([0-9]+)
- # 3. 'optional': match an optional literal '?'
- .replace(/:(\w+)(\(.*\))?(\?)?/g, (_, key, format, optional) ->
- keys.push key
- format = format or '([^ ]+)' # provide default format
- optional = optional or ''
- return format + optional
- )
- .replace(/([\/.])/g, '\\$1')
- .replace(/\*/g, '(.+)')
- new RegExp '^' + command + '$', ( 'i' if sensitive? )
+ command = command
+ .concat('/?')
+ .replace(/\/\(/g, '(?:/')
+ # regexp factors:
+ # 0. match a literal ':'
+ # 1. 'key': match 1 or more word characters followed by :
+ # 2. 'format': match anything inside (), should be a regexp factor ie ([0-9]+)
+ # 3. 'optional': match an optional literal '?'
+ .replace(/:(\w+)(\(.*\))?(\?)?/g, (_, key, format, optional) ->
+ keys.push key
+ format = format or '([^ ]+)' # provide default format
+ optional = optional or ''
+ return format + optional
+ )
+ .replace(/([\/.])/g, '\\$1')
+ .replace(/\*/g, '(.+)')
+ new RegExp '^' + command + '$', ( 'i' if sensitive? )
match = (req, routes, i) ->
- #from ?= 0
- #to = routes.length - 1
- #for (len = routes.length; i < len; ++i) {
- #for i in [from .. to]
- i ?= 0
- while i < routes.length
- route = routes[i]
- #fn = route.callback
- regexp = route.regexp
- keys = route.keys
- captures = regexp.exec req.command
- if captures
- route.params = {}
- index = 0
- #for (j = 1, len = captures.length; j < len; ++j) {
- #for j in [1 .. captures.length]
- j = 1
- while j < captures.length
- key = keys[j-1]
- val =
- if typeof captures[j] is 'string'
- then querystring.unescape captures[j]
- else captures[j]
- if key
- route.params[key] = val
- else
- route.params[''+index] = val
- index++
- j++
- req._route_index = i
- return route
- i++
- null
+ #from ?= 0
+ #to = routes.length - 1
+ #for (len = routes.length; i < len; ++i) {
+ #for i in [from .. to]
+ i ?= 0
+ while i < routes.length
+ route = routes[i]
+ #fn = route.callback
+ regexp = route.regexp
+ keys = route.keys
+ captures = regexp.exec req.command
+ if captures
+ route.params = {}
+ index = 0
+ #for (j = 1, len = captures.length; j < len; ++j) {
+ #for j in [1 .. captures.length]
+ j = 1
+ while j < captures.length
+ key = keys[j-1]
+ val =
+ if typeof captures[j] is 'string'
+ then querystring.unescape captures[j]
+ else captures[j]
+ if key
+ route.params[key] = val
+ else
+ route.params[''+index] = val
+ index++
+ j++
+ req._route_index = i
+ return route
+ i++
+ null
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- settings.sensitive ?= true
- # Expose routes
- routes = shell.routes = []
- params = {}
- shell.param = (name, fn) ->
- if Array.isArray name
- name.forEach (name) ->
- this.param name, fn
- , this
- else
- name = name.substr(1) if ':' is name[0]
- params[name] = fn
- this
- shell.cmd = (command, description, middleware1, middleware2, fn) ->
- args = Array.prototype.slice.call arguments
- route = {}
- route.command = args.shift()
- route.description = args.shift() if typeof args[0] is 'string'
- route.middlewares = utils.flatten args
- keys = []
- route.regexp =
- if route.command instanceof RegExp
- then route.command
- else normalize route.command, keys, settings.sensitive
- route.keys = keys
- routes.push route
- this
- # Register 'quit' command
- shell.cmd 'quit', 'Exit this shell', shell.quit.bind shell
- # middleware
- (req, res, next) ->
- route = null
- self = this
- i = 0
- pass = (i) ->
- route = match req, routes, i
- return next() if not route
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ settings.sensitive ?= true
+ # Expose routes
+ routes = shell.routes = []
+ params = {}
+ shell.param = (name, fn) ->
+ if Array.isArray name
+ name.forEach (name) ->
+ this.param name, fn
+ , this
+ else
+ name = name.substr(1) if ':' is name[0]
+ params[name] = fn
+ this
+ shell.cmd = (command, description, middleware1, middleware2, fn) ->
+ args = Array.prototype.slice.call arguments
+ route = {}
+ route.command = args.shift()
+ route.description = args.shift() if typeof args[0] is 'string'
+ route.middlewares = utils.flatten args
+ keys = []
+ route.regexp =
+ if route.command instanceof RegExp
+ then route.command
+ else normalize route.command, keys, settings.sensitive
+ route.keys = keys
+ routes.push route
+ this
+ # Register 'quit' command
+ shell.cmd 'quit', 'Exit this shell', shell.quit.bind shell
+ # middleware
+ (req, res, next) ->
+ route = null
+ self = this
+ i = 0
+ pass = (i) ->
+ route = match req, routes, i
+ return next() if not route
+ i = 0
+ keys = route.keys
+ req.params = route.params
+ # Param preconditions
+ # From expresso guide: There are times when we may want to "skip" passed
+ # remaining route middleware, but continue matching subsequent routes. To
+ # do this we invoke `next()` with the string "route" `next('route')`. If no
+ # remaining routes match the request url then Express will respond with 404 Not Found.
+ param = (err) ->
+ try
+ key = keys[ i++ ]
+ val = req.params[ key ]
+ fn = params[ key ]
+ if 'route' is err
+ pass req._route_index + 1
+ # Error
+ else if err
+ next err
+ # Param has callback
+ else if fn
+ # Return style
+ if 1 is fn.length
+ req.params[key] = fn val
+ param()
+ # Middleware style
+ else
+ fn req, res, param, val
+ # Finished processing params
+ else if not key
+ # route middleware
i = 0
- keys = route.keys
- req.params = route.params
- # Param preconditions
- # From expresso guide: There are times when we may want to "skip" passed
- # remaining route middleware, but continue matching subsequent routes. To
- # do this we invoke `next()` with the string "route" `next('route')`. If no
- # remaining routes match the request url then Express will respond with 404 Not Found.
- param = (err) ->
- try
- key = keys[ i++ ]
- val = req.params[ key ]
- fn = params[ key ]
- if 'route' is err
- pass req._route_index + 1
- # Error
- else if err
- next err
- # Param has callback
- else if fn
- # Return style
- if 1 is fn.length
- req.params[key] = fn val
- param()
- # Middleware style
- else
- fn req, res, param, val
- # Finished processing params
- else if not key
- # route middleware
- i = 0
- nextMiddleware = (err) ->
- fn = route.middlewares[ i++ ]
- if 'route' is err
- pass req._route_index + 1
- else if err
- next err
- else if fn
- fn req, res, nextMiddleware
- else
- pass req._route_index + 1
- #route.callback.call self, req, res, (err) ->
- #if err
- #next err
- #else
- #pass req._route_index + 1
- nextMiddleware()
- # More params
- else
- param()
- catch err
- next err
+ nextMiddleware = (err) ->
+ fn = route.middlewares[ i++ ]
+ if 'route' is err
+ pass req._route_index + 1
+ else if err
+ next err
+ else if fn
+ fn req, res, nextMiddleware
+ else
+ pass req._route_index + 1
+ #route.callback.call self, req, res, (err) ->
+ #if err
+ #next err
+ #else
+ #pass req._route_index + 1
+ nextMiddleware()
+ # More params
+ else
param()
- pass()
+ catch err
+ next err
+ param()
+ pass()
View
92 lib/plugins/stylus.coffee
@@ -4,13 +4,13 @@ start_stop = require '../start_stop'
# Sanitize a list of files separated by spaces
enrichFiles = (files) ->
- return files.split(' ').map( (file) ->
- path.normalize file
- # Stylus doesn't like trailing `/` in the use option
- if file.substr(-1, 1) is '/'
- file = file.substr 0, file.length - 1
- file
- ).join ' '
+ return files.split(' ').map( (file) ->
+ path.normalize file
+ # Stylus doesn't like trailing `/` in the use option
+ if file.substr(-1, 1) is '/'
+ file = file.substr 0, file.length - 1
+ file
+ ).join ' '
###
@@ -19,47 +19,47 @@ Stylus plugin
Start/stop a daemon to watch and convert stylus files to css.
Options include:
-* `output` Output to <dir> when passing files.
+* `output` Output to <dir> when passing files.
* `input` Add <path> to lookup paths
###
module.exports = (settings = {}) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Default settings
- settings.workspace ?= shell.set 'workspace'
- throw new Error 'No workspace provided' if not settings.workspace
- cmd = () ->
- args = []
- # Watch the modification times of the coffee-scripts,
- # recompiling as soon as a change occurs.
- args.push '-w'
- if settings.use
- args.push '-u'
- args.push enrichFiles(settings.use)
- if settings.output
- args.push '-o'
- args.push enrichFiles(settings.output)
- if not settings.input
- settings.input = settings.workspace
- if settings.input
- args.push enrichFiles(settings.input)
- cmd = 'stylus ' + args.join(' ')
- settings.cmd = cmd()
- #console.log settings.cmd
- # Register commands
- shell.cmd 'stylus start', 'Start CoffeeScript', (req, res, next) ->
- start_stop.start settings, (err, pid) ->
- return next err if err
- return res.cyan('Already Started').ln() unless pid
- message = "Stylus started"
- res.cyan( message ).ln()
- res.prompt()
- shell.cmd 'stylus stop', 'Stop Stylus', (req, res, next) ->
- start_stop.stop settings, (err, success) ->
- if success
- then res.cyan('Stylus successfully stoped').ln()
- else res.magenta('Stylus was not started').ln()
- res.prompt()
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Default settings
+ settings.workspace ?= shell.set 'workspace'
+ throw new Error 'No workspace provided' if not settings.workspace
+ cmd = () ->
+ args = []
+ # Watch the modification times of the coffee-scripts,
+ # recompiling as soon as a change occurs.
+ args.push '-w'
+ if settings.use
+ args.push '-u'
+ args.push enrichFiles(settings.use)
+ if settings.output
+ args.push '-o'
+ args.push enrichFiles(settings.output)
+ if not settings.input
+ settings.input = settings.workspace
+ if settings.input
+ args.push enrichFiles(settings.input)
+ cmd = 'stylus ' + args.join(' ')
+ settings.cmd = cmd()
+ #console.log settings.cmd
+ # Register commands
+ shell.cmd 'stylus start', 'Start CoffeeScript', (req, res, next) ->
+ start_stop.start settings, (err, pid) ->
+ return next err if err
+ return res.cyan('Already Started').ln() unless pid
+ message = "Stylus started"
+ res.cyan( message ).ln()
+ res.prompt()
+ shell.cmd 'stylus stop', 'Stop Stylus', (req, res, next) ->
+ start_stop.stop settings, (err, success) ->
+ if success
+ then res.cyan('Stylus successfully stoped').ln()
+ else res.magenta('Stylus was not started').ln()
+ res.prompt()
View
64 lib/plugins/test.coffee
@@ -5,36 +5,36 @@ existsSync = fs.existsSync or path.existsSync
exec = require('child_process').exec
module.exports = (settings) ->
- # Validation
- throw new Error 'No shell provided' if not settings.shell
- shell = settings.shell
- # Default settings
- settings.workspace ?= shell.set 'workspace'
- throw new Error 'No workspace provided' if not settings.workspace
- settings.glob ?= 'test/*.js'
- # Register commands
- shell.cmd 'test', 'Run all test', (req, res, next) ->
- run = (cmd) ->
- args = []
- args.push cmd
- if settings.coverage
- args.push '--cov'
- if settings.serial
- args.push '--serial'
- if settings.glob
- args.push settings.glob
- expresso = exec 'cd ' + settings.workspace + ' && ' + args.join(' ')
- expresso.stdout.on 'data', (data) ->
- res.cyan data
- expresso.stderr.on 'data', (data) ->
- res.magenta data
- expresso.on 'exit', (code) ->
- res.prompt()
- paths = [].concat module.paths, require.paths
- for p in paths
- if existsSync p + '/expresso/bin/expresso'
- return run p
- res.magenta('Expresso not found').ln()
+ # Validation
+ throw new Error 'No shell provided' if not settings.shell
+ shell = settings.shell
+ # Default settings
+ settings.workspace ?= shell.set 'workspace'
+ throw new Error 'No workspace provided' if not settings.workspace
+ settings.glob ?= 'test/*.js'
+ # Register commands
+ shell.cmd 'test', 'Run all test', (req, res, next) ->
+ run = (cmd) ->
+ args = []
+ args.push cmd
+ if settings.coverage
+ args.push '--cov'
+ if settings.serial
+ args.push '--serial'
+ if settings.glob
+ args.push settings.glob
+ expresso = exec 'cd ' + settings.workspace + ' && ' + args.join(' ')
+ expresso.stdout.on 'data', (data) ->
+ res.cyan data
+ expresso.stderr.on 'data', (data) ->
+ res.magenta data
+ expresso.on 'exit', (code) ->
res.prompt()
- shell.cmd 'test :pattern', 'Run specific tests', (req, res, next) ->
- #todo
+ paths = [].concat module.paths, require.paths
+ for p in paths
+ if existsSync p + '/expresso/bin/expresso'
+ return run p
+ res.magenta('Expresso not found').ln()
+ res.prompt()
+ shell.cmd 'test :pattern', 'Run specific tests', (req, res, next) ->
+ #todo
View
20 lib/routes/confirm.coffee
@@ -9,20 +9,20 @@ The `confirm` route ask the user if he want to continue the process. If the answ
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
+ app.use(shell.router({
+ shell: app
+ }));
});
app.cmd('install', [
- shell.routes.confirm('Do you confirm?'),
- my_app.routes.download,
- my_app.routes.configure
+ shell.routes.confirm('Do you confirm?'),
+ my_app.routes.download,
+ my_app.routes.configure
]);
```
###
module.exports = (message) ->
- (req, res, next) ->
- req.confirm message, true, (confirmed) ->
- return res.prompt() unless confirmed
- next()
+ (req, res, next) ->
+ req.confirm message, true, (confirmed) ->
+ return res.prompt() unless confirmed
+ next()
View
28 lib/routes/prompt.coffee
@@ -9,24 +9,24 @@ The `prompt` route is a convenient function to stop command once a few routes ar
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
+ app.use(shell.router({
+ shell: app
+ }));
});
app.cmd('install', [
- my_app.routes.download,
- my_app.routes.configure,
- shell.routes.prompt('Installation is finished')
+ my_app.routes.download,
+ my_app.routes.configure,
+ shell.routes.prompt('Installation is finished')
]);
```
###
module.exports = (req, res, next) ->
- if arguments.length is 1
- message = arguments[0]
- return (req, res, next) ->
- res.white message
- res.ln()
- res.prompt()
- else
- res.prompt()
+ if arguments.length is 1
+ message = arguments[0]
+ return (req, res, next) ->
+ res.white message
+ res.ln()
+ res.prompt()
+ else
+ res.prompt()
View
10 lib/routes/shellOnly.coffee
@@ -8,8 +8,8 @@ Ensure the current process is running in shell mode.
###
module.exports = (req, res, next) ->
- if not req.shell.isShell
- res.red 'Command may only be executed inside a running shell'
- res.prompt()
- return
- next()
+ if not req.shell.isShell
+ res.red 'Command may only be executed inside a running shell'
+ res.prompt()
+ return
+ next()
View
16 lib/routes/timeout.coffee
@@ -9,18 +9,18 @@ The `timeout` route will wait for the provided period (in millisenconds) before
```javascript
var app = new shell();
app.configure(function() {
- app.use(shell.router({
- shell: app
- }));
+ app.use(shell.router({
+ shell: app
+ }));
});
app.cmd('restart', [
- my_app.routes.stop,
- shell.routes.timeout(1000),
- my_app.routes.start
+ my_app.routes.stop,
+ shell.routes.timeout(1000),
+ my_app.routes.start
]);
```
###
module.exports = (timeout) ->
- (req, res, next) ->
- setTimeout timeout, next
+ (req, res, next) ->
+ setTimeout timeout, next
View
484 lib/start_stop.coffee
@@ -19,268 +19,268 @@ providing the `attach` option.
###
module.exports = start_stop =
- ###
+ ###
- `start(options, callback)`
- --------------------------
- Start a prcess as a daemon (default) or as a child of the current process. Options includes
- all the options of the "child_process.exec" function plus a few specific ones.
+ `start(options, callback)`
+ --------------------------
+ Start a prcess as a daemon (default) or as a child of the current process. Options includes
+ all the options of the "child_process.exec" function plus a few specific ones.
- `options` , Object with the following properties:
- * `cmd` , Command to run
- * `cwd` , Current working directory of the child process
- * `detached` , Detached the child process from the current process
- * `pidfile` , Path to the file storing the child pid
- * `stdout` , Path to the file where standard output is redirected
- * `stderr` , Path to the file where standard error is redirected
- * `strict` , Send an error when a pid file exists and reference
- an unrunning pid.
- * `watch` , Watch for file changes
- * `watchIgnore` , List of ignore files
-
- `callback` , Received arguments are:
- * `err` , Error if any
- * `pid` , Process id of the new child
+ `options` , Object with the following properties:
+ * `cmd` , Command to run
+ * `cwd` , Current working directory of the child process
+ * `detached` , Detached the child process from the current process
+ * `pidfile` , Path to the file storing the child pid