-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch tabs to spaces. jshint is now much stricter. bump version.
- Loading branch information
Showing
14 changed files
with
1,166 additions
and
1,160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(/'/g, "'") | ||
.replace(/"/g, '"') | ||
.replace(/&/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(/'/g, "'") | ||
.replace(/"/g, '"') | ||
.replace(/&/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']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.