Skip to content

Commit

Permalink
Merge branch 'release/v0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Dec 1, 2014
2 parents 029e731 + 0f72e8c commit de8f3e8
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 311 deletions.
27 changes: 27 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log

node_modules

.DS_Store
.c9revisions

.cdn-sync.json

# JetBrains IDEA files
/.idea
/*.iml

/tmp
41 changes: 41 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"env": {
"amd": false,
"browser": false,
"mocha": true,
"node": true
},
"globals": {
"Promise": false
},
"rules": {
/* Possible Errors */
"no-extra-parens": 2,
"no-reserved-keys": 2,
"valid-jsdoc": 1, // TODO: 2
/* Best Practices */
"block-scoped-var": 2,
"complexity": [1, 3],
"default-case": 2,
"guard-for-in": 2,
"no-div-regex": 2,
"no-else-return": 2,
"no-eq-null": 2,
"no-floating-decimal": 2,
"no-process-env": 2,
"no-self-compare": 2,
"no-void": 2,
"no-warning-comments": 1, // TODO: 2
"radix": 2,
"vars-on-top": 2,
"wrap-iife": 2,
/* Variables */
"no-catch-shadow": 2,
/* Node.JS */
"no-sync": 2,
/* Stylistic Issues */
"no-mixed-spaces-and-tabs": 2,
"no-underscore-dangle": 1, // TODO: drop Underscore requirement
"quotes": [1, "single", "avoid-escape"]
}
}
26 changes: 5 additions & 21 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
/*jslint indent:2, maxlen:80, node:true*/
'use strict';

module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({

jslint: {
all: {
src: [
'**/*.js',
'**/*.json',
'!test/**/*',
'!node_modules/**/*'
],
exclude: [],
directives: {
todo: true // TODO: eventually eliminate this exemption
},
options: {
errorsOnly: true,
failOnError: true
}
}
eslint: {
target: [ './' ]
},

mochacli: {
Expand Down Expand Up @@ -70,12 +54,12 @@ module.exports = function (grunt) {

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-mocha-cli');
grunt.loadNpmTasks('grunt-mocha-cov');

grunt.registerTask('travis', ['jslint', 'mochacli', 'mochacov:coveralls']);
grunt.registerTask('test', ['jslint', 'mochacli', 'mochacov:html']);
grunt.registerTask('travis', ['eslint', 'mochacli', 'mochacov:coveralls']);
grunt.registerTask('test', ['eslint', 'mochacli', 'mochacov:html']);

// Default task.
grunt.registerTask('default', ['test']);
Expand Down
40 changes: 17 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
/*jslint indent:2, maxlen:80, node:true*/
/*jslint nomen:true*/ // Underscore.JS and __dirname
'use strict';

// Node.JS standard modules

var fs, path;
fs = require('fs');
path = require('path');
var fs = require('fs');
var path = require('path');

// 3rd-party modules

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

// custom modules

var cdnSync, ActionList, Config, FileList;
cdnSync = require(path.join(__dirname, 'lib'));
ActionList = cdnSync.ActionList;
Config = cdnSync.Config;
FileList = cdnSync.FileList;
var cdnSync = require(path.join(__dirname, 'lib'));
var ActionList = cdnSync.ActionList;
var Config = cdnSync.Config;
var FileList = cdnSync.FileList;

// promise-bound anti-callbacks

Expand All @@ -41,9 +37,8 @@ function init(options) {
} else {
fs.exists(target, function (exists) {
if (exists) {
cli.error(target + ' already exists');
cli.info('remove existing file or use --force');
process.exit(1);
cli.fatal(target + ' already exists');
} else {
cli.fatal('`init` not implemented yet');
}
Expand Down Expand Up @@ -71,9 +66,8 @@ function testConfig() {
dfrd.resolve(config);
});
} else {
cli.error('.cdn-sync.json not found for ' + process.cwd());
cli.info('use `cdn-sync init` to get started');
process.exit(1);
cli.fatal('.cdn-sync.json not found for ' + process.cwd());
}
return dfrd.promise;
}
Expand Down Expand Up @@ -134,9 +128,9 @@ cli.parsePackageJson();
cli.parse({
'dry-run': ['n', 'make no changes, only simulate actions']
}, {
'init' : 'create a .cdn-sync.json file in this directory',
'test' : 'health-check on active .cdn-syn.json file',
'go' : 'execute synchronisation (default if no command)'
'init': 'create a .cdn-sync.json file in this directory',
'test': 'health-check on active .cdn-syn.json file',
'go': 'execute synchronisation (default if no command)'
});

/*jslint unparam:true*/
Expand Down
2 changes: 0 additions & 2 deletions lib/action.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*jslint indent:2, maxlen:80, node:true*/
/*jslint nomen:true*/ // Underscore.JS and __dirname
'use strict';

// Node.JS standard modules
Expand Down
2 changes: 0 additions & 2 deletions lib/actionlist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*jslint indent:2, maxlen:80, node:true*/
/*jslint nomen:true*/ // Underscore.JS and __dirname
'use strict';

// Node.JS standard modules
Expand Down
1 change: 0 additions & 1 deletion lib/bufferutils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*jslint indent:2, maxlen:80, node:true*/
'use strict';
// Node.JS standard modules

Expand Down
50 changes: 25 additions & 25 deletions lib/cdn/aws.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/*jslint indent:2, maxlen:80, node:true, nomen:true*/
'use strict';

// Node.JS standard modules

var events, path;
events = require('events');
path = require('path');
var events = require('events');
var path = require('path');

// 3rd-party modules

var Q, AWS, async;
Q = require('q');
AWS = require('aws-sdk');
async = require('async');
var Q = require('q');
var AWS = require('aws-sdk');
var async = require('async');

// custom modules

var File, FileList;
File = require(path.join(__dirname, '..', 'file'));
FileList = require(path.join(__dirname, '..', 'filelist'));
var File = require(path.join(__dirname, '..', 'file'));
var FileList = require(path.join(__dirname, '..', 'filelist'));

// promise-bound anti-callbacks

Expand Down Expand Up @@ -175,7 +171,7 @@ CDN.prototype.executeActions = function (actions, options) {
* @param {File} file
*/
CDN.prototype.fixFile = function (file) {
var self, dfrd, options, timer;
var self, dfrd, options, timer, request;
self = this;
dfrd = Q.defer();

Expand All @@ -186,35 +182,39 @@ CDN.prototype.fixFile = function (file) {
}

timer = setTimeout(function () {
var error;
error = new Error('fixFile took too long: ' + file.path);
console.error(error);
dfrd.reject(error);
if (request && request.abort) {
request.abort();
}
console.log('timeout: ' + file.path + '; retrying... ');
self.fixFile(file).then(dfrd.resolve, dfrd.reject);
}, 15 * 1e3); // wait 15 seconds

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

// TODO: check cache headers and permissions
return dfrd.promise;
Expand Down
12 changes: 4 additions & 8 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/*jslint indent:2, maxlen:80, node:true*/
/*jslint nomen:true*/ // Underscore.JS and __dirname
'use strict';
// Node.JS standard modules

var path = require('path');

// 3rd-party modules

var Q, ZSchema;
Q = require('q');
ZSchema = require('z-schema');
var Q = require('q');
var ZSchema = require('z-schema');

// custom modules

var Target, schema;
Target = require(path.join(__dirname, 'target'));
schema = require(path.join(__dirname, '..', 'doc', 'cdn-sync.schema.json'));
var Target = require(path.join(__dirname, 'target'));
var schema = require(path.join(__dirname, '..', 'doc', 'cdn-sync.schema.json'));

// this module

Expand Down
32 changes: 15 additions & 17 deletions lib/file.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/*jslint indent:2, maxlen:80, node:true*/
'use strict';
// Node.JS standard modules

var crypto, fs, path;
crypto = require('crypto');
fs = require('graceful-fs');
path = require('path');
var crypto = require('crypto');
var fs = require('graceful-fs');
var path = require('path');

// 3rd-party modules

var Q, mime, mmm, magic;
Q = require('q');
mime = require('mime');
mmm = require('mmmagic');
magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE);
var Q = require('q');
var mime = require('mime');
var mmm = require('mmmagic');
var magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE);

// custom modules

Expand All @@ -23,12 +20,6 @@ var detectFile = Q.nbind(magic.detectFile, magic);

// this module

mime.define({
'image/vnd.microsoft.icon': ['cur'],
'text/x-sass': ['sass'],
'text/x-scss': ['scss']
});

/**
* represents an individual file in the CDN, with required actions
* @constructor
Expand Down Expand Up @@ -78,7 +69,8 @@ var File = function (options) {
File.prototype.constructor = File;

File.prototype.clone = function () {
return new this.constructor(this);
var Constructor = this.constructor;
return new Constructor(this);
};

File.prototype.setMIME = function (value) {
Expand Down Expand Up @@ -189,6 +181,12 @@ File.prototype.getBuffer = function () {
return dfrd.promise;
};

mime.define({
'image/vnd.microsoft.icon': ['cur'],
'text/x-sass': ['sass'],
'text/x-scss': ['scss']
});

// exports

module.exports = File;
Loading

0 comments on commit de8f3e8

Please sign in to comment.