Skip to content

Commit

Permalink
allows notification to be done with script instead of server
Browse files Browse the repository at this point in the history
Allows notification to be done with script instead of server, exposing
a single 'call' method. Global installation is not required in this
point.
  • Loading branch information
Jurriën Dokter committed Nov 6, 2013
1 parent 9712c6d commit 4cda9db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
35 changes: 26 additions & 9 deletions lib/node-osx-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,30 @@ function route(req, res) {
});
}

// setup routes
server.use(express.bodyParser());
server.get('/:type', command.bind('query'), route);
server.post('/:type', command.bind('body'), route);
if(!module.parent) {
// setup routes
server.use(express.bodyParser());
server.get('/:type', command.bind('query'), route);
server.post('/:type', command.bind('body'), route);

// start server
console.info('starting server...');
server.listen(port, hostname, function(){
console.info('server started:', 'http://'+hostname+':'+port);
});
// start server
console.info('starting server...');
server.listen(port, hostname, function(){
console.info('server started:', 'http://'+hostname+':'+port);
});
} else {
module.exports = {
call: function(type, args, cb) {
console.info.apply(console, ['Notifying >'].concat([type], args));

var file = binary.replace('{type}', type);
var method_args = [];
Object.keys(args).forEach(function(arg){
method_args.push('-' + arg);
method_args.push(args[arg]);
});

execute(file, method_args, cb);
}
};
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"engines":{
"node":">= 0.8.0"
},
"preferGlobal":"true",
"bin":{
"node-osx-notifier":"lib/node-osx-notifier.js"
},
Expand Down

0 comments on commit 4cda9db

Please sign in to comment.