Comparing version 0.1.2 to 0.2.0
@@ -0,1 +1,16 @@ | ||
2014-03-27, Version v0.2.0 | ||
========================== | ||
* Disable colours if stdout is not a TTY (Ryan Graham) | ||
* procfile: Use real shell expansion for commands (Evan Owen) | ||
* Add Travis-CI (Ryan Graham) | ||
* test: Improve test portability (Ryan Graham) | ||
* export: Use runlevels in Upstart jobs (Ryan Graham) | ||
* Version dependencies (Ryan Graham) | ||
2014-03-27, Version v0.1.2 | ||
@@ -6,2 +21,4 @@ ========================== | ||
* Ignore npm packed tarballs (Ryan Graham) | ||
2014-03-27, Version v0.1.1 | ||
@@ -8,0 +25,0 @@ ========================== |
@@ -21,5 +21,13 @@ var reset = '\x1B[0m'; | ||
function identity(self) { | ||
return self | ||
} | ||
function colorizer(color) { | ||
return function (str) { | ||
return colors[color] + str + reset; | ||
if (process.stdout.isTTY) { | ||
return function (str) { | ||
return colors[color] + str + reset; | ||
} | ||
} else { | ||
return identity | ||
} | ||
@@ -26,0 +34,0 @@ } |
@@ -18,28 +18,13 @@ var prog = require('child_process') | ||
function run(key,proc,emitter){ | ||
var child = prog.exec(proc.command, { env: proc.env }); | ||
var command = proc.command; | ||
var args = proc.args; | ||
var opts = { | ||
env: proc.env | ||
}; | ||
// change sub-process switch style on Windows | ||
if(platform === 'win32'){ | ||
args.unshift(command); | ||
args = ['/C', args.join(' ')]; | ||
command = 'cmd'; | ||
opts.windowsVerbatimArguments = true; | ||
} | ||
var cmd = prog.spawn(command,args,opts); | ||
cmd.stdout.on('data',function(data){ | ||
child.stdout.on('data',function(data){ | ||
cons.log(key,proc,data.toString()); | ||
}); | ||
cmd.stderr.on('data',function(data){ | ||
child.stderr.on('data',function(data){ | ||
cons.log(key,proc,data.toString()); | ||
}); | ||
cmd.on('close',function(code){ | ||
child.on('close',function(code){ | ||
if(code==0){ | ||
@@ -51,9 +36,9 @@ cons.info(key,proc,"Exited Successfully"); | ||
}); | ||
cmd.on('exit',function(code){ | ||
child.on('exit',function(code){ | ||
emitter.emit('killall'); | ||
}); | ||
emitter.on('killall',function(){ | ||
cmd.kill(); | ||
child.kill(); | ||
}); | ||
@@ -72,7 +57,7 @@ | ||
var port = parseInt(portarg); | ||
if(port<1024) | ||
return cons.Error('Only Proxies Can Bind to Privileged Ports - '+ | ||
'Try \'sudo nf start -x %s\'',port); | ||
for(key in requirements){ | ||
@@ -84,3 +69,3 @@ var n = parseInt(requirements[key]); | ||
var color_val = (j+k) % colors_max; | ||
if (!procs[key]){ | ||
@@ -90,8 +75,7 @@ cons.Warn("Required Key '%s' Does Not Exist in Procfile Definition",key); | ||
} | ||
var p = { | ||
command : procs[key].command, | ||
args : procs[key].args, | ||
command : procs[key], | ||
color : colors[color_val], | ||
env : envs | ||
env : merge(merge({}, process.env), envs) | ||
} | ||
@@ -111,3 +95,13 @@ | ||
// Merge object b into object a | ||
function merge(a, b) { | ||
if (a && b) { | ||
for (var key in b) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
} | ||
module.exports.start = start | ||
module.exports.run = run |
@@ -15,3 +15,3 @@ var fs = require('fs') | ||
// Parse Procfile | ||
function procs(procdata,envs){ | ||
function procs(procdata){ | ||
@@ -21,3 +21,3 @@ var processes = {}; | ||
procdata.toString().split(/\n/).forEach(function(line){ | ||
if(line=='') return; | ||
if(!line) return; | ||
@@ -29,40 +29,9 @@ var tuple = /^([A-Za-z0-9_-]+):\s*(.+)$/m.exec(line); | ||
if(prockey=='') | ||
if(!prockey) | ||
return cons.Warn('Syntax Error in Procfile, Line %d: No Prockey Found',i+1); | ||
if(command=='') | ||
if(!command) | ||
return cons.Warn('Syntax Error in Procfile, Line %d: No Command Found',i+1); | ||
var comm = command.split(/\s/); | ||
var args = comm.splice(1,comm.length); | ||
// Substitute $variables for their values | ||
var key, i = 0; | ||
for (; i < args.length; i++) { | ||
if (envs) { | ||
for (key in envs) { | ||
args[i] = replaceVar(args[i], key, envs[key]); | ||
} | ||
} | ||
// If there's still possibly variables, then use process.env vars | ||
if (args[i].indexOf('$') !== -1) { | ||
for (key in _process.env) { | ||
args[i] = replaceVar(args[i], key, _process.env[key]); | ||
} | ||
} | ||
// Warn on unmatched substitutions | ||
if(args[i].match(/^\$\S+/)) cons.Warn('Unresovled Substitution in %s:',prockey,args[i]); | ||
} | ||
var process = { | ||
command : comm[0], | ||
args : args | ||
}; | ||
processes[prockey]=process; | ||
processes[prockey]=command; | ||
}); | ||
@@ -74,7 +43,7 @@ | ||
// Look for a Procfile at the Specified Location | ||
function loadProc(path,envs){ | ||
function loadProc(path){ | ||
try{ | ||
var data = fs.readFileSync(path); | ||
return procs(data,envs); | ||
return procs(data); | ||
}catch(e){ | ||
@@ -81,0 +50,0 @@ cons.Warn('No Procfile Found') |
10
nf.js
@@ -71,3 +71,3 @@ #!/usr/bin/env node | ||
var proc = loadProc(program.procfile,envs); | ||
var proc = loadProc(program.procfile); | ||
@@ -123,3 +123,3 @@ if(!proc) return; | ||
var procs = loadProc(program.procfile,envs); | ||
var procs = loadProc(program.procfile); | ||
@@ -182,5 +182,5 @@ if(!procs) return; | ||
var c = {}; | ||
var proc = procs[key]; | ||
var cmd = procs[key]; | ||
if (!proc){ | ||
if (!cmd){ | ||
display.Warn("Required Key '%s' Does Not Exist in Procfile Definition",key); | ||
@@ -192,3 +192,3 @@ continue; | ||
c.process=key; | ||
c.command=proc.command + " " + proc.args.join(' '); | ||
c.command=cmd; | ||
@@ -195,0 +195,0 @@ for(_ in config){ |
{ | ||
"name": "foreman", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"homepage": "http://strongloop.github.io/node-foreman/", | ||
@@ -23,5 +23,5 @@ "description": "Node Implementation of Foreman", | ||
"dependencies": { | ||
"commander": "latest", | ||
"mu2": "latest", | ||
"http-proxy": "latest" | ||
"commander": "~2.1.0", | ||
"mu2": "~0.5.20", | ||
"http-proxy": "~1.0.3" | ||
}, | ||
@@ -41,5 +41,5 @@ "repository": { | ||
"devDependencies": { | ||
"tap": "^0.4.8", | ||
"chai": "^1.9.1" | ||
"tap": "~0.4.8", | ||
"chai": "~1.9.1" | ||
} | ||
} |
@@ -1,10 +0,10 @@ | ||
# Node Foreman | ||
# Node Foreman [![Build Status](https://travis-ci.org/strongloop/node-foreman.svg)](https://travis-ci.org/strongloop/node-foreman) | ||
Node Foreman is a Node.js version of the popular | ||
Node Foreman is a Node.js version of the popular | ||
[Foreman](http://ddollar.github.com/foreman/) tool, | ||
with a few Node specific changes. | ||
> Foreman is a manager for Procfile-based applications. | ||
> Its aim is to abstract away the details of the Procfile | ||
> format, and allow you to either run your application | ||
> Foreman is a manager for Procfile-based applications. | ||
> Its aim is to abstract away the details of the Procfile | ||
> format, and allow you to either run your application | ||
> directly or export it to some other process management format. | ||
@@ -18,6 +18,2 @@ | ||
All of Foremans version dependencies have been set to use `latest`. | ||
If however you find a dependency should break it is possible to find out which dependency versions were last working with Foreman. | ||
The `npm-shrinkwrap.json` file is updated each time Foreman is published to npm. | ||
### How to Contribute | ||
@@ -28,5 +24,5 @@ | ||
If you would like to make a code change, go ahead. | ||
Fork the repository, open a pull request. | ||
Do this early, and talk about the change you want to make. | ||
If you would like to make a code change, go ahead. | ||
Fork the repository, open a pull request. | ||
Do this early, and talk about the change you want to make. | ||
Maybe we can work together on it. | ||
@@ -67,3 +63,3 @@ | ||
The `Procfile` format is a simple `key : command` format: | ||
web: node web_server.js | ||
@@ -91,3 +87,3 @@ api: node api_server.js | ||
The above JSON document will be flattened into env variables by | ||
The above JSON document will be flattened into env variables by | ||
concatenating the nested values with an underscore. | ||
@@ -131,3 +127,3 @@ Environmental variables are passed in fully capitalized. | ||
$ nf start web=5 | ||
18:51:12: web.1 | Web Server started listening on 0.0.0.0:5000 | ||
@@ -140,3 +136,3 @@ 18:51:12: web.2 | Web Server started listening on 0.0.0.0:5001 | ||
Each job will be started as its own process, receiving a different `PORT` | ||
environmental variable. | ||
environmental variable. | ||
The port number for processes of the same type will be offset by 1. | ||
@@ -146,3 +142,3 @@ The port number for processes of different types will be offset by 100. | ||
$ nf start web=2,api=2 | ||
18:51:12: web.1 | Web Server started listening on 0.0.0.0:5000 | ||
@@ -187,3 +183,3 @@ 18:51:12: web.2 | Web Server started listening on 0.0.0.0:5001 | ||
The export will occur with whatever environmental variables are | ||
The export will occur with whatever environmental variables are | ||
listed in the .env file. | ||
@@ -199,3 +195,3 @@ | ||
You can specify the type and number of processes exported using | ||
You can specify the type and number of processes exported using | ||
the `type=num` syntax: | ||
@@ -273,2 +269,1 @@ | ||
For users with Google Chrome, this can be paired with [Proxy Switch Sharp](http://switchy.samabox.com/) for great results. | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63
319007
951
260
21
+ Addedcommander@2.1.0(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedhttp-proxy@1.0.3(transitive)
- Removedcommander@13.1.0(transitive)
- Removedeventemitter3@4.0.7(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedhttp-proxy@1.18.1(transitive)
- Removedrequires-port@1.0.0(transitive)
Updatedcommander@~2.1.0
Updatedhttp-proxy@~1.0.3
Updatedmu2@~0.5.20