-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
21 changed files
with
816 additions
and
369 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/lib/hub/view/public/sockjs-* | ||
/dep/ | ||
/doc/quick-start/index.mustache | ||
/api/ | ||
|
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,127 +1,148 @@ | ||
var fs = require('fs'); | ||
var execute = require('child_process').exec; | ||
var ronn = require('ronn').Ronn; | ||
var version = require('./lib/package').readPackageSync().version; | ||
var rimraf = require('rimraf'); | ||
var walk = require('walk'); | ||
|
||
function exec(command, onComplete) { | ||
execute(command, function (err, stdout, stderr) { | ||
if (typeof(onComplete) !== "function" && stdout) { | ||
console.log(stdout); | ||
} | ||
if (stderr) { | ||
console.log(stderr); | ||
/*global task, desc, fail, complete */ | ||
|
||
"use strict"; | ||
|
||
var fs = require("fs"); | ||
var child_process = require("child_process"); | ||
|
||
var Ronn = require("ronn").Ronn; | ||
var rimraf = require("rimraf"); | ||
var walk = require("walk"); | ||
|
||
var version = require("./lib/package").readPackageSync().version; | ||
|
||
function nuke(dir, completer) { | ||
rimraf(dir, function (err) { | ||
if (err) { | ||
fail(err); | ||
} else if ("function" === typeof completer) { | ||
completer(); | ||
} | ||
if (typeof(onComplete) === "function") { | ||
onComplete(stdout); | ||
}); | ||
} | ||
|
||
function spawn(command, args, completer) { | ||
child_process.spawn(command, args, { | ||
stdio: "inherit", | ||
customFds: [0, 1, 2] | ||
}).on("exit", function (code) { | ||
if (code !== 0) { | ||
fail(command + " " + args.join(" ") + | ||
" failed with " + code); | ||
} else if ("function" === typeof completer) { | ||
completer(); | ||
} | ||
}); | ||
} | ||
|
||
function getTestFiles(path) { | ||
var jsFilter = new RegExp('.js$'), | ||
jsTestFiles = fs.readdirSync(path).filter(function(elem, index, arr) { | ||
function bin(name, args, completer) { | ||
if (!args) { | ||
args = []; | ||
} | ||
spawn("node", ["node_modules/.bin/" + name].concat(args), completer); | ||
} | ||
|
||
function getTestFiles() { | ||
var path = "test", | ||
jsFilter = new RegExp(".js$"), | ||
jsTestFiles = fs.readdirSync(path).filter(function (elem, index, arr) { | ||
return jsFilter.test(elem); | ||
}).map(function (file) { | ||
return "test/" + file; | ||
}); | ||
|
||
return jsTestFiles; | ||
} | ||
|
||
function getJsFiles(path, cb) { | ||
var files = [], | ||
jsFilter = new RegExp('.js$'); | ||
walker = walk.walk(path, { followLInks: false }); | ||
jsFilter = new RegExp(".js$"), | ||
walker = walk.walk(path, { | ||
followLinks: false | ||
}); | ||
|
||
walker.on('file', function(root, stat, next) { | ||
walker.on("file", function (root, stat, next) { | ||
if (jsFilter.test(stat.name)) { | ||
files.push(root + '/' + stat.name); | ||
files.push(root + "/" + stat.name); | ||
} | ||
next(); | ||
}); | ||
|
||
walker.on('end', function() { | ||
walker.on("end", function () { | ||
cb(files); | ||
}); | ||
}); | ||
} | ||
|
||
desc('Default: install all modules including devDependencies'); | ||
task('default', function () { | ||
exec('npm install .'); | ||
}); | ||
desc("Default: install all modules including devDependencies"); | ||
task("default", ["install"]); | ||
|
||
desc('Install all modules including devDependencies'); | ||
task('install', function () { | ||
exec('npm install .'); | ||
desc("Install all modules including devDependencies"); | ||
task("install", function () { | ||
spawn("npm", ["install"], complete); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Run all of Yeti\'s unit tests'); | ||
task('test', function () { | ||
// RegExp for JavaScript test files (used for Windows compatibility) | ||
var index, jsTestFiles = getTestFiles('test'); | ||
|
||
for (index = 0; index < jsTestFiles.length; index++) { | ||
exec('node node_modules/vows/bin/vows test/' + jsTestFiles[index], | ||
{ customFds: [0,1,2] }); | ||
} | ||
desc("Run all of Yeti's unit tests"); | ||
task("test", function () { | ||
bin("vows", getTestFiles(), complete); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Run all of Yeti\'s unit tests with the \'--spec\' flag'); | ||
task('spec', function () { | ||
var index, jsTestFiles = getTestFiles('test'); | ||
|
||
for (index = 0; index < jsTestFiles.length; index++) { | ||
exec('node node_modules/vows/bin/vows --spec test/' + jsTestFiles[index], | ||
{ customFds: [0,1,2] }); | ||
} | ||
desc("Run all of Yeti's unit tests with the '--spec' flag"); | ||
task("spec", function () { | ||
bin("vows", ["--spec"].concat(getTestFiles()), complete); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Build coverage tools and write out test coverage HTML page'); | ||
task('coverage', function () { | ||
// nodejs-coverage may not work well on Windows so just use the original | ||
exec('scripts/coverage.sh'); | ||
desc("Build coverage tools and write out test coverage HTML page"); | ||
task("coverage", function () { | ||
spawn("bash", ["scripts/coverage.sh"], complete); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Build HTML documentation'); | ||
task('html', function() { | ||
fs.readFile('README.md', function (err, data) { | ||
desc("Build HTML documentation"); | ||
task("html", function () { | ||
fs.readFile("README.md", "utf8", function (err, data) { | ||
var md, html; | ||
// Remove Travis info | ||
var markdown = data.toString().substr(124); | ||
var html = new ronn(markdown).html(); | ||
var moddedHtml = html.replace(/<[\/]*html>/, '') | ||
.replace('<pre>', '<pre class="code"'); | ||
fs.writeFileSync('doc/quick-start/index.mustache', moddedHtml); | ||
exec('node node_modules/selleck/bin/selleck'); | ||
md = data.split("\n").slice(4).join("\n"), | ||
html = new Ronn(md).html() | ||
.replace(/<[\/]*html>/, "") | ||
.replace("<pre>", '<pre class="code"'); | ||
fs.writeFileSync("doc/quick-start/index.mustache", html); | ||
bin("selleck", [], complete); | ||
}); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Build API documentation'); | ||
task('html-api', ['html'], function () { | ||
exec('node node_modules/yuidocjs/lib/cli.js --project-version ' + version); | ||
desc("Build API documentation"); | ||
task("html-api", ["html"], function () { | ||
bin("yuidoc", ["--project-version", version], complete); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Run JSLint on all files, or a specific given file'); | ||
task('lint', function () { | ||
getJsFiles('./lib', function (files) { | ||
exec('node node_modules/jshint/bin/hint ' + files.join(' ')); | ||
desc("Run JSLint on all files, or a specific given file"); | ||
task("lint", function () { | ||
getJsFiles("./lib", function (files) { | ||
bin("jshint", files, complete); | ||
}); | ||
}, { | ||
async: true | ||
}); | ||
|
||
desc('Remove build documentation'); | ||
task('clean', function () { | ||
rimraf('build_docs', function (err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
desc("Remove build documentation"); | ||
task("clean", function () { | ||
nuke("build_docs"); | ||
}); | ||
|
||
desc('Remove development tools'); | ||
task('maintainer-clean', function () { | ||
exec('npm rm webkit-devtools-agent'); | ||
rimraf('tools', function (err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
desc("Remove development tools"); | ||
task("maintainer-clean", function () { | ||
spawn("rpm", ["rm", "webkit-devtools-agent"]); | ||
nuke("tools"); | ||
}); |
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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
|
||
/** | ||
* @module hijack | ||
*/ | ||
|
||
/** | ||
* Attach the provided function as the first | ||
* listener of the given EventEmitter event. | ||
* | ||
* All listeners of the event will be removed | ||
* and replaced with a listener that will run | ||
* the provided function first, followed by | ||
* the original listeners if the function | ||
* returned false. | ||
* | ||
* Works with Node.js v0.7+ where the array | ||
* returned by `ee.listeners()` is a reference. | ||
* | ||
* @method hijack | ||
* @param {EventEmitter} ee Emitter. | ||
* @param {String} event Event name. | ||
* @param {Function} firstFn Function to run first. | ||
*/ | ||
module.exports = function hijack(ee, event, firstFn) { | ||
var listeners = ee.listeners(event), | ||
i = 0, | ||
length = listeners.length, | ||
originalListeners = []; | ||
|
||
// Note: listeners is a reference in Node v0.7. | ||
// Calling `removeAllListeners` no longer destroys | ||
// the listener array, which causes it survive | ||
// as a reference. See joyent/node commits: | ||
// - 78dc13fbf97e2e3003e6f3baacdd5ff60e8de3f7 | ||
// - 928ea564d16da47e615ddac627e0b4d4a40d8196 | ||
// | ||
// Make a copy first. | ||
for (; i < length; i += 1) { | ||
originalListeners[i] = listeners[i]; | ||
} | ||
|
||
ee.removeAllListeners(event); | ||
|
||
ee.on(event, function () { | ||
var args = Array.prototype.slice.call(arguments), | ||
stack = [firstFn].concat(originalListeners), | ||
handled; | ||
|
||
handled = firstFn.apply(ee, args); | ||
|
||
if (!handled) { | ||
originalListeners.forEach(function (fn) { | ||
fn.apply(ee, args); | ||
}); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.