Skip to content

Commit

Permalink
start adding coverage/custom tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Mar 10, 2015
1 parent 19abde7 commit fbffe84
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ tmp
TODO.md
vendor
staging
coverage
7 changes: 6 additions & 1 deletion .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Handlebars and Lo-Dash both allow **dot notation** to be used for referencing he
This can be used as a way of working around potential naming conflicts.


## Helpers
Currently {%= list('./lib/') %}

## API
{%= apidocs("lib/*.js") %}

Expand All @@ -76,12 +79,14 @@ This can be used as a way of working around potential naming conflicts.

{%= include("footer") %}

{%= reflinks() %}
{%%= reflinks() %}


[assemble]: https://github.com/assemble/assemble
[verb]: https://github.com/assemble/verb
[template]: https://github.com/jonschlinkert/template
[word-wrap]: https://github.com/jonschlinkert/word-wrap
[helper-concat]: https://github.com/helpers/helper-concat
[path]: https://nodejs.org/api/path.html

<!-- deps:helper-reflinks -->
137 changes: 137 additions & 0 deletions verbfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'use strict';

var fs = require('fs');
var path = require('path');
// var gutil = require('gulp-util');
// var istanbul = require('gulp-istanbul');
var exportFiles = require('export-files');
// var jshint = require('gulp-jshint');
// var mocha = require('gulp-mocha');
// var through = require('through2');
var strip = require('strip-ansi');
var code = require('code-context');
var mdu = require('markdown-utils');
var relative = require('relative');
var verb = require('verb');

// verb.option('debugEngine', true);
// verb.data({docsDiff: {}, testDiff: {}});

// verb.task('lint', function () {
// return verb.src(['index.js', 'lib/*.js'])
// .pipe(jshint('.jshintrc'))
// .pipe(jshint.reporter('jshint-stylish'));
// });

// verb.task('test', ['lint'], function (cb) {
// verb.src(['index.js', 'lib/*.js'])
// .pipe(istanbul({includeUntested: true}))
// .pipe(istanbul.hookRequire())
// .on('finish', function () {
// verb.src(['test/*.js'])
// .pipe(mocha())
// .on('error', gutil.log)
// .pipe(istanbul.writeReports())
// .on('end', function () {
// cb();
// })
// });
// });

verb.task('readme', function() {
// verb.partial('./coverage/*.txt', [coverage]);
return verb.src('.verb.md').pipe(verb.dest('.'));
});


/**
* Code coverage loader
*/

// function coverage(file) {
// var tmpl = file['summary.txt'];
// if (!tmpl) return '';

// tmpl.content = strip(tmpl.content);
// var lines = tmpl.content.split('\n');

// var arr = lines.reduce(function (acc, line, i) {
// if (i !== 0 && i !== lines.length - 2 && i !== lines.length - 4) {
// acc.push('| ' + line);
// }
// return acc;
// }, []);

// // remove the last line of the table
// arr.pop();
// tmpl.content = arr.join('\n');
// return file;
// }

// function foo(options) {
// return through.obj(function (file, enc, cb) {
// // console.log(file.contents.toString())
// this.push(file);
// cb();
// });
// };

verb.helper('list', function (dir) {
var res = exportFiles(dir).reduce(function (acc, fp) {
acc[fp] = require(path.resolve(dir, fp));
return acc;
}, {});
return generate(res);
});


/**
* TODO: move this out into a plugin
*/

function context(str) {
return code(str).reduce(function (acc, ele) {
if (ele && ele.type !== 'comment') {
acc[ele.name] = ele.begin;
}
return acc;
}, {});
}

function generate(obj) {
var keys = Object.keys(obj);
var len = keys.length;
var i = 0;
var res = '\n';
var count = len;

while (len--) {
var fp = keys[i++];
var ctx = context(fs.readFileSync(fp, 'utf8'));
var name = path.basename(fp, path.extname(fp));
res += '\n+ ' + mdu.strong(mdu.link(name, relative(fp))) + '\n';

var list = obj[fp];
var items = Object.keys(list);

// todo: move this to a new function
res += listItems(ctx, items);
}

function listItems(ctx, items) {
return items.map(function (method) {
var line = ctx[method];
var link = method;
if (line) {
link = mdu.link(method, relative(fp) + '#L' + line);
}
return ' - ' + link;
}).sort().join('\n');
}

var result = count + ' helpers organized into the following categories:' + res;
return result.replace(/^\s*|\s*$/g, '');
}


verb.task('default', ['readme']);

0 comments on commit fbffe84

Please sign in to comment.