1 | const co = require('co');
|
2 | const loader = require('./loader');
|
3 | const is = require('is_js');
|
4 |
|
5 | /**
|
6 | * Run a report from a path or function
|
7 | *
|
8 | * @param {String | Function} report
|
9 | * - fully qualified url to bundled module
|
10 | * - file path to module (absolute or relative)
|
11 | * - report function (ordinary or yieldable)
|
12 | * @param {*} [parameters = {}]
|
13 | */
|
14 | const run = co.wrap(function * (report, parameters) {
|
15 | if (!report) throw new TypeError('report: must be defined');
|
16 | parameters = parameters || {};
|
17 | if (is.string(report)) report = yield loader.load(report);
|
18 | if(!is.function(report)) throw new TypeError('report: must be a Function');
|
19 | return report(parameters);
|
20 | });
|
21 | module.exports = run;
|