diff --git a/lib/cli.js b/lib/cli.js index a3af414..0c918c4 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -6,7 +6,7 @@ const co = require('co') const argx = require('argx') -const ponfile = require('ponfile') +const runnable = require('./runnable') /** @lends cli */ function cli (name, options) { @@ -18,7 +18,7 @@ function cli (name, options) { list = false } = options return co(function * () { - let runner = ponfile(cwd) + let runner = runnable(cwd) if (list) { let pattern = typeof list === 'string' ? list : null return cli.list(runner.tasks, { pattern }) @@ -26,13 +26,7 @@ function cli (name, options) { if (names && names.length > 0) { let results = [] for (let name of names) { - let result = yield Promise.resolve(runner.run(name)).then((result) => { - let isEmpty = Object.keys(result).length === 0 - if (isEmpty) { - console.warn(`No task found for name: "${name}"`) - } - return result - }) + let result = yield Promise.resolve(runner.run(name)) results.push(result) } return results diff --git a/lib/runnable.js b/lib/runnable.js new file mode 100644 index 0000000..56c252d --- /dev/null +++ b/lib/runnable.js @@ -0,0 +1,28 @@ +/** + * Define CLI Runner + * @function runnable + * @param {string} cwd - Working directory + * @returns {CLIRunner} Runner instance + */ +'use strict' +const { Ponfile } = require('ponfile') + +/** + * Runner implementation for CLI + */ +class CLIRunner extends Ponfile { + run (...patterns) { + return Promise.resolve( + super.run(...arguments) + ).then((result) => { + let isEmpty = Object.keys(result).length === 0 + if (isEmpty) { + let specified = patterns.length > 1 ? patterns : patterns[ 0 ] + console.warn(`No task found for: ${JSON.stringify(specified)}`) + } + return result + }) + } +} + +module.exports = (cwd) => new CLIRunner(cwd) diff --git a/misc/mock/mock-project-01/Ponfile.js b/misc/mock/mock-project-01/Ponfile.js index 59db44b..526d559 100644 --- a/misc/mock/mock-project-01/Ponfile.js +++ b/misc/mock/mock-project-01/Ponfile.js @@ -12,6 +12,9 @@ module.exports = ponRunner({ }, b () { console.log('This is B') - } + }, + + invalid01: [ '__invalid_pointer_01__', () => {} ], + invalid02: [ '__invalid_pointer_02__' ] }).bind() diff --git a/test/cli_test.js b/test/cli_test.js index 3cd1811..73dfc1a 100644 --- a/test/cli_test.js +++ b/test/cli_test.js @@ -49,6 +49,16 @@ describe('cli', function () { list: true }) })) + + // https://github.com/realglobe-Inc/pon/issues/13 + it('Warning with not existing task', () => co(function * () { + yield cli('invalid01', { + cwd: `${__dirname}/../misc/mock/mock-project-01` + }) + yield cli('invalid02', { + cwd: `${__dirname}/../misc/mock/mock-project-01` + }) + })) }) /* global describe, before, after, it */