Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henry Lawson
committed
Jul 22, 2012
0 parents
commit 91a5fe9
Showing
7 changed files
with
174 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var bolt = require("./lib/bolt"); | ||
bolt.task = require("./build/tasks"); | ||
|
||
bolt.execute(process.argv); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var spawn = require('child_process').spawn; | ||
var path = require('path'); | ||
var bolt = require("../lib/bolt"); | ||
|
||
this.tests = function() { | ||
var jasmineScript = path.join("node_modules", "jasmine-node", "bin", "jasmine-node"); | ||
var specsFolder = path.join("specs"); | ||
return bolt.captureOutput("Tests", spawn("node", [jasmineScript, specsFolder])); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/bolt'); |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var q = require('q'); | ||
|
||
this.task = {}; | ||
this.captureOutput = function(name, spawnedProcess) { | ||
console.log("Executing " + name); | ||
var deferred = q.defer(); | ||
spawnedProcess.stdout.on('data', function (data) { | ||
process.stdout.write('' + data); | ||
}); | ||
spawnedProcess.stderr.on('data', function (data) { | ||
process.stdout.write('' + data); | ||
}); | ||
spawnedProcess.on('exit', function (code) { | ||
console.log(name + ' exited with: ' + code); | ||
deferred.resolve(); | ||
}); | ||
return deferred.promise; | ||
}; | ||
this.execute = function(args) { | ||
var argv = args.slice(2); | ||
var bolt = this; | ||
if (argv.length > 0) { | ||
argv.forEach(function (taskName, index) { | ||
bolt.task[taskName](); | ||
}); | ||
} else { | ||
bolt.task.default(); | ||
} | ||
return 0; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "bolt", | ||
"description": "A simple task runner tool", | ||
"version": "0.0.1", | ||
"author": { | ||
"name": "Henry Lawson", | ||
"email": "hen3rz@gmail.com" | ||
}, | ||
"dependencies": { | ||
"q" : "0.x" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node" : "1.x" | ||
}, | ||
"keywords": [ | ||
"bolt", | ||
"runner", | ||
"nant", | ||
"ant", | ||
"build" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/henrylawson/bolt.git" | ||
}, | ||
"main": "index", | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"_id": "bolt@0.0.1", | ||
"optionalDependencies": {}, | ||
"_engineSupported": true, | ||
"_npmVersion": "1.1.21", | ||
"_nodeVersion": "v0.6.18", | ||
"_defaultsLoaded": true, | ||
"_from": "bolt@0.0" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var bolt = require("../lib/bolt"); | ||
|
||
describe("Bolt", function() { | ||
describe("captureOutput", function() { | ||
var taskName; | ||
var spawnedProcess; | ||
|
||
beforeEach(function() { | ||
spyOn(process.stdout, 'write'); | ||
taskName = "A Task Name"; | ||
spawnedProcess = { | ||
stdout: { | ||
on: jasmine.createSpy() | ||
}, | ||
stderr: { | ||
on: jasmine.createSpy() | ||
}, | ||
on: jasmine.createSpy() | ||
}; | ||
}); | ||
|
||
it("should write executing message to stdout", function() { | ||
bolt.captureOutput(taskName, spawnedProcess); | ||
|
||
expect(process.stdout.write.mostRecentCall.args[0]).toContain(taskName); | ||
}); | ||
|
||
it("should write spawned process stdout messages to the hosting process stdout", function() { | ||
var data = "standard out message"; | ||
|
||
bolt.captureOutput(taskName, spawnedProcess); | ||
spawnedProcess.stdout.on.mostRecentCall.args[1](data); | ||
|
||
expect(spawnedProcess.stdout.on.mostRecentCall.args[0]).toEqual("data"); | ||
expect(process.stdout.write.mostRecentCall.args[0]).toEqual(data); | ||
}); | ||
|
||
it("should write spawned process stderr messages to the hosting process stdout", function() { | ||
var data = "standard error message"; | ||
|
||
bolt.captureOutput(taskName, spawnedProcess); | ||
spawnedProcess.stderr.on.mostRecentCall.args[1](data); | ||
|
||
expect(spawnedProcess.stderr.on.mostRecentCall.args[0]).toEqual("data"); | ||
expect(process.stdout.write.mostRecentCall.args[0]).toEqual(data); | ||
}); | ||
|
||
it("should write exit code to stdout", function() { | ||
var exitCode = 0; | ||
|
||
bolt.captureOutput(taskName, spawnedProcess); | ||
spawnedProcess.on.mostRecentCall.args[1](exitCode); | ||
|
||
expect(spawnedProcess.on.mostRecentCall.args[0]).toEqual("exit"); | ||
expect(process.stdout.write.mostRecentCall.args[0]).toContain('exited with: ' + exitCode); | ||
expect(process.stdout.write.mostRecentCall.args[0]).toContain(taskName); | ||
}); | ||
|
||
it("should resolve promise when spawned process exits", function() { | ||
var promiseResolvedSpy = jasmine.createSpy("Promise resolved"); | ||
bolt.captureOutput(taskName, spawnedProcess) | ||
.then(promiseResolvedSpy()); | ||
|
||
spawnedProcess.on.mostRecentCall.args[1](0); | ||
|
||
expect(promiseResolvedSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("execute", function() { | ||
it("should execute default when no arguments provided", function() { | ||
var args = ["temp", "temp"]; | ||
bolt.task.default = jasmine.createSpy("Default task"); | ||
|
||
bolt.execute(args); | ||
|
||
expect(bolt.task.default).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should execute the tasks provided by the command line", function() { | ||
var args = ["temp", "temp", "task1", "task2"]; | ||
bolt.task.task1 = jasmine.createSpy("Task 1"); | ||
bolt.task.task2 = jasmine.createSpy("Task 2"); | ||
|
||
bolt.execute(args); | ||
|
||
expect(bolt.task.task1).toHaveBeenCalled(); | ||
expect(bolt.task.task2).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |