Skip to content

Commit

Permalink
Merge branch 'nathanaelnsmith-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Knötschke committed Apr 26, 2016
2 parents 8f4bb2c + c10c547 commit 3e72915
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ For example:
mainBowerFiles({ paths: 'path/for/project', group: 'home' });
```

You can include all packages except for those listed in a group with the `!` operator.

```javascript
mainBowerFiles({ paths: 'path/for/project', group: '!home' });
```

## LICENSE

(MIT License)
Expand Down
20 changes: 15 additions & 5 deletions lib/package_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ PackageCollection.prototype = {
includeDev = this.opts.includeDev || false,
includeSelf = this.opts.includeSelf || false,
bowerJson = JSON.parse(stripJsonComments(readFile(this.opts.paths.bowerJson, 'utf8'))),
devDependencies = bowerJson.devDependencies || {},
dependencies = bowerJson.dependencies || {},
isExludingGroup = (group && bowerJson.group && group.charAt(0) === "!" && bowerJson.group[group.slice(1)].length > 0),
devDependencies = (isExludingGroup ? this.filterByGroup(bowerJson.devDependencies, bowerJson.group[group.slice(1)]) : bowerJson.devDependencies) || {},
dependencies = (isExludingGroup ? this.filterByGroup(bowerJson.dependencies, bowerJson.group[group.slice(1)]) : bowerJson.dependencies) || {},
main = bowerJson.main || {};

includeDev = includeDev === true ? 'inclusive' : includeDev;

this.overrides = extend(bowerJson.overrides || {}, this.overrides);

// add packages from group option or add packages entirely from bower file
if (group && bowerJson.group) {
// add packages from group option, add all except in group, or add packages entirely from bower file
if (group && bowerJson.group && !isExludingGroup) {
if (!bowerJson.group[group]) {
throw new Error('group "' + group + '" does not exists in bower.json');
}
Expand Down Expand Up @@ -112,6 +112,16 @@ PackageCollection.prototype = {
}
},

filterByGroup: function (deps, group) {
var filtered = {};
for (var dep in deps) {
if (group.indexOf(dep) === -1) {
filtered[dep] = deps[dep];
}
}
return filtered;
},

/**
* Get srcs of all packages
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "main-bower-files",
"version": "2.11.2",
"version": "2.12.0",
"description": "Get main files from your installed bower packages.",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 10 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,23 @@ describe('main-bower-files', function() {
]).fromConfig('/_bower_with_group.json').when(done);
});

it('should select the expected files from group propery in bower.json', function(done) {
it('should select the expected files from group property in bower.json', function(done) {
expect([
'/fixtures/simple/simple.js',
'/fixtures/multi/multi.js',
'/fixtures/multi/multi.css'
]).fromConfig('/_bower_with_group.json', { group: 'group1' }).when(done);
});

it('should select all files except those listed in the group property in bower.json', function(done) {
expect([
'/fixtures/overwritten/overwritten.js',
'/fixtures/hasPackageNoBower/hasPackageNoBower.js',
'/fixtures/deepPaths/lib/deeppaths.js',
'/fixtures/decoy/decoy.js'
]).fromConfig('/_bower_with_group.json', { group: '!group1' }).when(done);
});

it('should throw an exception if group name does not exist', function() {
var when = expect([]).fromConfig('/_bower_with_group.json', { group: 'nonExistingGroup' }).when;

Expand Down

0 comments on commit 3e72915

Please sign in to comment.