Permalink
Browse files

The v0.8 changes in install.

  • Loading branch information...
1 parent e7cd397 commit 8f8f3e42dda919e2c4b292f71d1610571af9dc88 @SaltwaterC committed Jan 24, 2013
Showing with 100 additions and 36 deletions.
  1. +30 −9 lib/internals.js
  2. +14 −5 lib/tools.js
  3. +12 −5 package.json
  4. +44 −17 tests/xml-parser.js
View
@@ -1,9 +1,35 @@
'use strict';
-/* Load the dependencies */
-var dependencies = require('../config/dependencies.js');
-var xmlDep = require(dependencies.xml);
-var mimeDep = require(dependencies.mime);
+/* the internally used modules */
+require('./Buffer.toByteArray.js');
+var cfg = require('../config/aws.js');
+var tools = require('./tools.js');
+
+/* Load the library dependencies with feature detection */
+var dependencies = {
+ xml: 'libxml-to-js',
+ mime: 'mime-magic'
+};
+
+var xmlDep, mimeDep;
+
+try {
+ xmlDep = require(dependencies.xml);
+ tools.debug('using libxml-to-js');
+} catch (e) {
+ dependencies.xml = 'xml2js';
+ xmlDep = require(dependencies.xml);
+ tools.debug('using xml2js');
+}
+
+try {
+ mimeDep = require(dependencies.mime);
+ tools.debug('using mime-magic');
+} catch (e) {
+ dependencies.mime = 'mime';
+ mimeDep = require(dependencies.mime);
+ tools.debug('using mime');
+}
/* core modules */
var fs = require('fs');
@@ -18,11 +44,6 @@ var EventEmitter = require('events').EventEmitter;
/* 3rd party module */
var lodash = require('lodash');
-/* the internally used modules */
-require('./Buffer.toByteArray.js');
-var cfg = require('../config/aws.js');
-var tools = require('./tools.js');
-
/**
* Checks the config for the minimally allowable setup
*
View
@@ -1,5 +1,8 @@
'use strict';
+/* core module */
+var util = require('util');
+
/* 3rd party module */
var lodash = require('lodash');
@@ -18,21 +21,20 @@ var merge = function (obj1, obj2) {
};
exports.merge = merge;
-/*jslint bitwise:true*/
-
/**
* Returns the absolute integer value of the input. Avoids the NaN crap.
*
* @param value
* @returns {Number}
*/
var absInt = function (value) {
- return Math.abs(parseInt(value, 10) | 0);
+ /*jslint bitwise:true*/
+ var sureInt = parseInt(value, 10) | 0;
+ /*jslint bitwise:false*/
+ return Math.abs(sureInt);
};
exports.absInt = absInt;
-/*jslint bitwise:false*/
-
/**
* Sorts the keys of an object
*
@@ -63,3 +65,10 @@ var escapePath = function (path) {
return encodeURI(path);
};
exports.escapePath = escapePath;
+
+var debug = function (message) {
+ if (process.env.NODE_ENV === 'development') {
+ util.debug('aws2js - ' + message);
+ }
+};
+exports.debug = debug;
View
@@ -1,20 +1,27 @@
{
"name": "aws2js",
"main": "./lib/aws.js",
- "version": "0.7.11",
+ "version": "0.8.0",
"description": "AWS (Amazon Web Services) APIs client implementation for node.js",
- "scripts": {
- "install": "node tools/install.js"
- },
"dependencies": {
"lodash": ">=0.6.x",
"semver": ">=1.0.x"
},
+ "optionalDependencies": {
+ "libxml-to-js": ">=0.3.10",
+ "mime-magic": ">=0.4.1",
+ "xml2js": ">=0.2.2",
+ "mime": ">=1.2.9"
+ },
"devDependencies": {
"http-get": ">=0.4.0"
},
+ "scripts": {
+ "test": "tools/test.sh"
+ },
"engines": {
- "node": ">=0.4.10"
+ "node": ">=0.6.0",
+ "npm": ">=1.1.x"
},
"homepage": "https://github.com/SaltwaterC/aws2js",
"author": {
View
@@ -3,35 +3,62 @@
var common = require('./includes/common.js');
var fs = require('fs');
+var util = require('util');
var assert = require('assert');
var config = require('../config/aws.js');
-var dependencies = require('../config/dependencies.js');
-var xmlDep = require(dependencies.xml);
-var mimeDep = require(dependencies.mime);
+var have = {
+ 'libxml-to-js': true,
+ 'xml2js': true
+};
var callbacks = {
- parser: 0
+ 'libxml-to-js': 0,
+ 'xml2js': 0
};
-var parser;
-if (dependencies.xml === 'libxml-to-js') {
- parser = xmlDep;
-} else { // xml2js
- parser = new xmlDep.Parser(config.xml2jsConfig).parseString;
+try {
+ require('libxml-to-js');
+} catch (e) {
+ have['libxml-to-js'] = false;
+ callbacks['libxml-to-js']++;
+ util.log('libxml-to-js is not installed, moving on without it');
+}
+
+try {
+ require('xml2js');
+} catch (e) {
+ util.error('ERROR: xml2js is missing, can not test the installation');
+ process.exit(1);
}
-fs.readFile('data/ec2-describeimages.xml', function (err, data) {
- assert.ifError(err);
+var testXml = function (lib) {
+ util.log('testing the XML library ' + lib);
+
+ var parser = require(lib);
+ if (lib === 'xml2js') {
+ parser = new parser.Parser(config.xml2jsConfig).parseString;
+ }
- var xml = new Buffer(data).toString();
- parser(xml, function (err, res) {
- callbacks.parser++;
+ fs.readFile('data/ec2-describeimages.xml', function (err, data) {
assert.ifError(err);
- assert.equal(res.imagesSet.item[0].imageId, 'ami-be3adfd7');
- assert.equal(res.imagesSet.item[1].imageId, 'ami-be3adfd9');
+
+ var xml = new Buffer(data).toString();
+ parser(xml, function (err, res) {
+ callbacks[lib]++;
+ assert.ifError(err);
+ assert.equal(res.imagesSet.item[0].imageId, 'ami-be3adfd7');
+ assert.equal(res.imagesSet.item[1].imageId, 'ami-be3adfd9');
+ });
});
-});
+};
+
+var idx;
+for (idx in have) {
+ if (have.hasOwnProperty(idx) && have[idx] === true) {
+ testXml(idx);
+ }
+}
common.teardown(callbacks);

0 comments on commit 8f8f3e4

Please sign in to comment.