From 6aaac874481916ae0dcd80c320bcb3a8c7cc55f9 Mon Sep 17 00:00:00 2001 From: Javier Carrillo Date: Mon, 8 Jun 2015 12:20:37 +0200 Subject: [PATCH 1/2] enhance: adds not found warning --- index.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 891c4fd..0a49df9 100644 --- a/index.js +++ b/index.js @@ -29,11 +29,36 @@ var repl = readline.createInterface({ repl.on('line', function onLine(line){ line = line.trim(); if(!line){ return repl.prompt(); } - var runner = gulp.parallel || gulp.start; - var result = runner.apply(gulp, line.split(/[ ]+/)); - if(typeof result === 'function'){ // gulp#4.0 - result(); + + var tasks; + if(gulp._registry){ + tasks = gulp._registry && gulp._registry._tasks; + } else { tasks = gulp.tasks; } + + var notFound = []; + line = line.split(/[ ]+/).filter(function(name){ + if(tasks && !tasks[name]){ + notFound.push(name); + } else { return true; } + }); + + if(notFound.length){ + var plural = notFound.length > 1; + console.log( + ' Warning: `%s` task%s %s undefined', + notFound.join(', '), + plural ? 's' : '', + plural ? 'are' : 'is' + ); + + if(!line.length){ return repl.prompt(); } } + + var runner = gulp.parallel || gulp.start; + var result = runner.apply(gulp, line); + + // gulp#4.0 + if(typeof result === 'function'){ result(); } }); exports = module.exports = repl; From a5179802f6deaf695b2253b4fe40a831e4768922 Mon Sep 17 00:00:00 2001 From: Javier Carrillo Date: Mon, 8 Jun 2015 12:21:27 +0200 Subject: [PATCH 2/2] test: adds notFound test --- test/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index c8cf0f8..c713eb4 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -require('should'); +var should = require('should'); describe('gulp-repl', function(){ var gulp = require('gulp'); @@ -17,4 +17,12 @@ describe('gulp-repl', function(){ gulp.task('two', function(cb){ two = true; done(); cb(); }); repl.emit('line', 'one two'); }); + + it('undefined tasks should not run', function(){ + gulp.task('one', function(){}); + var tasks = gulp.tasks || gulp._registry._tasks; + should.exist(tasks); + + repl.emit('line', 'whatever'); + }); });