Skip to content

Commit

Permalink
Fix: Allow gulpfiles specified by .gulp.* to register a loader (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored and phated committed Mar 13, 2019
1 parent 9a8a136 commit be9d25a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
21 changes: 21 additions & 0 deletions test/config-flags-gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
});

});

6 changes: 6 additions & 0 deletions test/fixtures/config/flags/gulpfile/autoload/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"flags": {
"silent": true,
"gulpfile": "other_folder/gulpfile-exports.babel.js"
}
}
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit be9d25a

Please sign in to comment.