Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docpad-plugin-cachr

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docpad-plugin-cachr - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

out/cachr.tester.js

6

History.md
## History
- v2.1.0 August 17, 2012
- Updated [request](https://github.com/mikeal/request) dependency from v2.9.x to v2.10.x
- Added tests
- Added `refreshCache` option (defaults to `false`)
- Now halts generation until all files are cached
- v2.0.2 August 10, 2012

@@ -4,0 +10,0 @@ - Re-added markdown files to npm distribution as they are required for the npm website

73

out/cachr.plugin.js

@@ -7,6 +7,7 @@ // Generated by CoffeeScript 1.3.3

module.exports = function(BasePlugin) {
var CachrPlugin, balUtil, pathUtil, request;
var CachrPlugin, balUtil, fsUtil, pathUtil, request;
balUtil = require('bal-util');
request = require('request');
pathUtil = require('path');
fsUtil = require('fs');
return CachrPlugin = (function(_super) {

@@ -23,2 +24,3 @@

CachrPlugin.prototype.config = {
refreshCache: false,
urlPrefix: '/_docpad/plugins/cachr',

@@ -36,3 +38,3 @@ pathPrefix: pathUtil.join('_docpad', 'plugins', 'cachr')

config = this.config;
name = pathUtil.basename(sourceUrl);
name = require('crypto').createHash('md5').update(sourceUrl).digest('hex') + pathUtil.extname(sourceUrl).replace(/[\?\#].*$/, '');
details = {

@@ -54,18 +56,18 @@ name: name,

viaRequest = function() {
var writeStream;
docpad.logger.log('debug', "Cachr is fetching [" + details.sourceUrl + "] to [" + details.cachePath + "]");
writeStream = fs.createWriteStream(details.cachePath);
docpad.log('debug', "Cachr is fetching [" + details.sourceUrl + "] to [" + details.cachePath + "]");
return request({
uri: details.sourceUrl
}, function(err) {
uri: details.sourceUrl,
encoding: null
}, function(err, response, body) {
if (err) {
++attempt;
if (attempt === 3) {
docpad.log('debug', "Cachr is gave up fetching [" + details.sourceUrl + "] to [" + details.cachePath + "]");
return balUtil.exists(details.cachePath, function(exists) {
if (exists) {
return fs.unlink(details.cachePath, function(err2) {
return typeof next === "function" ? next(err) : void 0;
return balUtil.unlink(details.cachePath, function(err2) {
return next(err);
});
} else {
return typeof next === "function" ? next(err) : void 0;
return next(err);
}

@@ -77,16 +79,23 @@ });

} else {
return typeof next === "function" ? next() : void 0;
docpad.log('debug', "Cachr fetched [" + details.sourceUrl + "] to [" + details.cachePath + "]");
return balUtil.writeFile(details.cachePath, body, function(err) {
return next(err);
});
}
}).pipe(writeStream);
});
};
balUtil.isPathOlderThan(details.cachePath, 1000 * 60 * 5, function(err, older) {
if (err) {
return typeof next === "function" ? next(err) : void 0;
}
if (older === null || older === true) {
return viaRequest();
} else {
return typeof next === "function" ? next() : void 0;
}
});
if (this.config.refreshCache) {
viaRequest();
} else {
balUtil.isPathOlderThan(details.cachePath, 1000 * 60 * 5, function(err, older) {
if (err) {
return next(err);
}
if (older === null || older === true) {
return viaRequest();
} else {
return next();
}
});
}
return this;

@@ -104,5 +113,3 @@ };

};
if (typeof next === "function") {
next();
}
next();
return this;

@@ -112,7 +119,6 @@ };

CachrPlugin.prototype.writeAfter = function(_arg, next) {
var cachr, cachrPath, config, docpad, failures, logger, templateData, urlsToCache, urlsToCacheLength;
var cachr, cachrPath, config, docpad, failures, templateData, urlsToCache, urlsToCacheLength;
templateData = _arg.templateData;
cachr = this;
docpad = this.docpad;
logger = this.docpad.logger;
config = this.config;

@@ -124,5 +130,5 @@ urlsToCache = this.urlsToCache;

if (!urlsToCacheLength) {
return typeof next === "function" ? next() : void 0;
return next();
}
logger.log('info', 'Cachr started caching...', (failures ? "with " + failures + " failures" : ''));
docpad.log('info', "Cachr is caching " + urlsToCacheLength + " files...", (failures ? "with " + failures + " failures" : ''));
balUtil.ensurePath(cachrPath, function(err) {

@@ -132,6 +138,7 @@ var tasks,

if (err) {
return typeof next === "function" ? next(err) : void 0;
return next(err);
}
tasks = new balUtil.Group(function(err) {
return logger.log((failures ? 'warn' : 'info'), 'Cachr finished caching', (failures ? "with " + failures + " failures" : ''));
docpad.log((failures ? 'warn' : 'info'), 'Cachr finished caching', (failures ? "with " + failures + " failures" : ''));
return next();
});

@@ -142,3 +149,3 @@ balUtil.each(urlsToCache, function(details, sourceUrl) {

if (err) {
docpad.logger.log('warn', "Cachr failed to fetch: " + sourceUrl);
docpad.log('warn', "Cachr failed to fetch: " + sourceUrl);
docpad.error(err);

@@ -152,3 +159,3 @@ ++failures;

tasks.async();
return typeof next === "function" ? next() : void 0;
return this;
});

@@ -155,0 +162,0 @@ return this;

{
"name": "docpad-plugin-cachr",
"version": "2.0.2",
"version": "2.1.0",
"description": "Caches remote resources locally",

@@ -32,3 +32,3 @@ "homepage": "https://github.com/bevry/docpad-extras",

"dependencies": {
"request": "2.9.x",
"request": "2.10.x",
"bal-util": "1.13.x"

@@ -39,3 +39,6 @@ },

},
"main": "./out/cachr.plugin.js"
"main": "./out/cachr.plugin.js",
"scripts": {
"test": "node ./test/cachr.test.js"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc