read-components
Advanced tools
Comparing version 0.6.0 to 0.6.1
89
index.js
@@ -6,3 +6,2 @@ var sysPath = require('path'); | ||
var emitter = new events.EventEmitter(); | ||
var path = require('path'); | ||
@@ -15,7 +14,2 @@ var jsonPaths = { | ||
var dirs = { | ||
bower: 'bower_components', | ||
component: 'components' | ||
}; | ||
var dependencyLocator = { | ||
@@ -30,2 +24,27 @@ bower: 'name', | ||
var getDir = function(root, type, callback) { | ||
if (type == 'bower') { | ||
var defaultBowerDir = 'bower_components'; | ||
var bowerrcPath = sysPath.join(root, '.bowerrc'); | ||
fs.exists(bowerrcPath, function(hasBowerrc) { | ||
if (hasBowerrc) { | ||
fs.readFile(bowerrcPath, 'utf8', function(error, bowerrcContent) { | ||
if (error) return callback(error); | ||
var bowerrcJson = JSON.parse(bowerrcContent); | ||
var bowerrcDirectory = bowerrcJson.directory; | ||
callback(null, bowerrcDirectory || defaultBowerDir); | ||
}); | ||
} else { | ||
callback(null, defaultBowerDir); | ||
} | ||
}); | ||
} else if (type == 'component') { | ||
return callback(null, 'components'); | ||
} else { | ||
return callback(null); | ||
} | ||
}; | ||
// Return unique list items. | ||
@@ -43,3 +62,2 @@ var unique = function(list) { | ||
return res[res.length-1] + '=' + res[res.length]; | ||
} | ||
@@ -94,5 +112,3 @@ return repo.replace('/', '-'); | ||
jsonProps.forEach(function(property) { | ||
pkg[property].forEach(function(item) { | ||
list.push(item); | ||
}); | ||
Array.isArray(pkg[property]) && list.push.apply(list, pkg[property]); | ||
}); | ||
@@ -107,5 +123,6 @@ return unique(list); | ||
var dotpath = getJsonPath(path, 'dotbower'); | ||
var _read = function(actualPath) { | ||
readJson(actualPath, type, function(error, json) { | ||
if (error) return callback(error); | ||
@@ -124,2 +141,3 @@ if (overrides) { | ||
var files = getPackageFiles(pkg).map(function(relativePath) { | ||
@@ -130,3 +148,3 @@ return sysPath.join(path, relativePath); | ||
callback(null, { | ||
name: pkg.name, version: pkg.version, repo: pkg.repo, | ||
name: pkg.name, version: pkg.version, repo: sysPath.basename(path), | ||
files: files, dependencies: pkg.dependencies || {} | ||
@@ -145,2 +163,3 @@ }); | ||
Object.keys(item.dependencies).forEach(function(dep) { | ||
dep = sanitizeRepo(dep); | ||
if (!obj[dep]) obj[dep] = true; | ||
@@ -153,26 +172,30 @@ }); | ||
var readPackages = function(root, type, allProcessed, list, overrides, callback) { | ||
var parent = sysPath.join(root, dirs[type]); | ||
var paths = list.map(function(item) { | ||
if (type === 'component') item = sanitizeRepo(item); | ||
return {path: sysPath.join(parent, item), overrides: overrides[item]}; | ||
}); | ||
each(paths, processPackage.bind(null, type), function(error, newProcessed) { | ||
getDir(root, type, function(error, dir) { | ||
if (error) return callback(error); | ||
var processed = allProcessed.concat(newProcessed); | ||
var processedNames = {}; | ||
processed.forEach(function(_) { | ||
processedNames[_[dependencyLocator[type]]] = true; | ||
var parent = sysPath.join(root, dir); | ||
var paths = list.map(function(item) { | ||
if (type === 'component') item = sanitizeRepo(item); | ||
return {path: sysPath.join(parent, item), overrides: overrides[item]}; | ||
}); | ||
var newDeps = gatherDeps(newProcessed, type).filter(function(item) { | ||
return !processedNames[item]; | ||
each(paths, processPackage.bind(null, type), function(error, newProcessed) { | ||
if (error) return callback(error); | ||
var processed = allProcessed.concat(newProcessed); | ||
var processedNames = {}; | ||
processed.forEach(function(_) { | ||
processedNames[_[dependencyLocator[type]]] = true; | ||
}); | ||
var newDeps = gatherDeps(newProcessed, type).filter(function(item) { | ||
return !processedNames[item]; | ||
}); | ||
if (newDeps.length === 0) { | ||
callback(error, processed); | ||
} else { | ||
readPackages(root, type, processed, newDeps, overrides, callback); | ||
} | ||
}); | ||
if (newDeps.length === 0) { | ||
callback(error, processed); | ||
} else { | ||
readPackages(root, type, processed, newDeps, overrides, callback); | ||
} | ||
}); | ||
@@ -200,2 +223,3 @@ }; | ||
deps.forEach(function(depName) { | ||
depName = sanitizeRepo(depName) | ||
var dep = find(packages, function(_) { | ||
@@ -206,3 +230,2 @@ if (type === 'component') { | ||
return true; | ||
// nasty hack to ensure component repo ends with the specified repo | ||
@@ -221,3 +244,3 @@ // e.g. "repo": "https://raw.github.com/component/typeof" | ||
}).join(', '); | ||
throw new Error('Dependency "' + depName + '" is not present in the list of deps [' + names + ']. Specify correct dependency in bower.json or contact package author.'); | ||
throw new Error('Dependency "' + depName + '" is not present in the list of deps [' + names + ']. Specify correct dependency in ' + type + '.json or contact package author.'); | ||
} | ||
@@ -224,0 +247,0 @@ setLevel(initial + 1, dep); |
{ | ||
"name": "read-components", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Read bower and component(1) components", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# read-components | ||
# read-components [![Build Status](https://travis-ci.org/paulmillr/read-components.svg?branch=add-travis)](https://travis-ci.org/paulmillr/read-components) | ||
@@ -7,3 +7,3 @@ Read Twitter Bower and component(1) components. | ||
read-components was made for automatic builders like [Brunch](http://brunch.io). | ||
> 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. | ||
@@ -13,3 +13,9 @@ Instead, read-components reads root `bower.json`, opens `bower.json` of | ||
This requires files to have `dependencies` and `main` properties specified. | ||
## Component JSON file must have `main` property. | ||
Every component which is handled by bower must have "main" property in bower.json. You can specify this in your own `bower.json` in `overrides` section. See below for examples. | ||
## Why | ||
For automatic builds, read-components requires files to have `dependencies` and `main` properties specified. | ||
But not all bower packages have `bower.json` with `main` property specified. | ||
@@ -16,0 +22,0 @@ I’d say less than 50%. So parsing these will fail: |
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
13549
5
264
133