read-components
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -0,1 +1,4 @@ | ||
# read-components 0.4.2 (7 July 2013) | ||
* Updated docs and links in code. | ||
# read-components 0.4.1 (7 July 2013) | ||
@@ -2,0 +5,0 @@ * Fixed bug with overridden properties. |
@@ -88,6 +88,7 @@ var sysPath = require('path'); | ||
if (!json.main) { | ||
return callback(new Error('Component JSON file "' + fullPath + '" must have `main` property. See git.io/brunch-bower')); | ||
return callback(new Error('Component JSON file "' + fullPath + '" must have `main` property. See https://github.com/paulmillr/read-components#README')); | ||
} | ||
var pkg = standardizePackage(json); | ||
var files = getPackageFiles(pkg).map(function(relativePath) { | ||
@@ -94,0 +95,0 @@ return sysPath.join(path, relativePath); |
{ | ||
"name": "read-components", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Read bower and component(1) components", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,55 @@ # read-components | ||
Install with `npm install read-components`. | ||
read-components was made for automatic builders like [Brunch](http://brunch.io). | ||
Automatic means you don’t need to specify bower files which will be built. | ||
Instead, read-components reads root `bower.json`, opens `bower.json` of | ||
all packages and their dependencies and auto-calculates concatenation order. | ||
This requires files to have `dependencies` and `main` properties specified. | ||
But not all bower packages have `bower.json` with `main` property specified. | ||
I’d say less than 50%. So parsing these will fail: | ||
```json | ||
// Root bower.json | ||
{ | ||
... | ||
dependencies: { | ||
"chaplin": "*" | ||
} | ||
} | ||
// bower_components/chaplin/bower.json | ||
{ | ||
... | ||
dependencies: {"backbone": "*"} | ||
} | ||
// bower_components/backbone/bower.json | ||
{// no deps, no `main`} | ||
``` | ||
read-components solves the problem by allowing user to specify `bower.json` | ||
**overrides** in root config file. | ||
For example, if your root bower.json looks like that | ||
```json | ||
{ | ||
"dependencies": {"chaplin": "*"}, | ||
"overrides": { | ||
"backbone": { | ||
"main": "backbone.js", | ||
"dependencies": { | ||
"underscore": "~1.5.0", | ||
"jquery": "~2.0.0" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
read-components will treate backbone bower.json as completed and will produce | ||
correct output for automatic builders. | ||
## Usage | ||
@@ -18,4 +71,36 @@ | ||
}); | ||
read('.', 'bower', function(error, components) {}); | ||
``` | ||
Output is a list of packages like this: | ||
```json | ||
[{ name: 'd', | ||
version: '1.0.2', | ||
files: [ '/Users/john/project/bower_components/d/index.js' ], | ||
dependencies: { }, | ||
sortingLevel: 2 }, | ||
{ name: 'e', | ||
version: '1.0.1', | ||
files: [ '/Users/paul/project/bower_components/e/index.js' ], | ||
dependencies: { d: '~1.0.0' }, | ||
sortingLevel: 1 } ] | ||
``` | ||
Each package will also have `sortingLevel` and `files` specified. | ||
You can use it to get concatenation order like this: | ||
```javascript | ||
// Note that it is sorted like this by default. | ||
packages | ||
.sort(function(a, b) { | ||
var field = 'sortingLevel'; | ||
return b[field] - a[field]; | ||
}) | ||
.map(function(pkg) { | ||
return pkg.files; | ||
}); | ||
``` | ||
## License | ||
@@ -22,0 +107,0 @@ |
@@ -12,10 +12,18 @@ require('chai').should(); | ||
describe('Main', function() { | ||
describe('getPackageFiles', function() { | ||
it('should extract all package files', function(done) { | ||
read(__dirname, 'bower', function(error, value) { | ||
value.map(getAttr('name')).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
describe('read', function() { | ||
it('should provide the correct order', function(done) { | ||
read(__dirname, 'bower', function(error, packages) { | ||
packages.map(getAttr('name')).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
done(); | ||
}); | ||
}); | ||
// it('should extract all package files', function(done) { | ||
// read(__dirname, 'bower', function(error, packages) { | ||
// console.log(packages) | ||
// packages.map(getAttr('files')).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
// done(); | ||
// }); | ||
// }); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11387
242
127