Skip to content

Commit

Permalink
alpha version of woodchipper
Browse files Browse the repository at this point in the history
  • Loading branch information
Hays Clark committed Sep 27, 2015
1 parent bf70cb3 commit 0fb7c96
Show file tree
Hide file tree
Showing 26 changed files with 1,107 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.idea
node_modules/
woodchipper-*.tgz
coverage/
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
.git
.gitignore
.travis.yml
node_modules
spec
coverage
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.12"

after_success:
- ./node_modules/.bin/istanbul cover -x '**/spec/**' ./node_modules/mocha/bin/_mocha --report lcovonly -- --recursive --require spec/helpers/chai.js spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2015 Hays Clark

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# scrutiny
Woodchipper [![Build Status](https://travis-ci.org/haysclark/woodchipper.svg)](https://travis-ci.org/haysclark/woodchipper)[![Coverage Status](https://coveralls.io/repos/haysclark/woodchipper/badge.svg?branch=develop&service=github)](https://coveralls.io/github/haysclark/woodchipper?branch=develop)
===========

A simple module and CLI utility that converts [Treeherder](https://wiki.mozilla.org/Auto-tools/Projects/Treeherder) (the successor to [TBPL](https://wiki.mozilla.org/Sheriffing/TBPL)) output to [JUnit](http://junit.org/) xml.

## Installation

npm install woodchipper -g

## Usage

woodchipper [--version] [--help] [--format=<name>] <input>

## Tests

npm test
npm run coverage

## Development

npm install
npm link
woodchipper

## Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.

## Release History

* 0.8.9 alpha release
9 changes: 9 additions & 0 deletions bin/woodchipper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

var cli = require('../lib/cli'),
argv = require('minimist')(process.argv.slice(2));

/**
* treating the CLI as a module for better test coverage.
*/
cli.argv(argv);
17 changes: 17 additions & 0 deletions doc/cli/about.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Name:

woodchipper - chops up trees

Description:

Simple Treeherder converter.

Usage:

woodchipper [--version] [--help] [--format=<name>] <input>

Options:

-v, --version output version number
-h, --help output usage information
-f, --format output format (default format is junit)
2 changes: 2 additions & 0 deletions doc/cli/usage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

usage: woodchipper [--version] [--help] [--format=<name>] <input>
40 changes: 40 additions & 0 deletions lib/cli/argv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var argv = require('./argv'),
help = require('./help'),
version = require('./version'),
parse = require('./parse');

/**
* routes argv settings to cli modules
*
* @param argv
*/
module.exports = function(argv) {
// --help or -h
argv.help = argv.help || argv.h;
if(argv.help) {
help(null, onComplete);
return;
}

// --version or -v
argv.version = argv.version || argv.v;
if(argv.version) {
version(argv, onComplete);
}

// default parse action
parse(argv, onComplete);
};

function onComplete(err, data) {
if(err) {
console.error(err);
help('usage', logger);
process.exit(1);
}
logger(null, data);
};

function logger(err, data) {
console.log(data + '\n');
};
30 changes: 30 additions & 0 deletions lib/cli/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var path = require('path'),
fs = require('fs');

/**
* returns help information for topc
*
* @param topic
* @param callback
*/
module.exports = function(topic, callback) {
if(topic == null) {
topic = 'about';
}
findHelpTopic(topic, callback);
};

function findHelpTopic(topic, callback) {
// filename format: help.topic.txt
var filepath = [topic];
filepath.push('txt');
filepath = filepath.join('.');

// full doc file path
var basepath = path.join(__dirname, '..', '..', 'doc', 'cli');
filepath = path.join(basepath, filepath);

// get help info
var data = fs.readFileSync(filepath, 'utf8');
callback(null, data);
}
9 changes: 9 additions & 0 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Command line commands.
*/
module.exports = {
argv: require('./argv'),
help: require('./help'),
version: require('./version'),
parse: require('./parse')
};
57 changes: 57 additions & 0 deletions lib/cli/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var woodchipper = require('../woodchipper');

var TIMEOUT = 100;

/**
* routes argv or stdin input and format to parser
*
* @param argv
* @param callback
*/
module.exports = function(argv, callback) {
// handle command arguments and piped data via stdin
if(validateArgs(argv)) {
routeToParse(argv._[0], argv, callback);
} else if(argv._.length <= 1) {
handleStdin(TIMEOUT, function (err, data) {
if(err) {
callback('too few arguments');
}
routeToParse(data, argv, callback);
});
} else {
callback('too many arguments');
}
};

function validateArgs(argv) {
return (argv._.length == 1);
}

function handleStdin(dur, callback) {
var stdin = process.openStdin();
var timeout = setTimeout(function() {
if(data) {
// data incoming, waiting for stdin end
return;
} else {
callback('timed out after ' + dur);
}
}, dur);

var data;
stdin.on('data', function(chunk) {
data = (!!data) ? data : '';
data += chunk;
});
stdin.on('end', function() {
clearTimeout(timeout);
callback(null, data);
});
}

function routeToParse(data, argv, callback) {
// --format or -f
argv.format = argv.format || argv.f;
woodchipper.parse(data, argv.format, callback);
}
11 changes: 11 additions & 0 deletions lib/cli/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var pjson = require('../../package.json');

/**
* outputs the version number
*
* @param argv
* @param callback
*/
module.exports = function(argv, callback) {
callback(null, pjson.version);
};
3 changes: 3 additions & 0 deletions lib/woodchipper/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
parse: require('./parse')
};
26 changes: 26 additions & 0 deletions lib/woodchipper/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var DEFAULT_PARSER = 'junit';

/**
* Routes to data to parser.
*
* @param data
* @param callback
*/
module.exports = function(data, format, callback) {
if(format == null) {
format = DEFAULT_PARSER;
}

findParser(format, data, callback);
};

function findParser(format, data, callback) {
// parser module format: ./parser/format.js
var module = './parser/' + format;
try {
var parser = require(module);
parser(data, callback);
} catch(err) {
callback('unknown format: ' + format);
}
}

0 comments on commit 0fb7c96

Please sign in to comment.