Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 2f77a60

Browse files
Merge pull request #593 from stephanebachelier/uglify-task-naming
support both uglify and uglifyjs in flow
2 parents 819d655 + 47128d0 commit 2f77a60

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

lib/flow.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,27 @@ var _ = require('lodash');
1414
// }
1515
//
1616
var Flow = module.exports = function (flowConfig) {
17-
this._steps = flowConfig.steps || {};
18-
this._post = flowConfig.post || {};
17+
this.setSteps(flowConfig.steps);
18+
this.setPost(flowConfig.post);
19+
};
20+
21+
Flow.formatStepName = function (step) {
22+
if (typeof step === 'string') {
23+
return /uglify/.test(step) ? 'uglify' : step;
24+
}
25+
26+
step.name = /uglify/.test(step.name) ? 'uglify' : step.name;
27+
28+
return step;
29+
};
30+
31+
Flow.formatSteps = function (steps) {
32+
var formattedSteps = {};
33+
_.forIn(steps, function (config, type) {
34+
formattedSteps[type] = config.map(Flow.formatStepName);
35+
});
36+
37+
return formattedSteps;
1938
};
2039

2140
//
@@ -29,8 +48,7 @@ Flow.prototype.steps = function (blockType) {
2948
// Set the steps for the flow
3049
//
3150
Flow.prototype.setSteps = function (steps) {
32-
// FIXME: Check format !!!
33-
this._steps = steps;
51+
this._steps = Flow.formatSteps(steps) || {};
3452
};
3553

3654
//
@@ -44,8 +62,7 @@ Flow.prototype.post = function (blockType) {
4462
// Set the post for the flow
4563
//
4664
Flow.prototype.setPost = function (post) {
47-
// FIXME: Check format !!!
48-
this._post = post;
65+
this._post = Flow.formatSteps(post) || {};
4966
};
5067

5168

test/test-flow.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var assert = require('assert');
33
var helpers = require('./helpers');
44
var Flow = require('../lib/flow.js');
55

6-
describe('ConfigWriter', function () {
6+
describe('Flow', function () {
77
before(helpers.directory('temp'));
88

99
it('should allow steps per block type', function () {
@@ -73,7 +73,7 @@ describe('ConfigWriter', function () {
7373
assert.deepEqual(flow.steps('js'), ['foo', 'bar']);
7474
});
7575

76-
it('should allow to set steps', function () {
76+
it('should allow to set post-processors', function () {
7777
var flow = new Flow({
7878
post: {
7979
html: ['bar']
@@ -85,4 +85,43 @@ describe('ConfigWriter', function () {
8585
assert.deepEqual(flow.post('js'), ['foo', 'bar']);
8686
});
8787

88+
it('should rename uglifyjs to uglify in steps', function () {
89+
var flow = new Flow({});
90+
flow.setSteps({
91+
js: ['uglifyjs']
92+
});
93+
94+
assert.deepEqual(flow.steps('js'), ['uglify']);
95+
});
96+
97+
it('should rename uglifyjs to uglify in steps given to contructor', function () {
98+
var flow = new Flow({
99+
steps: {
100+
js: ['uglifyjs']
101+
}
102+
});
103+
104+
assert.deepEqual(flow.steps('js'), ['uglify']);
105+
});
106+
107+
it('should rename uglifyjs to uglify in post-processors', function () {
108+
var flow = new Flow({});
109+
flow.setPost({
110+
js: ['uglifyjs']
111+
112+
});
113+
114+
assert.deepEqual(flow.post('js'), ['uglify']);
115+
});
116+
117+
it('should rename uglifyjs to uglify in post-processors given to contructor', function () {
118+
var flow = new Flow({
119+
post: {
120+
js: ['uglifyjs']
121+
}
122+
});
123+
124+
assert.deepEqual(flow.post('js'), ['uglify']);
125+
});
126+
88127
});

0 commit comments

Comments
 (0)