Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Aug 27, 2014
2 parents def05ec + 3687c35 commit 029e731
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 53 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ FileList = cdnSync.FileList;

var localFiles;

// lift the default socket cap from 5 to Infinity
require('http').globalAgent.maxSockets = Infinity;
require('https').globalAgent.maxSockets = Infinity;

function init(options) {
var target = path.join(process.cwd(), '.cdn-sync.json');
if (options.force) {
Expand Down
35 changes: 24 additions & 11 deletions lib/cdn/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ CDN.prototype.executeActions = function (actions, options) {
* @param {File} file
*/
CDN.prototype.fixFile = function (file) {
var self, dfrd, options;
var self, dfrd, options, timer;
self = this;
dfrd = Q.defer();

Expand All @@ -185,22 +185,35 @@ CDN.prototype.fixFile = function (file) {
return dfrd.promise;
}

timer = setTimeout(function () {
var error;
error = new Error('fixFile took too long: ' + file.path);
console.error(error);
dfrd.reject(error);
}, 15 * 1e3); // wait 15 seconds

options = {
Bucket: this.cfg.Bucket,
Key: file.path
};
this.api.headObject(options, function (err, res) {
if (err) {
console.error(err);
dfrd.reject(err);
return;
}
file.setMIME(res.ContentType);
if (res.ContentEncoding) {
file.headers['Content-Encoding'] = res.ContentEncoding;
try {
if (err) {
console.error(err);
dfrd.reject(err);
return;
}
file.setMIME(res.ContentType);
if (res.ContentEncoding) {
file.headers['Content-Encoding'] = res.ContentEncoding;
}
self.emit('file:fixed');
dfrd.resolve();
} catch (e) {
console.error(e);
dfrd.reject(e);
}
self.emit('file:fixed');
dfrd.resolve();
clearTimeout(timer);
});

// TODO: check cache headers and permissions
Expand Down
18 changes: 8 additions & 10 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ Config.validate = function (obj) {
dfrd = Q.defer();

validator = new ZSchema();
validator.validate(obj, schema, function (err, report) {
var error;
if (err) {
dfrd.reject(err);
validator.validate(obj, schema, function (err, valid) {
if (!valid || err) {
if (Array.isArray(err) && err.length) {
dfrd.reject(err[0]);
} else {
dfrd.reject(err);
}
return;
}
if (!report || report.valid) {
dfrd.resolve();
} else {
error = report.errors[0];
dfrd.reject(new TypeError(error.path + ': ' + error.message));
}
dfrd.resolve();
});
return dfrd.promise;
};
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cdn-sync",
"description": "deflate / synchronise assets to a CDN",
"version": "0.5.0",
"version": "0.6.0",
"homepage": "https://github.com/jokeyrhyme/cdn-sync",
"author": {
"name": "Ron Waldon",
Expand Down Expand Up @@ -37,26 +37,27 @@
},
"dependencies": {
"async": "0.9.0",
"aws-sdk": "2.0.6",
"cli": "0.6.3",
"aws-sdk": "2.0.15",
"cli": "0.6.4",
"findup-sync": "0.1.3",
"glob": "4.0.3",
"glob": "4.0.5",
"graceful-fs": "3.0.2",
"mime": "1.2.11",
"mmmagic": "0.3.8",
"progress": "~1.1.7",
"q": "0.9.7",
"underscore": "1.6.0",
"z-schema": "2.4.8"
"underscore": "1.7.0",
"z-schema": "3.0.0"
},
"devDependencies": {
"chai": "~1.9",
"grunt": "~0.4",
"grunt-contrib-watch": "~0.6",
"grunt-jslint": "~1.1",
"grunt-mocha-cli": "~1.9",
"grunt-mocha-cov": "~0.2",
"mocha": "~1.20",
"grunt-mocha-cli": "~1.10",
"grunt-mocha-cov": "~0.3",
"mocha": "~1.21",
"request": "^2.40.0",
"sinon": "~1.10",
"sinon-chai": "~2.5"
},
Expand Down
51 changes: 28 additions & 23 deletions test/json_schema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ path = require('path');

// 3rd-party modules

var chai, assert, sinon, ZSchema;
var chai, assert, sinon, request, ZSchema;

chai = require('chai');
chai.use(require('sinon-chai'));
assert = require('chai').assert;
request = require('request');
sinon = require('sinon');
ZSchema = require('z-schema');

Expand Down Expand Up @@ -41,37 +42,40 @@ example = {
};

suite('JSON schema for `.cdn-sync.json`', function () {
var validator, schema, compiledSchema;
var validator, schema, jsonSchemaURL;

suiteSetup(function () {
suiteSetup(function (done) {
jsonSchemaURL = 'http://json-schema.org/draft-04/schema';
validator = new ZSchema({
strict: false // true
strictMode: false // true
});
schema = require(path.join(__dirname, '..', 'doc', 'cdn-sync.schema.json'));
});

test('schema passes validation', function (done) {
validator.validateSchema(schema, function (err, report) {
assert.isNull(err);
assert.isObject(report);
assert.lengthOf(report.errors, 0);
request(jsonSchemaURL, function (err, res, body) {
validator.setRemoteReference(jsonSchemaURL, JSON.parse(body));
done();
});
});

test('schema compiles', function (done) {
validator.compileSchema(schema, function (err, compiled) {
assert(true, 'asynchronous callback is executed');
assert.isNull(err, 'no compilation errors');
assert(compiled);
compiledSchema = compiled;
done();
});
test('schema passes validation', function () {
var err, valid;
valid = validator.validateSchema(schema);
err = validator.getLastErrors();
assert(!err);
assert.isTrue(valid);
});

test('schema compiles', function () {
var err, valid;
valid = validator.compileSchema(schema);
err = validator.getLastErrors();
assert(!err);
assert.isTrue(valid);
});

test('example validates against compiled schema', function (done) {
validator.validate(example, compiledSchema, function (report) {
assert.isNull(report);
validator.validate(example, schema, function (err, valid) {
assert(!err);
assert.isTrue(valid);
done();
});
});
Expand All @@ -80,8 +84,9 @@ suite('JSON schema for `.cdn-sync.json`', function () {
var broken;
broken = JSON.parse(JSON.stringify(example));
delete broken.targets[0].options.region;
validator.validate(broken, compiledSchema, function (err, report) {
assert.isObject(err);
validator.validate(broken, schema, function (err, valid) {
assert(err);
assert.isFalse(valid);
done();
});
});
Expand Down

0 comments on commit 029e731

Please sign in to comment.