Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

add option.exclude #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ module.exports = function(grunt) {
src: ['test/fixtures/Project_A/*.js', 'test/fixtures/Project_B/*.js'],
dest: 'tmp/multipackage_partial_simple.js'
},
multipackage_partial_exclude: {
options: {
only: 'ProjectB/*',
exclude: ['ProjectA/*'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

name: {
ProjectB: 'test/fixtures/Project_B',
ProjectA: 'test/fixtures/Project_A'
}
},
src: ['test/fixtures/Project_A/*.js', 'test/fixtures/Project_B/*.js'],
dest: 'tmp/multipackage_partial_exclude.js'
},
multipackage_partial_widcard: {
options: {
only: 'ProjectB/*',
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ grunt.initConfig({
});
```

#### options.exclude
Type: `Array`

The specific dependencies packages to exclude from the compilation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might include an example; the fact that it can take wild cards is non-obvious.

### Other Usage Examples

#### Default Options
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-mootools-packager",
"description": "Grunt task for MooTools Packager projects.",
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/ibolmo/grunt-mootools-packager",
"author": {
"name": "Olmo Maldonado",
Expand Down
12 changes: 12 additions & 0 deletions tasks/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ module.exports = function(grunt) {
// load each component into the buffer list
(only ? toArray(only) : set).forEach(loadComponent);

// remove unwanted dependencies
if (options.exclude){
var toExclude = toArray(options.exclude);
buffer = buffer.filter(function(def){
var shouldKeep = toExclude.filter(function(dependency){
var match = dependency.match(/([^\*]+)/);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary, but I feel like this matcher should be a method reused elsewhere.

return match ? def.key.indexOf(match[1]) != 0 : true;
});
return shouldKeep.length;
});
}

// convert the buffer into the actual source
buffer = buffer.map(function(def){ return def.source; }).join(options.separator);

Expand Down
17 changes: 17 additions & 0 deletions test/expected/multipackage_partial_exclude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
---

name: B part of ProjectA

description: ProjectB, extending ProjectA

requires: [ProjectA/ProjectA]

provides: ProjectB

...
*/

var projectB = function(){
return [projectA.name].concat('ProjectB');
};
10 changes: 10 additions & 0 deletions test/packager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ exports.packager = {

test.done();
},
// multi project build with wildcard option `exclude: 'package/*'`
multipackage_partial_exclude: function(test){
test.expect(1);

var actual = grunt.file.read('tmp/multipackage_partial_exclude.js');
var expected = grunt.file.read('test/expected/multipackage_partial_exclude.js');
test.equal(actual, expected, 'should be exact for multipackage build without specified excluded components.');

test.done();
},
// option `callback`
callback: function(test){
test.expect(1);
Expand Down