Skip to content

Commit

Permalink
switch tabs to spaces. jshint is now much stricter. bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
pstadler committed Mar 13, 2014
1 parent ac4f368 commit 95c78ba
Show file tree
Hide file tree
Showing 14 changed files with 1,166 additions and 1,160 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,5 @@ transport.abort('Severe turbulences over the atlantic ocean!');

<!-- ENDDOCS -->

## What's planned?

- Add possibility to define a `sudoUser` per host with `briefing()`.
- Tests will be implemented with upcoming releases. A part of this will be driven by bug reports.

[npm-url]: https://npmjs.org/package/flightplan
[npm-image]: https://badge.fury.io/js/flightplan.png
42 changes: 21 additions & 21 deletions bin/fly.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
#!/usr/bin/env node
var path = require('path')
, fs = require('fs')
, program = require('commander')
, logger = new (require('../lib/logger'))()
, version = require('../package.json').version;
, fs = require('fs')
, program = require('commander')
, logger = new (require('../lib/logger'))()
, version = require('../package.json').version;

program
.usage('<destination> [options]')
.version(version)
.option('-p, --plan <file>', 'path to flightplan (default: flightplan.js)', 'flightplan.js')
.option('-u, --username <string>', 'user for connecting to remote hosts')
.option('-d, --debug', 'enable debug mode')
.parse(process.argv);
.usage('<destination> [options]')
.version(version)
.option('-p, --plan <file>', 'path to flightplan (default: flightplan.js)', 'flightplan.js')
.option('-u, --username <string>', 'user for connecting to remote hosts')
.option('-d, --debug', 'enable debug mode')
.parse(process.argv);

var flightFile = path.join(process.cwd(), program.plan);

if(!fs.existsSync(flightFile)) {
logger.error(logger.format('Unable to load %s', program.plan.white));
process.exit(1);
logger.error(logger.format('Unable to load %s', program.plan.white));
process.exit(1);
}

var flightplan = require(flightFile)
, options = {
username: program.username || null,
debug: program.debug || null
};
, options = {
username: program.username || null,
debug: program.debug || null
};

var destination = program.args[0];

if(!flightplan.requiresDestination) {
logger.error(logger.format('%s is not a valid flightplan', program.plan.white));
process.exit(1);
logger.error(logger.format('%s is not a valid flightplan', program.plan.white));
process.exit(1);
}

if(!destination && flightplan.requiresDestination()) {
logger.error('Please specfiy a destination');
program.help();
process.exit(1);
logger.error('Please specfiy a destination');
program.help();
process.exit(1);
}

flightplan.start(destination, options);
84 changes: 49 additions & 35 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
var fs = require('fs')
, gulp = require('gulp')
, stylish = require('jshint-stylish')
, jshint = require('gulp-jshint')
, markdox = require('markdox');
, gulp = require('gulp')
, stylish = require('jshint-stylish')
, jshint = require('gulp-jshint')
, markdox = require('markdox');

var sourceFiles = ['*.js', 'lib/**/*.js', 'bin/**/*.js'];

gulp.task('lint', function() {
var jshintOptions = {
laxcomma: true
};
return gulp.src(sourceFiles)
.pipe(jshint(jshintOptions))
.pipe(jshint.reporter(stylish));
var jshintOptions = {
laxcomma: true,
laxbreak: true,
node: true,
curly: true,
camelcase: true,
eqeqeq: true,
maxdepth: 3,
maxlen: 100,
newcap: true,
noempty: true,
latedef: true,
noarg: true,
unused: true,
trailing: true,
indent: 2
};
return gulp.src(sourceFiles)
.pipe(jshint(jshintOptions))
.pipe(jshint.reporter(stylish));
});

gulp.task('docs', function(taskFinished) {
var sources = ['lib/flightplan.js', 'lib/transport/transport.js']
, readme = 'README.md'
, tmpFile = 'docs/API.md';

var options = {
template: 'docs/template.md.ejs',
output: tmpFile
};

markdox.process(sources, options, function() {
var docsStr = fs.readFileSync(tmpFile, 'utf8')
, readmeStr = fs.readFileSync(readme, 'utf8');

docsStr = docsStr
.replace(/&#39;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&amp;/g, '&');
readmeStr = readmeStr.replace(/(<!-- DOCS -->)(?:\r|\n|.)+(<!-- ENDDOCS -->)/gm
, "$1" + docsStr + "$2");

fs.writeFileSync(readme, readmeStr);
fs.unlinkSync(tmpFile);
console.log('Documentation generated.');
taskFinished();
});
var sources = ['lib/flightplan.js', 'lib/transport/transport.js']
, readme = 'README.md'
, tmpFile = 'docs/API.md';

var options = {
template: 'docs/template.md.ejs',
output: tmpFile
};

markdox.process(sources, options, function() {
var docsStr = fs.readFileSync(tmpFile, 'utf8')
, readmeStr = fs.readFileSync(readme, 'utf8');

docsStr = docsStr
.replace(/&#39;/g, "'")
.replace(/&quot;/g, '"')
.replace(/&amp;/g, '&');
readmeStr = readmeStr.replace(/(<!-- DOCS -->)(?:\r|\n|.)+(<!-- ENDDOCS -->)/gm
, "$1" + docsStr + "$2");

fs.writeFileSync(readme, readmeStr);
fs.unlinkSync(tmpFile);
console.log('Documentation generated.');
taskFinished();
});
});

gulp.task('default', ['lint']);
78 changes: 38 additions & 40 deletions lib/briefing.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
var util = require('util');

function Briefing(flightplan, config) {
this.flightplan = flightplan;
config = config || {};
this.debug = config.debug || false;
this.destinations = config.destinations || {};
this.flightplan.logger.enableDebug(this.debug);
this.flightplan = flightplan;
config = config || {};
this.debug = config.debug || false;
this.destinations = config.destinations || {};
this.flightplan.logger.enableDebug(this.debug);
}

Briefing.prototype = {

applyOptions: function(options) {
var destinations = this.getDestinations();
if(options.username && destinations) {
destinations.forEach(function(destination) {
var hosts = this.getHostsForDestination(destination);
for(var i=0, len=hosts.length; i < len; i++) {
hosts[i].username = options.username;
}
}.bind(this));
}
if(options.debug !== undefined && options.debug !== null) {
this.debug = options.debug;
this.flightplan.logger.enableDebug(this.debug);
}
},
applyOptions: function(options) {
var destinations = this.getDestinations();
if(options.username && destinations) {
destinations.forEach(function(destination) {
var hosts = this.getHostsForDestination(destination);
for(var i=0, len=hosts.length; i < len; i++) {
hosts[i].username = options.username;
}
}.bind(this));
}
if(options.debug !== undefined && options.debug !== null) {
this.debug = options.debug;
this.flightplan.logger.enableDebug(this.debug);
}
},

getDestinations: function() {
return Object.keys(this.destinations);
},
getDestinations: function() {
return Object.keys(this.destinations);
},

getHostsForDestination: function(destination) {
try {
var hosts = this.destinations[destination];
return (hosts instanceof Array) ? hosts : [hosts];
} catch(e) {
return null;
}
},
getHostsForDestination: function(destination) {
try {
var hosts = this.destinations[destination];
return (hosts instanceof Array) ? hosts : [hosts];
} catch(e) {
return null;
}
},

hasDestination: function(destination) {
try {
return !!this.destinations[destination];
} catch(e) {
return false;
}
}
hasDestination: function(destination) {
try {
return !!this.destinations[destination];
} catch(e) {
return false;
}
}
};

module.exports = Briefing;
92 changes: 46 additions & 46 deletions lib/flight.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
var Fiber = require('fibers')
, Future = require('fibers/future');
, Future = require('fibers/future');

function Flight(flightplan, transportClass, fn) {
this.flightplan = flightplan;
this.fn = fn;
this.transportClass = transportClass;
this.logger = flightplan.logger;
this.hosts = null;
this.status = {
aborted: false,
crashRecordings: null,
executionTime: 0 // milliseconds
};
this.flightplan = flightplan;
this.fn = fn;
this.transportClass = transportClass;
this.logger = flightplan.logger;
this.hosts = null;
this.status = {
aborted: false,
crashRecordings: null,
executionTime: 0 // milliseconds
};
}

Flight.prototype = {

start: function(destination) {
this.hosts = this.flightplan.briefing().getHostsForDestination(destination);
this.__start();
return this.getStatus();
},
start: function(destination) {
this.hosts = this.flightplan.briefing().getHostsForDestination(destination);
this.__start();
return this.getStatus();
},

abort: function(msg) {
throw new Error(msg);
},
abort: function(msg) {
throw new Error(msg);
},

isAborted: function() {
return this.status.aborted;
},
isAborted: function() {
return this.status.aborted;
},

getStatus: function() {
return this.status;
},
getStatus: function() {
return this.status;
},

__start: function() {
var future = new Future();
__start: function() {
var future = new Future();

var task = function() {
Fiber(function() {
var t = process.hrtime();
var task = function() {
new Fiber(function() {
var t = process.hrtime();

var transport = new this.transportClass(this);
try {
this.fn(transport);
} catch(e) {
this.status.aborted = true;
this.status.crashRecordings = e.message || null;
this.flightplan.abort();
}
transport.close();
var transport = new this.transportClass(this);
try {
this.fn(transport);
} catch(e) {
this.status.aborted = true;
this.status.crashRecordings = e.message || null;
this.flightplan.abort();
}
transport.close();

this.status.executionTime = process.hrtime(t);
this.status.executionTime = process.hrtime(t);

return future.return();
}.bind(this)).run();
return future.return();
}.bind(this)).run();

return future;
}.bind(this);
return future;
}.bind(this);

Future.wait(task());
}
Future.wait(task());
}
};

module.exports = Flight;
Loading

0 comments on commit 95c78ba

Please sign in to comment.