From be9d25a98429e0760973147bec22e5126245a4f4 Mon Sep 17 00:00:00 2001 From: sttk Date: Thu, 14 Mar 2019 00:23:55 +0900 Subject: [PATCH] Fix: Allow gulpfiles specified by .gulp.* to register a loader (fixes #181) --- index.js | 21 ++++++++++++------- test/config-flags-gulpfile.js | 21 +++++++++++++++++++ .../config/flags/gulpfile/autoload/.gulp.json | 6 ++++++ .../other_folder/gulpfile-exports.babel.js | 8 +++++++ 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/config/flags/gulpfile/autoload/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload/other_folder/gulpfile-exports.babel.js diff --git a/index.js b/index.js index d397f49d..cf884aef 100644 --- a/index.js +++ b/index.js @@ -85,23 +85,29 @@ cli.on('respawn', function(flags, child) { log.info('Respawned to PID:', pid); }); + function run() { - cli.launch({ + cli.prepare({ cwd: opts.cwd, configPath: opts.gulpfile, require: opts.require, completion: opts.completion, - }, handleArguments); + }, function(env) { + + var cfgLoadOrder = ['home', 'cwd']; + var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); + opts = mergeConfigToCliFlags(opts, cfg); + env = mergeConfigToEnvFlags(env, cfg); + env.configProps = cfg; + + cli.execute(env, handleArguments); + }); } module.exports = run; // The actual logic function handleArguments(env) { - var cfgLoadOrder = ['home', 'cwd']; - var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); - opts = mergeConfigToCliFlags(opts, cfg); - env = mergeConfigToEnvFlags(env, cfg); // This translates the --continue flag in gulp // To the settle env variable for undertaker @@ -178,5 +184,6 @@ function handleArguments(env) { } // Load and execute the CLI version - require(path.join(__dirname, '/lib/versioned/', range, '/'))(opts, env, cfg); + var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); + require(versionedDir)(opts, env, env.configProps); } diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 792db81e..6f6af20b 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -6,6 +6,7 @@ var path = require('path'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var headLines = require('gulp-test-tools').headLines; +var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); describe('config: flags.gulpfile', function() { @@ -88,5 +89,25 @@ describe('config: flags.gulpfile', function() { } }); + it('Should autoload a module for loading a specified gulpfile', function(done) { + this.timeout(0); + + runner + .chdir('flags/gulpfile/autoload') + .gulp('dist') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual( + 'Requiring external module babel-register\n' + + 'clean!\n' + + 'build!\n' + + ''); + done(err); + } + }); + }); diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json new file mode 100644 index 00000000..fba4be3c --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -0,0 +1,6 @@ +{ + "flags": { + "silent": true, + "gulpfile": "other_folder/gulpfile-exports.babel.js" + } +} diff --git a/test/fixtures/config/flags/gulpfile/autoload/other_folder/gulpfile-exports.babel.js b/test/fixtures/config/flags/gulpfile/autoload/other_folder/gulpfile-exports.babel.js new file mode 100644 index 00000000..08520ff6 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload/other_folder/gulpfile-exports.babel.js @@ -0,0 +1,8 @@ +'use strict'; + +import gulp from 'gulp'; + +export function clean(done) { console.log('clean!'); done(); }; +export function build(done) { console.log('build!'); done(); }; +export const string = 'no function'; +export const dist = gulp.series(clean, build);