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

Commit

Permalink
feat(uglifyjs): renamed flow to uglify for consistency
Browse files Browse the repository at this point in the history
fix #409
  • Loading branch information
stephanebachelier committed Feb 22, 2015
1 parent 4d1593a commit 7482614
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -54,7 +54,7 @@ grunt.registerTask('build', [
## The useminPrepare task

`useminPrepare` task updates the grunt configuration to apply a configured transformation flow to tagged files (i.e. blocks).
By default the transformation flow is composed of `concat` and `uglifyjs` for JS files, but it can be configured.
By default the transformation flow is composed of `concat` and `uglify` for JS files, but it can be configured.

### Blocks
Blocks are expressed as:
Expand Down Expand Up @@ -85,7 +85,7 @@ An example of this in completed form can be seen below:

The transformation flow is made of sequential steps: each of the steps transform the file, and useminPrepare will modify the configuration in order for the described steps to be correctly performed.

By default the flow is: `concat -> uglifyjs`.
By default the flow is: `concat -> uglify`.
Additionally to the flow, at the end, some postprocessors can be launched to further alter the configuration.

Let's have an example, using the default flow (we're just going to look at the steps), `app` for input dir, `dist` for output dir, and the following block:
Expand Down Expand Up @@ -186,7 +186,7 @@ The root directory from which your files will be resolved.
### flow

Type: 'object'
Default: `{ steps: { js: ['concat', 'uglifyjs'], css: ['concat', 'cssmin'] }, post: {} }`
Default: `{ steps: { js: ['concat', 'uglify'], css: ['concat', 'cssmin'] }, post: {} }`

This allow you to configure the workflow, either on a per-target basis, or for all the targets.
You can change the `steps` or the post-processors (`post`) separately.
Expand All @@ -202,7 +202,7 @@ useminPrepare: {
flow: {
html: {
steps: {
js: ['uglifyjs']
js: ['uglify']
},
post: {}
}
Expand All @@ -219,7 +219,7 @@ useminPrepare: {
options: {
flow: {
steps: {
js: ['uglifyjs']
js: ['uglify']
},
post: {}
}
Expand All @@ -235,7 +235,7 @@ useminPrepare: {
options: {
flow: {
steps: {
js: ['uglifyjs']
js: ['uglify']
},
post: {
js: [{
Expand All @@ -262,7 +262,7 @@ User-defined steps and post-processors must have 2 attributes:
* `name`: name of the `Gruntfile` attribute that holds the corresponding config
* `createConfig` which is a 2 arguments function ( a `context` and the treated `block`)

For an example of steps/post-processors, you can have a look at `concat` and `uglifyjs` in the `lib/config` directory of this repository.
For an example of steps/post-processors, you can have a look at `concat` and `uglify` in the `lib/config` directory of this repository.

##### `createConfig`

Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions lib/configwriter.js
Expand Up @@ -23,7 +23,7 @@ var deepMerge = function (origCfg, cfg) {
//
// flow is an array of strings that contains name of each steps, in order.
// Each of the steps is corresponding to a processor that will be used on the files
// enclosed in blocks (for example, concat, uglifyjs).
// enclosed in blocks (for example, concat, uglify).
// Note that a corresponding file implementing a dedicated writer needs to be present
// under the same name, in config directory.
//
Expand All @@ -32,11 +32,11 @@ var deepMerge = function (origCfg, cfg) {
//
// For example:
//
// var w = new ConfigWriter( ['concat', 'uglifyjs'], [], {input: 'app', staging: '.tmp', dest: 'dist'});
// var w = new ConfigWriter( ['concat', 'uglify'], [], {input: 'app', staging: '.tmp', dest: 'dist'});
//
// We'll:
// - have files config/concat.js and config/uglifyjs.js implementing each config writer
// - Use .tmp for the output of concat and input of uglifyjs
// - have files config/concat.js and config/uglify.js implementing each config writer
// - Use .tmp for the output of concat and input of uglify
// - Deliver for each block the requested file under dist directory
//
//
Expand All @@ -52,8 +52,8 @@ var ConfigWriter = module.exports = function (flow, dirs) {
this.destinations = {};

// We need to create all the needed config writers, given them their output directory
// E.g, if we do have the flow concat | uglifyjs, the output dir will be .tmp/concat and dist
// if the flow is concat | uglifyjs | foo, the dirs will be .tmp/concat, .tmp/uglifyjs, dist
// E.g, if we do have the flow concat | uglify, the output dir will be .tmp/concat and dist
// if the flow is concat | uglify | foo, the dirs will be .tmp/concat, .tmp/uglify, dist
flow.blockTypes().forEach(function (blockType) {
self.steps[blockType] = [];
self.postprocessors[blockType] = [];
Expand Down
2 changes: 1 addition & 1 deletion tasks/usemin.js
Expand Up @@ -10,7 +10,7 @@ var getFlowFromConfig = function (config, target) {
var Flow = require('../lib/flow');
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs'],
js: ['concat', 'uglify'],
css: ['concat', 'cssmin']
},
post: {}
Expand Down
22 changes: 11 additions & 11 deletions test/test-config-uglifyjs.js
@@ -1,6 +1,6 @@
'use strict';
var assert = require('assert');
var uglifyjsConfig = require('../lib/config/uglifyjs.js');
var uglifyConfig = require('../lib/config/uglify.js');
var path = require('path');

var block = {
Expand All @@ -20,22 +20,22 @@ var block = {
]
};

describe('Uglifyjs config write', function () {
describe('Uglify config write', function () {
it('should have a correct name', function () {
assert.equal(uglifyjsConfig.name, 'uglify');
assert.equal(uglifyConfig.name, 'uglify');
});

it('should use the input files correctly', function () {
var ctx = {
inDir: 'zzz',
inFiles: ['foo.js', 'bar.js', 'baz.js'],
outDir: 'tmp/uglifyjs',
outDir: 'tmp/uglify',
outFiles: []
};
var cfg = uglifyjsConfig.createConfig(ctx, block);
var cfg = uglifyConfig.createConfig(ctx, block);
assert.ok(cfg.files);
assert.equal(cfg.files.length, 3);
var dests = ['tmp/uglifyjs/foo.js', 'tmp/uglifyjs/bar.js', 'tmp/uglifyjs/baz.js'];
var dests = ['tmp/uglify/foo.js', 'tmp/uglify/bar.js', 'tmp/uglify/baz.js'];
var srcs = ['zzz/foo.js', 'zzz/bar.js', 'zzz/baz.js'];

cfg.files.forEach(function (files, idx) {
Expand All @@ -56,7 +56,7 @@ describe('Uglifyjs config write', function () {
outFiles: [],
last: true
};
var cfg = uglifyjsConfig.createConfig(ctx, block);
var cfg = uglifyConfig.createConfig(ctx, block);
assert.ok(cfg.files);
assert.equal(cfg.files.length, 1);
var files = cfg.files[0];
Expand All @@ -68,12 +68,12 @@ describe('Uglifyjs config write', function () {

// it('should allow for concatenation', function () {
// var requirejsConfig = {};
// var co = new uglifyjsConfig( 'tmp/uglifyjs', requirejsConfig );
// var co = new uglifyConfig( 'tmp/uglify', requirejsConfig );
// var ctx = { inFiles: ['foo.js', 'bar.js', 'baz.js'], outFiles: []};
// var cfg = co.createConfig(ctx, block);
// assert.ok(cfg['tmp/uglifyjs/foo.js']);
// assert.deepEqual(cfg['tmp/uglifyjs/scripts/site.js'], ['foo.js', 'bar.js', 'baz.js']);
// assert.deepEqual(ctx.outFiles, ['tmp/uglifyjs/scripts/site.js']);
// assert.ok(cfg['tmp/uglify/foo.js']);
// assert.deepEqual(cfg['tmp/uglify/scripts/site.js'], ['foo.js', 'bar.js', 'baz.js']);
// assert.deepEqual(ctx.outFiles, ['tmp/uglify/scripts/site.js']);
// });

});
22 changes: 11 additions & 11 deletions test/test-config-writer.js
Expand Up @@ -20,7 +20,7 @@ describe('ConfigWriter', function () {

var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs', copy]
js: ['concat', 'uglify', copy]
},
post: {}
});
Expand All @@ -47,7 +47,7 @@ describe('ConfigWriter', function () {
it('should output a set of config', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});
var file = helpers.createFile('foo', 'app', blocks);
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('ConfigWriter', function () {
it('should have a configurable destination directory', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('ConfigWriter', function () {
it('should have a configurable staging directory', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});

Expand Down Expand Up @@ -154,7 +154,7 @@ describe('ConfigWriter', function () {
it('should allow for single step flow', function () {
var flow = new Flow({
steps: {
js: ['uglifyjs']
js: ['uglify']
}
});

Expand All @@ -181,7 +181,7 @@ describe('ConfigWriter', function () {
it('should allow for a configuration of the flow\'s step order', function () {
var flow = new Flow({
steps: {
js: ['uglifyjs', 'concat']
js: ['uglify', 'concat']
}
});

Expand Down Expand Up @@ -222,7 +222,7 @@ describe('ConfigWriter', function () {
it('should augment the furnished config', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});
var config = {
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('ConfigWriter', function () {
it('should deduplicate blocks', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});
var doubleBlocks = [blocks[0], blocks[0]];
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('ConfigWriter', function () {
it('should deduplicate blocks across files', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});
var file = helpers.createFile('foo', 'app', blocks);
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('ConfigWriter', function () {
it('should throw with conflicting blocks', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs']
js: ['concat', 'uglify']
}
});
var conflictBlock = {
Expand Down Expand Up @@ -386,7 +386,7 @@ describe('ConfigWriter', function () {
it('should return all writers if called without block type', function () {
var flow = new Flow({
steps: {
js: ['concat', 'uglifyjs'],
js: ['concat', 'uglify'],
css: ['concat']
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/test-usemin.js
Expand Up @@ -530,7 +530,7 @@ describe('useminPrepare', function () {
options: {
flow: {
steps: {
js: ['uglifyjs']
js: ['uglify']
},
post: {}
}
Expand Down Expand Up @@ -562,7 +562,7 @@ describe('useminPrepare', function () {
flow: {
html: {
steps: {
js: ['uglifyjs']
js: ['uglify']
},
post: {}
}
Expand Down

0 comments on commit 7482614

Please sign in to comment.