Browse files

Multistage, removed runInNewContext

  • Loading branch information...
1 parent 4f66c40 commit 59d259f7cdf7095e2012ca5638417c3f6160add7 @1602 committed Oct 15, 2012
Showing with 29 additions and 23 deletions.
  1. +13 −2 bin/roco
  2. +1 −1 cockout/deploy.coffee
  3. +15 −20 lib/rockout.js
View
15 bin/roco
@@ -9,14 +9,25 @@ var argv = optimist
console.log(argv);
var roco = require('../lib/rockout');
-roco.init();
+
+var env, command;
+if (argv._[1]) {
+ env = argv._[0];
+ command = argv._[1];
+} else if (argv._[0]) {
+ env = 'production';
+ command = argv._[0];
+} else {
+ // ???
+}
+roco.init(env);
if (argv.T) {
roco.list(argv.T);
} else if (argv.t) {
roco.list(argv.t, true);
} else if (argv._.length) {
- roco.perform(argv._);
+ roco.perform(command);
} else {
optimist.showHelp();
console.log('Environment variables:\n');
View
2 cockout/deploy.coffee
@@ -28,7 +28,7 @@ ensure 'job', ->
if roco.env == 'production'
roco.application
else
- roco.application '-' + roco.env
+ roco.application + '-' + roco.env
namespace 'deploy', ->
View
35 lib/rockout.js
@@ -10,7 +10,6 @@ var beforeTask = {};
var afterTask = {};
var existsSync = fs.existsSync || path.existsSync;
-
/**
* Print arguments to stdout using util.puts
*/
@@ -21,8 +20,8 @@ function log() {
/**
* Initialize module. Creates module-wide global variable called `roco`
*/
-exports.init = function () {
- return roco = new Roco;
+exports.init = function (env) {
+ return roco = new Roco(env);
};
/**
@@ -32,18 +31,10 @@ exports.init = function () {
* [0] {String} env - environment (optional)
* [1] {String} command
*/
-exports.perform = function (what) {
- var env = what[0];
- var cmd = what[1];
-
- // check whether env param omitted
- if (!cmd || roco[env] || roco[env + ':default']) {
- cmd = env;
- env = 'production';
- }
+exports.perform = function (cmd) {
+ var env = roco.env;
log('Running in', $(env).bold, 'mode');
- roco.set('env', env);
if (roco[cmd]) {
roco[cmd]();
@@ -72,12 +63,10 @@ exports.list = function listTasks(how, noDescriptions) {
*
* Every rocofile changes context of this object.
*/
-function Roco() {
+function Roco(env) {
roco = this;
- roco.__defineGetter__('roco', function () { return roco; });
- Object.keys(Roco.prototype).forEach(function (method) {
- roco[method] = Roco.prototype[method];
- });
+ roco.env = env;
+ roco.roco = this;
this.init();
}
@@ -152,6 +141,9 @@ Roco.prototype.log = function () {
* HOSTS jsdoc.info:222,node-js.ru:2222 roco i:free
*/
Roco.prototype.run = function (cmd, callback) {
+ if (typeof roco.hosts === 'string') {
+ roco.hosts = [roco.hosts];
+ }
log('Executing ' + $(cmd).yellow + ' on ' + $(roco.hosts.join(', ')).blue);
var wait = 0;
data = [];
@@ -282,9 +274,12 @@ Roco.prototype.set = function (key, def) {
*/
Roco.prototype.load = function (file) {
if (!file) throw new Error('File not specified');
+ if (!fs.existsSync(file)) return;
+ console.log('loading', file);
var code = coffee.compile(fs.readFileSync(file).toString());
- var script = vm.createScript(code, file);
- script.runInNewContext(this);
+ var dir = path.dirname(file);
+ var fn = new Function('roco', '__dirname', 'with(roco){(function(){ ' + code + ' })();}');
+ fn(this, dir);
};
/**

0 comments on commit 59d259f

Please sign in to comment.