Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-components

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-components - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# read-components 0.3.0 (19 June 2013)
* Added new API syntax.
# read-components 0.2.1 (18 June 2013)

@@ -2,0 +5,0 @@ * Made API fully async.

65

index.js

@@ -13,17 +13,26 @@ var sysPath = require('path');

var readJson = function(file, callback) {
fs.readFile(file, function(err, contents) {
if (err) return callback(err);
fs.exists(file, function(exists) {
if (!exists) {
return callback(new Error('Component must have "' + bowerJson + '"'));
};
var json;
fs.readFile(file, function(err, contents) {
if (err) return callback(err);
try {
var json;
try {
json = JSON.parse(contents.toString());
} catch (err) {
} catch(err) {
err.code = 'EMALFORMED';
return callback(err);
}
return callback(new Error('Component JSON file is invalid in "' + file + '": ' + err));
}
callback(null, json);
if (!json.main && !json.scripts && !json.styles) {
return callback(new Error('Component JSON file must have `main` property. See git.io/brunch-bower. Contact component author of "' + file + '"'));
}
callback(null, json);
});
});

@@ -34,24 +43,9 @@ };

// Returns String.
var readBowerJson = function(path, callback) {
var bowerJson = sysPath.join(path, 'bower.json');
var jsonPaths = {
bower: 'bower.json',
component: 'component.json'
};
fs.exists(bowerJson, function(exists) {
if (!exists) {
return callback(new Error('Bower component must have bower.json in "' + bowerJson + '"'));
};
var fullPath = sysPath.resolve(bowerJson);
readJson(fullPath, function(error, data) {
if (error) return callback(new Error('Bower component bower.json is invalid in "' + path + '": ' + error));
var main = data.main;
if (!main && !data.scripts && !data.styles) {
return callback(new Error('Bower component bower.json must have `main` property. See git.io/brunch-bower. Contact component author of "' + path + '"'));
}
callback(null, data);
});
});
var getJsonPath = function(path, type) {
return sysPath.resolve(sysPath.join(path, jsonPaths[type]));
};

@@ -79,3 +73,3 @@

var processPackage = function(path, callback) {
readBowerJson(path, function(error, json) {
readJson(getJsonPath(path, 'bower'), function(error, json) {
if (error) return callback(error);

@@ -137,3 +131,7 @@ var pkg = standardizePackage(json);

var getPaths = function(directory, callback) {
var readBowerComponents = exports.readBowerComponents = function(directory, callback) {
if (typeof directory === 'function') {
directory = null;
callback = directory;
}
if (directory == null) directory = '.';

@@ -152,3 +150,2 @@ var parent = sysPath.join(directory, 'components');

getPaths('.', console.log.bind(console));
module.exports = getPaths;
// getBowerPaths('.', console.log.bind(console));
{
"name": "read-components",
"version": "0.2.1",
"version": "0.3.0",
"description": "Read bower and component(1) components",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,5 +10,5 @@ # read-components

```javascript
var readComponents = require('read-components');
var reader = require('read-components');
readComponents('your-project-dir-with-bower.json', function(error, components) {
reader.readBowerComponents('your-project-dir-with-bower.json', function(error, components) {
console.log('All components:', components);

@@ -15,0 +15,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc