Skip to content

Commit

Permalink
Update: Support new alpha of gulp 4 to handle new undertaker tree ret…
Browse files Browse the repository at this point in the history
…urn value
  • Loading branch information
phated committed Dec 21, 2017
1 parent 410c09b commit 571a7c9
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/versioned/^4.0.0-alpha.1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ var tildify = require('tildify');
var exit = require('../../shared/exit');

var logTasks = require('../../shared/log/tasks');
var logEvents = require('./log/events');
var logSyncTask = require('./log/syncTask');
var logTasksSimple = require('./log/tasksSimple');
var logEvents = require('../^4.0.0-alpha.2/log/events');
var logSyncTask = require('../^4.0.0-alpha.2/log/syncTask');
var logTasksSimple = require('../^4.0.0-alpha.2/log/tasksSimple');

function execute(opts, env) {

Expand Down
File renamed without changes.
79 changes: 79 additions & 0 deletions lib/versioned/^4.0.0-alpha.2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict';

var fs = require('fs');

var log = require('gulplog');
var chalk = require('chalk');
var stdout = require('mute-stdout');
var tildify = require('tildify');

var exit = require('../../shared/exit');

var logTasks = require('../../shared/log/tasks');
var logEvents = require('./log/events');
var logSyncTask = require('./log/syncTask');
var logTasksSimple = require('./log/tasksSimple');

function execute(opts, env) {

var tasks = opts._;
var toRun = tasks.length ? tasks : ['default'];

if (opts.tasksSimple || opts.tasks || opts.tasksJson) {
// Mute stdout if we are listing tasks
stdout.mute();
}

var gulpInst = require(env.modulePath);
logEvents(gulpInst);
logSyncTask(gulpInst);

// This is what actually loads up the gulpfile
require(env.configPath);

// Always unmute stdout after gulpfile is required
stdout.unmute();

process.nextTick(function() {
var tree;

if (opts.tasksSimple) {
tree = gulpInst.tree();
return logTasksSimple(tree.nodes);
}
if (opts.tasks) {
tree = gulpInst.tree({ deep: true });
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));

return logTasks(tree, function(task) {
return gulpInst.task(task).description;
});
}
if (opts.tasksJson) {
tree = gulpInst.tree({ deep: true });
tree.label = 'Tasks for ' + tildify(env.configPath);

var output = JSON.stringify(tree);

if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
return console.log(output);
} else {
return fs.writeFileSync(opts.tasksJson, output, 'utf-8');
}
}
try {
log.info('Using gulpfile', chalk.magenta(tildify(env.configPath)));
gulpInst.parallel(toRun)(function(err) {
if (err) {
exit(1);
}
});
} catch (err) {
log.error(chalk.red(err.message));
log.error('To list available tasks, try running: gulp --tasks');
exit(1);
}
});
}

module.exports = execute;
File renamed without changes.
2 changes: 1 addition & 1 deletion test/expected/flags-tasks-json.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]
{"label":"Tasks for {{path}}","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]}
9 changes: 7 additions & 2 deletions test/flags-tasks-json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var fs = require('fs-extra');
var path = require('path');
var tildify = require('tildify');
var lab = exports.lab = require('lab').script();
var code = require('code');

Expand All @@ -9,11 +11,14 @@ var output = require('./expected/flags-tasks-json.json');

lab.experiment('flag: --tasks-json', function() {

var outputString = JSON.stringify(output).replace(/{{path}}/, tildify(path.join(__dirname, 'fixtures/gulpfile.js')));
var expected = JSON.parse(outputString);

lab.test('prints the task list with no args', function(done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks-json --gulpfile "./test/fixtures/gulpfile.js" ', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/').split('\n');
var parsedJson = JSON.parse(stdout[1]);
code.expect(parsedJson).to.deep.equal(output);
code.expect(parsedJson).to.deep.equal(expected);
done(err);
});
});
Expand All @@ -27,7 +32,7 @@ lab.experiment('flag: --tasks-json', function() {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks-json "../output/tasks.json" --gulpfile "./test/fixtures/gulpfile.js" ', function(err) {
var file = fs.readFileSync(__dirname + '/output/tasks.json', 'utf8');
var parsedJson = JSON.parse(file);
code.expect(parsedJson).to.deep.equal(output);
code.expect(parsedJson).to.deep.equal(expected);
fs.removeSync(__dirname + '/output/');
done(err);
});
Expand Down

0 comments on commit 571a7c9

Please sign in to comment.