Skip to content

Commit

Permalink
Merge branch 'release/v0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Jul 11, 2014
2 parents 9803733 + fcb0580 commit def05ec
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 33 deletions.
33 changes: 21 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ path = require('path');

// 3rd-party modules

var Q, async, cli, findup;
var Q, async, cli, findup, ProgressBar;
Q = require('q');
async = require('async');
cli = require('cli');
findup = require('findup-sync');
ProgressBar = require('progress');

// custom modules

Expand Down Expand Up @@ -74,30 +75,38 @@ function testConfig() {
}

function eachTarget(t, options, done) {
var actions, info;
var actions, info, theseLocalFiles, bar;
info = function (msg) {
cli.info(t.label + ': ' + msg);
};
t.on('progress', function (action) {
cli.info(action.toString());
});

Q.all([
localFiles.applyStrategy(t.strategy),
t.cdn.listFiles()
]).spread(function (localFiles, remoteFiles) {
info(remoteFiles.length + ' remote file(s)');
cli.info('applying "' + t.strategy + '" strategy to local file(s)');
localFiles.applyStrategy(t.strategy).then(function (files) {
theseLocalFiles = files;
info('scanning...');
t.cdn.once('files.length', function (length) {
bar = new ProgressBar('[:bar] :current/:total :percent :elapsed :etas', {
total: length
});
});
t.cdn.on('file:fixed', function () {
bar.tick();
});
return t.cdn.listFiles();
}).then(function (remoteFiles) {
actions = new ActionList();
actions.compareFileLists(localFiles, remoteFiles);
actions.compareFileLists(theseLocalFiles, remoteFiles);
info(actions.length + ' synchronisation action(s) to perform');
return t.cdn.executeActions(actions, options);

}).then(function () {
done();

}).fail(function (err) {
cli.fatal(err);
}).done();
}).done(function () {
done();
});
}

function go(options) {
Expand Down
19 changes: 17 additions & 2 deletions lib/cdn/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ CDN.prototype.executeActions = function (actions, options) {
* @param {File} file
*/
CDN.prototype.fixFile = function (file) {
var dfrd, options;
var self, dfrd, options;
self = this;
dfrd = Q.defer();

if (file.mime && typeof file.mime === 'string') {
self.emit('file:fixed');
dfrd.resolve();
return dfrd.promise;
}
Expand All @@ -189,13 +191,15 @@ CDN.prototype.fixFile = function (file) {
};
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;
}
self.emit('file:fixed');
dfrd.resolve();
});

Expand All @@ -208,10 +212,11 @@ CDN.prototype.fixFiles = function (files) {
self = this;
dfrd = Q.defer();

async.eachLimit(files, 10, function (file, done) { // perItem
async.eachLimit(files, 15, function (file, done) { // perItem
self.fixFile(file).done(done, done);
}, function (err) { // onComplete
if (err) {
console.error('fixFiles', err);
dfrd.reject(err);
} else {
dfrd.resolve(files);
Expand Down Expand Up @@ -275,9 +280,19 @@ CDN.prototype.listFiles = function () {

this.listAllFiles(files)
.then(function (files) {
self.emit('files.length', files.length);
return self.fixFiles(files);
})
.then(function (files) {
files.sort(function (a, b) {
if (a.path < b.path) {
return -1;
}
if (a.path > b.path) {
return 1;
}
return 0;
});
dfrd.resolve(files);
})
.done();
Expand Down
9 changes: 9 additions & 0 deletions lib/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ FileList.prototype.applyStrategy = function (strategy) {
lists.forEach(function (list) {
files = files.concat(list);
});
files.sort(function (a, b) {
if (a.path < b.path) {
return -1;
}
if (a.path > b.path) {
return 1;
}
return 0;
});
return (new FileList(files)).ready();
});
};
Expand Down
39 changes: 20 additions & 19 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.4.0",
"version": "0.5.0",
"homepage": "https://github.com/jokeyrhyme/cdn-sync",
"author": {
"name": "Ron Waldon",
Expand Down Expand Up @@ -36,28 +36,29 @@
"node": ">=0.9.0 <0.11.0"
},
"dependencies": {
"async": "~0.2",
"aws-sdk": "~1.12",
"cli": "~0.4",
"findup-sync": "~0.1",
"glob": "~3.2",
"graceful-fs": "~2.0",
"mime": "~1.2",
"mmmagic": "~0.3",
"q": "~0.9",
"underscore": "~1.5",
"z-schema": "~2.0"
"async": "0.9.0",
"aws-sdk": "2.0.6",
"cli": "0.6.3",
"findup-sync": "0.1.3",
"glob": "4.0.3",
"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"
},
"devDependencies": {
"chai": "~1.8",
"chai": "~1.9",
"grunt": "~0.4",
"grunt-contrib-watch": "~0.5",
"grunt-contrib-watch": "~0.6",
"grunt-jslint": "~1.1",
"grunt-mocha-cli": "~1.3",
"grunt-mocha-cov": "~0.0.7",
"mocha": "~1.14",
"sinon": "~1.7",
"sinon-chai": "~2.4"
"grunt-mocha-cli": "~1.9",
"grunt-mocha-cov": "~0.2",
"mocha": "~1.20",
"sinon": "~1.10",
"sinon-chai": "~2.5"
},
"peerDependencies": {},
"keywords": []
Expand Down

0 comments on commit def05ec

Please sign in to comment.