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

Commit

Permalink
Merge pull request #593 from stephanebachelier/uglify-task-naming
Browse files Browse the repository at this point in the history
support both uglify and uglifyjs in flow
  • Loading branch information
stephanebachelier committed Aug 22, 2015
2 parents 819d655 + 47128d0 commit 2f77a60
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
29 changes: 23 additions & 6 deletions lib/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,27 @@ var _ = require('lodash');
// }
//
var Flow = module.exports = function (flowConfig) {
this._steps = flowConfig.steps || {};
this._post = flowConfig.post || {};
this.setSteps(flowConfig.steps);
this.setPost(flowConfig.post);
};

Flow.formatStepName = function (step) {
if (typeof step === 'string') {
return /uglify/.test(step) ? 'uglify' : step;
}

step.name = /uglify/.test(step.name) ? 'uglify' : step.name;

return step;
};

Flow.formatSteps = function (steps) {
var formattedSteps = {};
_.forIn(steps, function (config, type) {
formattedSteps[type] = config.map(Flow.formatStepName);
});

return formattedSteps;
};

//
Expand All @@ -29,8 +48,7 @@ Flow.prototype.steps = function (blockType) {
// Set the steps for the flow
//
Flow.prototype.setSteps = function (steps) {
// FIXME: Check format !!!
this._steps = steps;
this._steps = Flow.formatSteps(steps) || {};
};

//
Expand All @@ -44,8 +62,7 @@ Flow.prototype.post = function (blockType) {
// Set the post for the flow
//
Flow.prototype.setPost = function (post) {
// FIXME: Check format !!!
this._post = post;
this._post = Flow.formatSteps(post) || {};
};


Expand Down
43 changes: 41 additions & 2 deletions test/test-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var assert = require('assert');
var helpers = require('./helpers');
var Flow = require('../lib/flow.js');

describe('ConfigWriter', function () {
describe('Flow', function () {
before(helpers.directory('temp'));

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

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

it('should rename uglifyjs to uglify in steps', function () {
var flow = new Flow({});
flow.setSteps({
js: ['uglifyjs']
});

assert.deepEqual(flow.steps('js'), ['uglify']);
});

it('should rename uglifyjs to uglify in steps given to contructor', function () {
var flow = new Flow({
steps: {
js: ['uglifyjs']
}
});

assert.deepEqual(flow.steps('js'), ['uglify']);
});

it('should rename uglifyjs to uglify in post-processors', function () {
var flow = new Flow({});
flow.setPost({
js: ['uglifyjs']

});

assert.deepEqual(flow.post('js'), ['uglify']);
});

it('should rename uglifyjs to uglify in post-processors given to contructor', function () {
var flow = new Flow({
post: {
js: ['uglifyjs']
}
});

assert.deepEqual(flow.post('js'), ['uglify']);
});

});

0 comments on commit 2f77a60

Please sign in to comment.