Skip to content

Commit

Permalink
style: added jshint and jscs linters
Browse files Browse the repository at this point in the history
  • Loading branch information
kilianc committed Jun 30, 2015
1 parent cc5be40 commit 40e14e7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 84 deletions.
28 changes: 28 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"preset": "airbnb",
"esnext": true,
"verbose": true,
"disallowCapitalizedComments": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleSpaces": true,
"disallowSemicolons": true,
"disallowSpacesInAnonymousFunctionExpression": null,
"disallowSpacesInFunctionExpression": null,
"disallowYodaConditions": null,
"requireCamelCaseOrUpperCaseIdentifiers": null,
"requirePaddingNewLinesAfterUseStrict": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"safeContextKeyword": ["self", "doc", "ctx"],
"validateIndentation": 2,
"plugins": [
"jscs-jsdoc"
],
"jsDoc": {
"checkAnnotations": "closurecompiler",
"checkTypes": "strictNativeCase",
"enforceExistence": "exceptExports"
}
}
11 changes: 11 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"asi": true,
"esnext": true,
"expr": true,
"mocha": true,
"node": true,
"noyield": true,
"strict": true,
"unused": true,
"validthis": true
}
31 changes: 12 additions & 19 deletions app/app.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Main JS controller for webapp
/*!
* main js controller for webapp
*/

angular
.module('app', [
'ngAnimate',
Expand All @@ -11,9 +10,7 @@ angular
])
.controller('MainController', function MainController($scope, $injector) {
var $sce = $injector.get('$sce')
var $moment = $injector.get('moment')
var $localForage = $injector.get('$localForage')
var $window = $injector.get('$window')
var $streamLines = $('.stream-lines')
var BUFFER_SIZE = 100
var ctrl = this
Expand All @@ -22,10 +19,9 @@ angular
ctrl.version = '<%= version %>'
ctrl.lines = []

/**
* Socket stuff
/*!
* socket stuff
*/

ctrl.socket = io(document.location.origin, { path: document.location.pathname + 'socket.io' })

ctrl.socket.on('streams', function (streams) {
Expand Down Expand Up @@ -102,10 +98,9 @@ angular

$streamLines.on('mousewheel', ctrl.pause)

/**
* Settings and preferences
/*!
* settings and preferences
*/

ctrl.toggleFavorite = function toggleFavorite(stream) {
if (ctrl.favorites[stream]) {
delete ctrl.favorites[stream]
Expand All @@ -126,7 +121,7 @@ angular
$localForage.setItem('fontFamily', fontFamily)
}

ctrl.incFontSize = function incFontSize(fontSize) {
ctrl.incFontSize = function incFontSize() {
ctrl.fontSize = Math.min(7, ctrl.fontSize + 1)
$localForage.setItem('fontSize', ctrl.fontSize)
}
Expand All @@ -146,10 +141,9 @@ angular
$localForage.setItem('streamDirection', streamDirection)
}

/**
* Load storage in memory and boot
/*!
* load storage in memory and boot
*/

$localForage.getItem('theme').then(function (theme) {
ctrl.theme = theme || 'dark'
})
Expand All @@ -176,9 +170,8 @@ angular
ctrl.streamDirection = undefined === streamDirection ? true : streamDirection
})

/**
* Tell UI we're ready to roll
/*!
* tell UI we're ready to roll
*/

ctrl.loaded = true
})
})
29 changes: 14 additions & 15 deletions cli/lib/webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
* (c) 2014-2015
*/

var debug = require('debug')('rtail:webapp')
, get = require('request').defaults({ encoding: null })
'use strict'

const debug = require('debug')('rtail:webapp')
const get = require('request').defaults({ encoding: null })

// serve frontend from s3
module.exports = function webapp(opts) {
var cache = Object.create(null)
var cacheTTL = opts.cacheTTL
var s3 = opts.s3
let cache = Object.create(null)
let cacheTTL = opts.cacheTTL
let s3 = opts.s3

/**
* Middleware
/*!
* middleware
*/

return function (req, res) {
if (cache[req.path]) {
return serveCache(req, res)
Expand All @@ -34,21 +35,19 @@ module.exports = function webapp(opts) {
})
}

/**
* Wipes out cache every cacheTTL ms
/*!
* wipes out cache every cachettl ms
*/

setInterval(function () {
cache = Object.create(null)
}, cacheTTL)

/**
* Serves req from cache
/*!
* serves req from cache
*/

function serveCache(req, res) {
debug('serving from cache %s', req.path)
res.writeHead(200, cache[req.path].headers)
res.end(cache[req.path].body)
}
}
}
37 changes: 15 additions & 22 deletions cli/rtail-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'use strict'

const dgram = require('dgram')
const path = require('path')
const app = require('express')()
const serve = require('express').static
const http = require('http').Server(app)
Expand All @@ -21,20 +20,18 @@ const webapp = require('./lib/webapp')
const updateNotifier = require('update-notifier')
const pkg = require('../package')

/**
* Inform the user of updates
/*!
* inform the user of updates
*/

updateNotifier({
packageName: pkg.name,
packageVersion: pkg.version
}).notify()

/**
* Parsing argv
/*!
* parsing argv
*/

var argv = yargs
let argv = yargs
.usage('Usage: rtail-server [--udp-host [string] --udp-port [num] --web-host [string] --web-port [num] --web-version [stable,unstable,<version>]]')
.example('rtail-server --web-port 8080', 'Use custom http port')
.example('rtail-server --udp-port 8080', 'Use custom udp port')
Expand Down Expand Up @@ -71,12 +68,11 @@ var argv = yargs
.strict()
.argv

/**
/*!
* UDP sockets setup
*/

var streams = {}
var socket = dgram.createSocket('udp4')
let streams = {}
let socket = dgram.createSocket('udp4')

socket.on('message', function (data, remote) {
// try to decode JSON
Expand All @@ -88,7 +84,7 @@ socket.on('message', function (data, remote) {
io.sockets.emit('streams', Object.keys(streams))
}

var message = {
let message = {
timestamp: Date.now(),
streamid: data.id,
host: remote.address,
Expand All @@ -105,10 +101,9 @@ socket.on('message', function (data, remote) {
io.sockets.to(data.id).emit('line', message)
})

/**
/*!
* socket.io
*/

io.on('connection', function (socket) {
socket.emit('streams', Object.keys(streams))
socket.on('select stream', function (stream) {
Expand All @@ -119,10 +114,9 @@ io.on('connection', function (socket) {
})
})

/**
* Serve static webapp from s3
/*!
* serve static webapp from S3
*/

if (!argv.webVersion) {
app.use(serve(__dirname + '/../dist'))
} else if ('development' === argv.webVersion) {
Expand All @@ -138,13 +132,12 @@ if (!argv.webVersion) {
debug('serving webapp from: http://rtail.s3-website-us-east-1.amazonaws.com/%s', argv.webVersion)
}

/**
* Listen!
/*!
* listen!
*/

io.attach(http, { serveClient: false })
socket.bind(argv.udpPort, argv.udpHost)
http.listen(argv.webPort, argv.webHost)

debug('UDP server listening: %s:%s', argv.udpHost, argv.udpPort)
debug('HTTP server listening: http://%s:%s', argv.webHost, argv.webPort)
debug('HTTP server listening: http://%s:%s', argv.webHost, argv.webPort)
47 changes: 19 additions & 28 deletions cli/rtail.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

const dgram = require('dgram')
const split = require('split')
const crypto = require('crypto')
const Writable = require('stream').Writable
const tty = require('tty')
const JSON5 = require('json5')
const yargs = require('yargs')
const map = require('through2-map')
Expand All @@ -22,10 +19,9 @@ const moniker = require('moniker').choose
const updateNotifier = require('update-notifier')
const pkg = require('../package')

/**
* Inform the user of updates
/*!
* inform the user of updates
*/

updateNotifier({
packageName: pkg.name,
packageVersion: pkg.version
Expand All @@ -34,11 +30,10 @@ updateNotifier({
// fix yargs help
moniker.toString = function () { return 'moniker()' }

/**
* Parsing argv
/*!
* parsing argv
*/

var argv = yargs
let argv = yargs
.usage('Usage: cmd | rtail --host [string] --port [num] [--mute] [--id [string]]')
.example('server | rtail --host 127.0.0.1 > server.log', 'Broadcast to localhost + file')
.example('server | rtail --port 43567', 'Custom port')
Expand Down Expand Up @@ -78,10 +73,9 @@ var argv = yargs
.strict()
.argv
/**
* Setup pipes
/*!
* setup pipes
*/
if (!argv.mute) {
if (!process.stdout.isTTY || argv['not-tty']) {
process.stdin
Expand All @@ -94,23 +88,21 @@ if (!argv.mute) {
}
}
/**
* Initialize socket
/*!
* initialize socket
*/
var isClosed = false
var isSending = 0
var socket = dgram.createSocket('udp4')
var baseMessage = { id: argv.id }
let isClosed = false
let isSending = 0
let socket = dgram.createSocket('udp4')
let baseMessage = { id: argv.id }
socket.bind(function () {
socket.setBroadcast(true)
})
/**
* Broadcast lines to browser
/*!
* broadcast lines to browser
*/
process.stdin
.pipe(split())
.on('data', function (line) {
Expand All @@ -125,19 +117,18 @@ process.stdin
baseMessage.content = line
// prepare binary message
var buffer = new Buffer(JSON.stringify(baseMessage))
let buffer = new Buffer(JSON.stringify(baseMessage))
socket.send(buffer, 0, buffer.length, argv.port, argv.host, function () {
isSending --
if (isClosed && !isSending) socket.close()
})
})
/**
* Drain pipe and exit
/*!
* drain pipe and exit
*/
process.stdin.on('end', function () {
isClosed = true
if (!isSending) socket.close()
})
})

0 comments on commit 40e14e7

Please sign in to comment.