Skip to content

Commit

Permalink
convert to standard style, add travis
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Mar 23, 2015
1 parent 4705a81 commit a9564d3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- '0.12'
30 changes: 15 additions & 15 deletions configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ var events = {

openDir: function () {
ipc.send('open-dir')
},
},

openLogsDir: function (e) {
ipc.send('open-logs-dir', e.context.name)
}
Expand All @@ -38,17 +38,17 @@ var events = {
ipc.on('got-all', function gotAll (data) {
data = data.map(function map (d) {
if (d.uptime) {
d.classes = "btn-positive"
d.message = "Running"
d.classes = 'btn-positive'
d.message = 'Running'
return d
}
if (d.state === 'dead') {
d.classes = "btn-negative"
d.message = "Dead"
d.classes = 'btn-negative'
d.message = 'Dead'
return d
}
d.message = "Not Running"

d.message = 'Not Running'
return d
})
var obj = {items: data}
Expand All @@ -61,23 +61,23 @@ ipc.on('got-one', function gotOne (data) {
})

var routes = {
configure: function(ctx, next) {
configure: function configure (ctx, next) {
ctx.template = templates.configure
state.configure = render(ctx, {loading: true})
ipc.send('get-all')
ipc.once('status', function() {
ipc.once('status', function gotOnce () {
next()
})
},
detail: function(ctx, next) {
detail: function detail (ctx, next) {
ctx.template = templates.detail
state.detail = render(ctx, {loading: true})
ipc.send('get-one', {name: ctx.params.name})
ipc.once('status', function() {
ipc.once('status', function gotOnce () {
next()
})
},
about: function(ctx, next) {
about: function about (ctx, next) {
ctx.template = templates.about
state.about = render(ctx, {})
}
Expand All @@ -92,9 +92,9 @@ page('/about', routes.about)
page.start()
page('/')

function render(ctx) {
function render (ctx) {
var ract = new Ractive({
el: "#container",
el: '#container',
template: ctx.template,
data: ctx.data
})
Expand Down
94 changes: 46 additions & 48 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
var path = require('path')
var child = require('child_process')
var fs = require('fs')

var app = require('app')
var Menu = require('menu')
var Tray = require('tray')
var BrowserWindow = require('browser-window')
var ipc = require('ipc')
var shell = require('shell')

var ms = require('ms')
var Mongroup = require('mongroup')
var fs = require('fs')
var mkdir = require('mkdirp').sync
var debug = require('debug')('monu')

var icon, menu, configure, about
var icon, configure

// launching from .app doesnt use bash and never loads .e.g. .bash_profile
process.env.PATH = '/usr/local/bin:' + process.env.PATH

app.on('ready', function() {
app.on('ready', function ready () {
app.dock.hide()
var atomScreen = require('screen')
var size = atomScreen.getPrimaryDisplay()

var canQuit = false
app.on('will-quit', function(e) {
app.on('will-quit', function tryQuit (e) {
if (canQuit) return true
configure = undefined
e.preventDefault()
})

var conf = loadConfig()

// start all once
start([], function started (err) {
if (err) return console.log("error starting processes: " + err.message)
console.log("started all processes")
if (err) return console.log('error starting processes: ' + err.message)
console.log('started all processes')
})

var iconPath = path.join(__dirname, 'images', 'Icon.png')
icon = new Tray(iconPath)
icon.on('clicked', function(e) {

icon.on('clicked', function clicked (e) {
if (configure && configure.isVisible()) return hideConfigure()
showConfigure()
})
Expand All @@ -51,37 +49,37 @@ app.on('ready', function() {
canQuit = true
app.terminate()
})

ipc.on('open-dir', function openDir (ev) {
shell.showItemInFolder(path.join(conf.exec.cwd, 'config.json'))
})

ipc.on('open-logs-dir', function openLogsDir (ev, name) {
shell.showItemInFolder(path.join(conf.logs, name + '.log'))
})

ipc.on('get-all', function getAll (ev, data) {
getStatus()
})

ipc.on('get-one', function getOne (ev, data) {
getStatus(null, data.name)
})

ipc.on('task', function task (ev, data) {
if (data.task === "startAll") start([], getStatus)
if (data.task === "stopAll") stop([], getStatus)
if (data.task === "restartAll") restart([], getStatus)
if (data.task === "start") start([data.name], updateSingle)
if (data.task === "stop") stop([data.name], updateSingle)
if (data.task === "restart") restart([data.name], updateSingle)
function updateSingle() {
if (data.task === 'startAll') start([], getStatus)
if (data.task === 'stopAll') stop([], getStatus)
if (data.task === 'restartAll') restart([], getStatus)
if (data.task === 'start') start([data.name], updateSingle)
if (data.task === 'stop') stop([data.name], updateSingle)
if (data.task === 'restart') restart([data.name], updateSingle)

function updateSingle () {
getStatus(null, data.name)
}
})
function loadConfig() {
})

function loadConfig () {
var dir = path.join(app.getPath('userData'), 'data')
var configFile = dir + '/config.json'
var conf, data
Expand All @@ -107,15 +105,15 @@ app.on('ready', function() {
conf.exec = {cwd: dir}
conf.logs = path.resolve(path.join(dir, conf.logs || 'logs'))
conf.pids = path.resolve(path.join(dir, conf.pids || 'pids'))

mkdir(conf.logs)
mkdir(conf.pids)

conf.mon = path.join(__dirname, 'mon')
return conf
}
function showConfigure() {

function showConfigure () {
if (configure) {
getStatus()
return configure.show()
Expand All @@ -130,12 +128,12 @@ app.on('ready', function() {
configure.on('blur', hideConfigure)
configure.loadUrl('file://' + __dirname + '/index.html')
}
function hideConfigure() {

function hideConfigure () {
if (configure) return configure.hide()
}
function getStatus(err, procName) {

function getStatus (err, procName) {
if (err) throw err
if (!configure) return
debug('reload config, get proc status...')
Expand All @@ -146,7 +144,7 @@ app.on('ready', function() {
if (procName) procs = procs.filter(function filter (proc) {
return proc.name === procName
})
procs.forEach(function(proc) {
procs.forEach(function each (proc) {
var state = proc.state()
var uptime
if (state === 'alive') uptime = ms(Date.now() - proc.mtime(), { long: true })
Expand All @@ -161,32 +159,32 @@ app.on('ready', function() {

status.push(item)
})

if (procName) configure.webContents.send('got-one', status[0])
else configure.webContents.send('got-all', status)
}
function restart(procs, cb) {
stop(procs, function (err1) {
start(procs, function (err2) {

function restart (procs, cb) {
stop(procs, function onstop (err1) {
start(procs, function onstart (err2) {
if (cb) cb(err1 || err2)
})
})
}
function start(procs, cb) {

function start (procs, cb) {
var group = new Mongroup(conf)
group.start(procs, function (err) {
group.start(procs, function onstart (err) {
if (err) return cb(err)
cb()
})
}

function stop(procs, cb) {
function stop (procs, cb) {
var group = new Mongroup(conf)
group.stop(procs, 'SIGQUIT', function (err) {
group.stop(procs, 'SIGQUIT', function onstop (err) {
if (cb) return cb(err)
cb()
})
}
})
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "standard",
"app": "atom-shell ./",
"build": "atom-shell-packager . Monu --ignore=node_modules/atom-shell"
},
Expand All @@ -24,6 +24,7 @@
"ractive": "^0.7.1"
},
"devDependencies": {
"atom-shell": "^0.22.1"
"atom-shell": "^0.22.1",
"standard": "^3.2.1"
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Monu is currently **ALPHA STATUS** and is intended for developers/early adopters

To download the latest version visit the [releases page](https://github.com/maxogden/monu/releases)

[![js-standard-style](https://raw.githubusercontent.com/feross/standard/master/badge.png)](https://github.com/feross/standard)

[![Build Status](https://travis-ci.org/maxogden/monu.svg?branch=master)](https://travis-ci.org/maxogden/monu)

![screenshot.png](screenshot.png)

##### How to use Monu
Expand Down Expand Up @@ -56,4 +60,5 @@ If you would like Monu.app to start when your Mac starts up, got to <b>System Pr
```bash
npm install # installs atom-shell and all the deps needed for monu
npm run app # runs the app in the atom-shell wrapper
npm run build # builds the mac app
```

0 comments on commit a9564d3

Please sign in to comment.