From 06c62027167de741020aa478067531c296d49fbe Mon Sep 17 00:00:00 2001 From: Taka Okunishi Date: Sat, 10 Jun 2017 14:42:01 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=BF=E3=82=B9=E3=82=AF=E3=82=92=E5=AE=9F=E8=A1=8C=E3=81=97?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=A8=E3=81=97=E3=81=9F=E3=82=89=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E3=82=92=E5=87=BA=E3=81=97=E3=81=A6=E3=81=BB=E3=81=97?= =?UTF-8?q?=E3=81=84=20realglobe-Inc/pon#13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cli.js | 12 +++--------- lib/runnable.js | 28 ++++++++++++++++++++++++++++ misc/mock/mock-project-01/Ponfile.js | 5 ++++- test/cli_test.js | 10 ++++++++++ 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 lib/runnable.js 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 */