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

Commit 0c8b687

Browse files
switch flow to merge steps
1 parent ae0d10f commit 0c8b687

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

tasks/usemin.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ var getFlowFromConfig = function (config, target) {
1515
},
1616
post: {}
1717
});
18+
1819
if (config.options && config.options.flow) {
19-
if (config.options.flow[target]) {
20-
flow.setSteps(config.options.flow[target].steps);
21-
flow.setPost(config.options.flow[target].post);
22-
} else {
23-
flow.setSteps(config.options.flow.steps);
24-
flow.setPost(config.options.flow.post);
25-
}
20+
var flowConfig = config.options.flow[target] ? config.options.flow[target] : config.options.flow;
21+
flow.mergeSteps(flowConfig.steps);
22+
flow.setPost(flowConfig.post);
2623
}
2724
return flow;
2825
};

test/test-usemin-prepare.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,19 @@ describe('useminPrepare', function () {
235235

236236
var uglify = grunt.config('uglify');
237237
var concat = grunt.config('concat');
238+
var cssmin = grunt.config('cssmin');
238239

239-
assert.equal(concat, null);
240-
assert.ok(uglify);
240+
assert.ok(concat);
241+
assert.equal(concat.generated.files.length, 1);
242+
assert.equal(concat.generated.files[0].dest, path.normalize('.tmp/concat/styles/main.min.css'));
241243

244+
assert.ok(uglify);
242245
assert.equal(uglify.generated.files.length, 1);
243-
var files = uglify.generated.files[0];
246+
assert.equal(uglify.generated.files[0].dest, path.normalize('dist/scripts/plugins.js'));
244247

245-
assert.equal(files.dest, path.normalize('dist/scripts/plugins.js'));
248+
assert.ok(cssmin);
249+
assert.equal(cssmin.generated.files.length, 1);
250+
assert.equal(cssmin.generated.files[0].dest, path.normalize('dist/styles/main.min.css'));
246251

247252
});
248253

@@ -267,13 +272,53 @@ describe('useminPrepare', function () {
267272

268273
var uglify = grunt.config('uglify');
269274
var concat = grunt.config('concat');
275+
var cssmin = grunt.config('cssmin');
276+
277+
assert.ok(concat);
278+
assert.equal(concat.generated.files.length, 1);
279+
assert.equal(concat.generated.files[0].dest, path.normalize('.tmp/concat/styles/main.min.css'));
280+
281+
assert.ok(uglify);
282+
assert.equal(uglify.generated.files.length, 1);
283+
assert.equal(uglify.generated.files[0].dest, path.normalize('dist/scripts/plugins.js'));
284+
285+
assert.ok(cssmin);
286+
assert.equal(cssmin.generated.files.length, 1);
287+
assert.equal(cssmin.generated.files[0].dest, path.normalize('dist/styles/main.min.css'));
288+
289+
});
290+
291+
it('should allow to suppress a step', function () {
292+
grunt.log.muted = true;
293+
grunt.config.init();
294+
grunt.config('useminPrepare', {
295+
html: 'index.html',
296+
options: {
297+
flow: {
298+
html: {
299+
steps: {
300+
js: ['uglify'],
301+
css: []
302+
}
303+
}
304+
}
305+
}
306+
});
307+
grunt.file.copy(path.join(__dirname, 'fixtures/usemin.html'), 'index.html');
308+
grunt.task.run('useminPrepare');
309+
grunt.task.start();
310+
311+
var uglify = grunt.config('uglify');
312+
var concat = grunt.config('concat');
313+
var cssmin = grunt.config('cssmin');
270314

271315
assert.equal(concat, null);
316+
272317
assert.ok(uglify);
273318
assert.equal(uglify.generated.files.length, 1);
274-
var files = uglify.generated.files[0];
275-
assert.equal(files.dest, path.normalize('dist/scripts/plugins.js'));
319+
assert.equal(uglify.generated.files[0].dest, path.normalize('dist/scripts/plugins.js'));
276320

321+
assert.equal(cssmin, null);
277322
});
278323

279324
it('should allow use to furnish new steps of the flow', function () {

0 commit comments

Comments
 (0)