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

cetera

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cetera - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

lib/cache/.undefined

48

lib/cache/development_cache.js

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.8.0
var DevelopmentCache, fs, path;

@@ -12,3 +12,3 @@

DevelopmentCache.prototype.route = function(conf) {
var app, name, route, script, scripts, src, _i, _len, _results;
var app, name, route, script, scripts, src, tags, _i, _len;
app = conf.app;

@@ -18,23 +18,33 @@ scripts = conf.scripts;

name = conf.name;
_results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
script = scripts[_i];
route = "/" + name + "/" + script;
_results.push(app.get(route, function(req, res) {
var file, match;
match = req.path.match(new RegExp("^\/" + name + "\/(.*)"));
file = path.join(src, match[1]);
res.header({
'Content-Type': 'text/javascript'
});
return fs.readFile(file, function(err, data) {
if (!err) {
return res.send(data);
}
res.statusCode = 404;
return res.send();
});
}));
app.get(route, (function(_this) {
return function(req, res) {
var file, match;
match = req.path.match(new RegExp("^\/" + name + "\/(.*)"));
file = path.join(src, match[1]);
res.header({
'Content-Type': 'text/javascript'
});
return fs.readFile(file, function(err, data) {
if (!err) {
return res.send(data);
}
res.statusCode = 404;
return res.send();
});
};
})(this));
}
return _results;
tags = (function() {
var _j, _len1, _results;
_results = [];
for (_j = 0, _len1 = scripts.length; _j < _len1; _j++) {
script = scripts[_j];
_results.push("<script src='/" + name + "/" + script + "' type='text/javascript'></script>\n");
}
return _results;
})();
return tags.join('');
};

@@ -41,0 +51,0 @@

@@ -1,3 +0,3 @@

// Generated by CoffeeScript 1.6.3
var ProductionCache, cache, fs, path;
// Generated by CoffeeScript 1.8.0
var ProductionCache, cache, fs, md5, moment, path, uglify;

@@ -8,2 +8,10 @@ path = require('path');

uglify = require('uglify-js');
md5 = require('MD5');
moment = require('moment');
require('moment-timezone');
cache = {};

@@ -15,3 +23,3 @@

ProductionCache.prototype.route = function(conf) {
var app, name, script, scripts, src, _i, _len, _results;
var app, cache_control, cache_control_file, cache_seconds, concat_script, concat_script_name, current_checksum, name, script, scripts, src, tag, version;
app = conf.app;

@@ -21,30 +29,55 @@ scripts = conf.scripts;

name = conf.name;
_results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
script = scripts[_i];
_results.push((function(script) {
var route;
route = "/" + name + "/" + script;
return app.get(route, function(req, res) {
var file, match;
res.header({
'Content-Type': 'text/javascript'
});
if (cache[route] != null) {
return res.send(cache[route]);
}
match = req.path.match(new RegExp("^\/" + name + "\/(.*)"));
file = path.join(src, match[1]);
return fs.readFile(file, function(err, data) {
if (err == null) {
cache[route] = data;
return res.send(data);
}
res.statusCode = 404;
return res.send();
});
});
})(script));
cache_seconds = conf.cache_seconds || 86400;
version = conf.version || '0.0.0';
cache_control_file = __dirname + ("/." + name.cache_control);
concat_script_name = "/" + name + "-" + version + ".min.js";
tag = "<script src='" + concat_script_name + "', type='text/javascript'></script>";
concat_script = uglify.minify((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
script = scripts[_i];
_results.push(src + '/' + script);
}
return _results;
})());
cache_control = void 0;
try {
cache_control = JSON.parse(fs.readFileSync(cache_control_file).toString());
} catch (_error) {}
if (cache_control != null) {
current_checksum = md5(concat_script.code);
if (cache_control.md5 !== current_checksum) {
cache_control['Last-Modified'] = moment().tz('GMT').format('ddd, DD MMM YYYY hh:mm:ss GMT');
cache_control.md5 = current_checksum;
}
} else {
cache_control = {};
cache_control['Last-Modified'] = moment().tz('GMT').format('ddd, DD MMM YYYY hh:mm:ss GMT');
cache_control.md5 = md5(concat_script.code);
}
return _results;
try {
fs.writeFileSync(cache_control_file, JSON.stringify(cache_control));
} catch (_error) {}
app.head(concat_script_name, function(req, res) {
res.header({
'Content-Type': 'text/javascript',
'Content-Length': concat_script.code.length,
'Cache-Control': "max-age=" + cache_seconds + ", must-revalidate",
'Expires': moment(Date.now() + cache_seconds * 1000).tz('GMT').format('ddd, DD MMM YYYY hh:mm:ss GMT'),
'Last-Modified': cache_control['Last-Modified']
});
return res.send('');
});
app.get(concat_script_name, function(req, res) {
res.header({
'Content-Type': 'text/javascript',
'Content-Length': concat_script.code.length,
'Cache-Control': "max-age=" + cache_seconds + ", must-revalidate",
'Expires': moment(Date.now() + cache_seconds * 1000).tz('GMT').format('ddd, DD MMM YYYY hh:mm:ss GMT'),
'Last-Modified': cache_control['Last-Modified']
});
return res.send(concat_script.code);
});
return tag;
};

@@ -51,0 +84,0 @@

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.8.0
var Development, Packager, Production;

@@ -12,3 +12,3 @@

Packager.prototype.mount = function(conf) {
var cache, env;
var cache, env, tags;
if (conf == null) {

@@ -32,6 +32,8 @@ conf = {};

cache = new Production;
return cache.route(conf);
tags = cache.route(conf);
return tags;
} else {
cache = new Development;
return cache.route(conf);
tags = cache.route(conf);
return tags;
}

@@ -38,0 +40,0 @@ };

{
"name": "cetera",
"description": "effortlessness, requirejs, packager, modules",
"version": "0.0.8",
"version": "0.0.9",
"author": "nomilous <nomilous@gmail.com",

@@ -12,3 +12,8 @@ "contributors": [

],
"dependencies": {},
"dependencies": {
"MD5": "^1.2.1",
"moment": "^2.8.4",
"moment-timezone": "^0.2.5",
"uglify-js": "^2.4.16"
},
"repository": "git@github.com:nomilous/cetera.git",

@@ -15,0 +20,0 @@ "main": "./lib/cetera",

@@ -6,3 +6,3 @@ cetera

### version 0.0.8 (high alpha)
### version 0.0.9 (high alpha)

@@ -20,3 +20,3 @@

packager.mount
script_tags = packager.mount

@@ -34,3 +34,3 @@ #

#
# - results in script routes as /packagename/**/*.js
# - results in script routes as /packagename/**/*.js for the browser to access
#

@@ -41,3 +41,3 @@

#
# config.src as source directory for scripts
# config.src as source directory for the js scripts
#

@@ -48,3 +48,4 @@

#
# scripts as array of scripts to serve
# scripts as array of scripts to serve,
# path relative to 'src' as specified above
#

@@ -59,5 +60,34 @@

#
# When NODE_ENV is set to production all scripts are concatinated and minified,
# and published with a version number and cache controls in the headed
#
#
cache_seconds: 31536000 # how long should proxies and clients cache the script file
# defaults to one day
#
version: 'n.n.n' # changing the version will cause a refresh on the proxies
# and clients no matter how long the cache_seconds
# defaults to 0.0.0
#
app.get '/index', (req, res) ->
res.render 'index',
title: 'www.newswords.org'
script_tags: script_tags
```
```html
<html>
<head>
<%= script_tags %>
</head>
...
```
Todo

@@ -64,0 +94,0 @@ ----

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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