Skip to content

Commit 4f75f10

Browse files
erikkempermanphated
authored andcommitted
New: Add flag & config option for running tasks in series (closes #93)
1 parent 9df91cc commit 4f75f10

File tree

17 files changed

+191
-10
lines changed

17 files changed

+191
-10
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Supported configurations properties:
111111
| flags.tasksDepth | Set default depth of task dependency tree. |
112112
| flags.gulpfile | Set a default gulpfile |
113113
| flags.silent | Silence logging by default |
114+
| flags.series | Run tasks given on the CLI in series (the default is parallel) |
114115

115116
## Flags
116117

@@ -207,6 +208,11 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp
207208
<td></td>
208209
<td>Continue execution of tasks upon failure.</td>
209210
</tr>
211+
<tr>
212+
<td>--series</td>
213+
<td></td>
214+
<td>Run tasks given on the CLI in series (the default is parallel).</td>
215+
</tr>
210216
<tr>
211217
<td>--log-level</td>
212218
<td>-L</td>

lib/shared/cliOptions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ module.exports = {
9999
desc: ansi.gray(
100100
'Continue execution of tasks upon failure.'),
101101
},
102+
series: {
103+
type: 'boolean',
104+
desc: ansi.gray(
105+
'Run tasks given on the CLI in series (the default is parallel).'),
106+
},
102107
'log-level': {
103108
alias: 'L',
104109
// Type isn't needed because count acts as a boolean

lib/shared/config/cli-flags.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var copyProps = require('copy-props');
55
var fromTo = {
66
'flags.silent': 'silent',
77
'flags.continue': 'continue',
8+
'flags.series': 'series',
89
'flags.logLevel': 'logLevel',
910
'flags.compactTasks': 'compactTasks',
1011
'flags.tasksDepth': 'tasksDepth',

lib/versioned/^4.0.0-alpha.1/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function execute(opts, env, config) {
7474
}
7575
try {
7676
log.info('Using gulpfile', ansi.magenta(tildify(env.configPath)));
77-
gulpInst.parallel(toRun)(function(err) {
77+
var runMethod = opts.series ? 'series' : 'parallel';
78+
gulpInst[runMethod](toRun)(function(err) {
7879
if (err) {
7980
exit(1);
8081
}

lib/versioned/^4.0.0-alpha.2/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function execute(opts, env, config) {
7474
}
7575
try {
7676
log.info('Using gulpfile', ansi.magenta(tildify(env.configPath)));
77-
gulpInst.parallel(toRun)(function(err) {
77+
var runMethod = opts.series ? 'series' : 'parallel';
78+
gulpInst[runMethod](toRun)(function(err) {
7879
if (err) {
7980
exit(1);
8081
}

lib/versioned/^4.0.0/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function execute(opts, env, config) {
7474
}
7575
try {
7676
log.info('Using gulpfile', ansi.magenta(tildify(env.configPath)));
77-
gulpInst.parallel(toRun)(function(err) {
77+
var runMethod = opts.series ? 'series' : 'parallel';
78+
gulpInst[runMethod](toRun)(function(err) {
7879
if (err) {
7980
exit(1);
8081
}

test/config-flags-series.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
var expect = require('expect');
4+
var path = require('path');
5+
6+
var skipLines = require('gulp-test-tools').skipLines;
7+
var eraseTime = require('gulp-test-tools').eraseTime;
8+
var eraseLapse = require('gulp-test-tools').eraseLapse;
9+
var runner = require('gulp-test-tools').gulpRunner;
10+
11+
var fixturesDir = path.join(__dirname, 'fixtures/config');
12+
var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir);
13+
14+
describe('config: flags.series', function() {
15+
16+
it('Should run in series if `flags.series` is true in .gulp.*',
17+
function(done) {
18+
runner
19+
.chdir('flags/series/t')
20+
.gulp('task1 task2')
21+
.run(cb);
22+
23+
function cb(err, stdout, stderr) {
24+
expect(err).toEqual(null);
25+
expect(stderr).toEqual('');
26+
27+
stdout = eraseLapse(eraseTime(skipLines(stdout, 1)));
28+
expect(stdout).toEqual(
29+
'Starting \'task1\'...\n' +
30+
'Finished \'task1\' after ?\n' +
31+
'Starting \'task2\'...\n' +
32+
'Finished \'task2\' after ?\n' +
33+
''
34+
);
35+
done();
36+
}
37+
});
38+
39+
it('Should run in parallel if `flags.series` is false in .gulp.*',
40+
function(done) {
41+
runner
42+
.chdir('flags/series/f')
43+
.gulp('task1 task2')
44+
.run(cb);
45+
46+
function cb(err, stdout, stderr) {
47+
expect(err).toEqual(null);
48+
expect(stderr).toEqual('');
49+
50+
stdout = eraseLapse(eraseTime(skipLines(stdout, 1)));
51+
expect(stdout).toEqual(
52+
'Starting \'task1\'...\n' +
53+
'Starting \'task2\'...\n' +
54+
'Finished \'task2\' after ?\n' +
55+
'Finished \'task1\' after ?\n' +
56+
''
57+
);
58+
done();
59+
}
60+
});
61+
62+
});

test/expected/flags-help.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Options:
3131
colors, even when color support is detected. [boolean]
3232
--silent, -S Suppress all gulp logging. [boolean]
3333
--continue Continue execution of tasks upon failure. [boolean]
34+
--series Run tasks given on the CLI in series (the default is
35+
parallel). [boolean]
3436
--log-level, -L Set the loglevel. -L for least verbose and -LLLL for
3537
most verbose. -LLL is default. [count]
3638

test/expected/flags-tasks-json.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]}
1+
{"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"test5","nodes":[],"type":"task"},{"label":"test6","nodes":[],"type":"task"},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]}

test/expected/flags-tasks-simple.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ test1
22
test2
33
test3
44
test4
5+
test5
6+
test6
57
default

0 commit comments

Comments
 (0)