Skip to content

Commit

Permalink
The v0.8 changes in install.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltwaterC committed Jan 24, 2013
1 parent e7cd397 commit 8f8f3e4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 36 deletions.
39 changes: 30 additions & 9 deletions lib/internals.js
@@ -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');
Expand All @@ -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
*
Expand Down
19 changes: 14 additions & 5 deletions lib/tools.js
@@ -1,5 +1,8 @@
'use strict';

/* core module */
var util = require('util');

/* 3rd party module */
var lodash = require('lodash');

Expand All @@ -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
*
Expand Down Expand Up @@ -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;
17 changes: 12 additions & 5 deletions package.json
@@ -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": {
Expand Down
61 changes: 44 additions & 17 deletions tests/xml-parser.js
Expand Up @@ -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.