diff --git a/src/lib/package-lib.js b/src/lib/package-lib.js index 9eea50f2c..83f8bb25b 100644 --- a/src/lib/package-lib.js +++ b/src/lib/package-lib.js @@ -54,25 +54,6 @@ module.exports = (pathToProject, entry, baseEslintPath, options = {}) => { 'node_modules', ], }, - module: { - rules: [ - { - enforce: 'pre', - test: /\.js$/, - loader: 'eslint-loader', - exclude: /node_modules/, - options: { - baseConfig: baseEslintConfig, - useEslintrc: true, - ignore: !options.skipEslintIgnore, - - // pack the library regardless of the eslint result - failOnError: false, - failOnWarning: false, - }, - }, - ], - }, plugins: [ new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // Ignore all optional deps of moment.js ] diff --git a/src/lib/validate-declarative-schema.js b/src/lib/validate-declarative-schema.js index a2004e23d..b9112f9b4 100644 --- a/src/lib/validate-declarative-schema.js +++ b/src/lib/validate-declarative-schema.js @@ -117,11 +117,14 @@ const TaskSchema = joi.array().items( 'should define property "resolvedIf" as: function(contact, report) { ... }.' ) ), - events: joi.alternatives().conditional('events', { - is: joi.array().length(1), - then: joi.array().items(EventSchema('optional')).min(1).required(), - otherwise: joi.array().items(EventSchema('required')).unique('id').required(), - }), + events: joi.alternatives().try( + joi.function(), + joi.alternatives().conditional('events', { + is: joi.array().length(1), + then: joi.array().items(EventSchema('optional')).min(1), + otherwise: joi.array().items(EventSchema('required')).unique('id'), + }) + ).required(), priority: joi.alternatives().try( joi.object({ level: joi.string().valid('high', 'medium').optional(), diff --git a/src/nools/task-emitter.js b/src/nools/task-emitter.js index d6a2d9d2d..a3aae1d7d 100644 --- a/src/nools/task-emitter.js +++ b/src/nools/task-emitter.js @@ -90,8 +90,19 @@ function emitTasks(taskDefinition, Utils, Task, emit, c, r) { function emitForEvents(scheduledTaskIdx) { var i, dueDate = null, event, priority, task; - for (i = 0; i < taskDefinition.events.length; i++) { - event = taskDefinition.events[i]; + + var events; + if (typeof taskDefinition.events === 'function') { + events = taskDefinition.events(c, r); + if (!Array.isArray(events)) { + throw Error('events did not return an array'); + } + } else { + events = taskDefinition.events; + } + + for (i = 0; i < events.length; i++) { + event = events[i]; if (event.dueDate) { dueDate = event.dueDate(event, c, r, scheduledTaskIdx); diff --git a/test/lib/validate-declarative-schema.spec.js b/test/lib/validate-declarative-schema.spec.js index 68bdf35df..b5e4c9d1a 100644 --- a/test/lib/validate-declarative-schema.spec.js +++ b/test/lib/validate-declarative-schema.spec.js @@ -123,6 +123,13 @@ describe('validate-declarative-schema', () => { ]); }); + it('events can be function', () => { + const task = buildTaskWithAction('contact'); + task.events = () => []; + const actual = validate([task], TaskSchema); + expect(actual).to.be.empty; + }); + it('array.unique internal', () => { const schema = joi.array().items(joi.object({ event: joi.array().items(joi.object()).unique('id'),