1 | /**
|
2 | * apeman task to measure coverage.
|
3 | * @memberof module:apeman-task-coverage/lib
|
4 | * @function define
|
5 | * @param {string} script - Script to run for coverage.
|
6 | * @param {options} [options] - Optional settings.
|
7 | * @param {string} [options.out="coverage"] - Output directory.
|
8 | * @returns {function} - Defined task function.
|
9 | */
|
10 |
|
11 | ;
|
12 |
|
13 | var argx = require('argx'),
|
14 | execcli = require('execcli'),
|
15 | objnest = require('objnest');
|
16 |
|
17 | /** @lends define */
|
18 | function define(script, options) {
|
19 | var args = argx(arguments);
|
20 | options = objnest.expand(args.pop('object') || {});
|
21 |
|
22 | var out = options.out || 'coverage';
|
23 |
|
24 | /**
|
25 | * Defined task.
|
26 | * @function task
|
27 | * @param {object} context - Apeman task context.
|
28 | * @param {function} callback - Callback when done.
|
29 | */
|
30 | return function task(context, callback) {
|
31 | var logger = context.logger,
|
32 | verbose = context.verbose;
|
33 |
|
34 | var cmdArgs = ['cover'].concat(script.split(' ')).concat({
|
35 | dir: out
|
36 | });
|
37 | execcli('istanbul', cmdArgs, {
|
38 | notfound: 'try `npm install istanbul -g`'
|
39 | }, callback);
|
40 | }
|
41 | }
|
42 |
|
43 | module.exports = define;
|