From 393242561f5d78c3b01c5487b110724c3bfcadd9 Mon Sep 17 00:00:00 2001 From: Joseph Spencer Date: Tue, 12 Nov 2013 17:27:27 -0700 Subject: [PATCH 1/2] Replacing an invalid return statement with a valid exit code. --- bin/gulp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gulp.js b/bin/gulp.js index 2c3449e4a..3e210a2c6 100755 --- a/bin/gulp.js +++ b/bin/gulp.js @@ -14,7 +14,7 @@ var cliGulp = require('../'); if (!gulpFile) { cliGulp.log(chalk.red('No Gulpfile found')); - return; + process.exit(1); } // find the local gulp @@ -86,4 +86,4 @@ function getGulpFile(baseDir) { return gulpFiles.concat(Gulpfiles) .filter(fs.existsSync)[0]; -} \ No newline at end of file +} From 36de59f29868238b0e6b58752c59a98a32da5884 Mon Sep 17 00:00:00 2001 From: Joseph Spencer Date: Tue, 12 Nov 2013 18:03:45 -0700 Subject: [PATCH 2/2] gulp may be run anywhere within a project. --- bin/gulp.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/bin/gulp.js b/bin/gulp.js index 3e210a2c6..95b3e4a62 100755 --- a/bin/gulp.js +++ b/bin/gulp.js @@ -8,12 +8,13 @@ var chalk = require('chalk'); var resolve = require('resolve'); var tasks = argv._; -var gulpFile = getGulpFile(process.cwd()); +var initialCwd = process.cwd(); +var gulpFile = getGulpFileAndChangeCwd(initialCwd); var cliPkg = require('../package.json'); var cliGulp = require('../'); if (!gulpFile) { - cliGulp.log(chalk.red('No Gulpfile found')); + cliGulp.log(chalk.red('No Gulpfile found in any parent directory starting at: '+initialCwd)); process.exit(1); } @@ -74,16 +75,29 @@ function loadGulpFile(localGulp, gulpFile, tasks){ return theGulpfile; } -function getGulpFile(baseDir) { - var extensions = Object.keys(require.extensions); - var Gulpfiles = extensions.map(function(ext){ - return path.join(baseDir, "Gulpfile" + ext); - }); - - var gulpFiles = extensions.map(function(ext){ - return path.join(baseDir, "gulpfile" + ext); - }); - - return gulpFiles.concat(Gulpfiles) - .filter(fs.existsSync)[0]; +function getGulpFileAndChangeCwd(baseDir) { + var processed={}; + var proposedPath; + var gulpFile; + + while(!(baseDir in processed)){ + processed[baseDir]=1; + + proposedPath = path.resolve(baseDir, "Gulpfile.js"); + if(fs.existsSync(proposedPath)){ + gulpFile=proposedPath; + } else { + proposedPath = path.resolve(baseDir, "gulpfile.js"); + if(fs.existsSync(proposedPath)){ + gulpFile=proposedPath; + } + } + + if(gulpFile){ + process.chdir(baseDir); + return gulpFile; + } + baseDir = path.resolve(baseDir, '..'); + } + return null; }