express-istatic
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -44,2 +44,4 @@ var uglify = require('./uglify.js'); | ||
opts = opts || options || defaultOptions; | ||
var str = read(path, opts) || ''; | ||
@@ -49,3 +51,3 @@ | ||
if (str.indexOf('#{') > -1) { | ||
compiled_fns[path] = function(locals) { | ||
var fn = function(locals) { | ||
return str.replace(reg_val, function(m0, m1) { | ||
@@ -56,3 +58,14 @@ var fn = new Function('locals', 'with (locals) { return ' + m1 + '; }'); | ||
}; | ||
return compiled_fns[path](this); | ||
var ttl = opts && opts.ttl || 0; | ||
if (!ttl && ttl !== 0 || ttl > 5) { | ||
compiled_fns[path] = fn; | ||
} | ||
if (ttl > 5) { | ||
setTimeout(function() { | ||
delete compiled_fns[path]; | ||
}, ttl * 1000); | ||
} | ||
return fn(this); | ||
} | ||
@@ -59,0 +72,0 @@ |
@@ -6,9 +6,9 @@ var fs = require('fs'); | ||
var stylus = require('stylus'); | ||
var debug = require('debug')('istatic'); | ||
var log = require('debug')('istatic'); | ||
function waitStale(ttl, _t) { | ||
function globalStale(ttl, _t) { | ||
try { | ||
clearInterval(_t); | ||
} catch (e) {} | ||
_t = setInterval(function() { cache = {}; }, ttl * 1000); | ||
_t = setInterval(function() { global_cache = {}; }, ttl * 1000); | ||
} | ||
@@ -41,3 +41,4 @@ | ||
if (ttl > 5) { | ||
waitStale(ttl, _t); | ||
globalStale(ttl, _t); | ||
setInterval(function() { cache = {}; }, ttl * 1000); | ||
} else { | ||
@@ -67,3 +68,3 @@ // if the ttl is less than 5 seconds, | ||
var charset = opt.charset || 'utf-8'; | ||
var debug = process.env.DEBUG || opt.debug; | ||
var debug = 'debug' in opt ? opt.debug : process.env.DEBUG; | ||
var doCompress = 'compress' in opt ? opt.compress : true; | ||
@@ -79,3 +80,5 @@ var _doCache = opt.fresh ? false : doCache; | ||
} catch (e) { | ||
debug('Reading..', filepath, e); | ||
log('Reading %s failed: %s', filepath, e); | ||
if (opt.debug) throw e; | ||
return '/* == istatic: no such file: ' + filepath + ' == */'; | ||
} | ||
@@ -87,3 +90,3 @@ | ||
stylus.render(str, function(err, str) { | ||
if (err) debug('Compiling', filepath, err); | ||
if (err) log('Compiling %s failed: %s', filepath, err); | ||
else cache[filepath] = _uglify('css', str, opt.css, doCompress); | ||
@@ -94,3 +97,3 @@ }); | ||
less.render(str, function(err, str) { | ||
if (err) debug('Compiling', filepath, err); | ||
if (err) log('Compiling %s failed: %s', filepath, err); | ||
else cache[filepath] = _uglify('css', str, opt.css, doCompress); | ||
@@ -97,0 +100,0 @@ }); |
@@ -1,16 +0,11 @@ | ||
var uglifycss = require('uglifycss'); | ||
var cleancss = require('clean-css'); | ||
var uglifyjs = require('uglify-js'); | ||
var jsp = uglifyjs.parser; | ||
var pro = uglifyjs.uglify; | ||
module.exports = { | ||
js: function(str, opt) { | ||
var ast = jsp.parse(str); | ||
ast = pro.ast_mangle(ast); | ||
ast = pro.ast_squeeze(ast); | ||
return pro.gen_code(ast, opt); | ||
js: function(code) { | ||
return uglifyjs.minify(code, { fromString: true, }).code; | ||
}, | ||
css: function(str, opt) { | ||
return uglifycss.processString(str, opt); | ||
css: function(code) { | ||
return cleancss.process(code); | ||
} | ||
}; |
{ | ||
"name": "express-istatic", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"homepage": "http://github.com/ktmud/express-istatic", | ||
@@ -11,7 +11,7 @@ "description": "Add compressed inline css and scripts to your html, but write them as seperated files.", | ||
"dependencies": { | ||
"less": ">= 1.0", | ||
"debug": "*", | ||
"stylus": ">= 0.1", | ||
"uglify-js": "1.3.x", | ||
"uglifycss": ">= 0.0.5" | ||
"less": "~1.3.1", | ||
"debug": "~0.7.2", | ||
"stylus": "~0.32.1", | ||
"uglify-js": "~2.2.5", | ||
"clean-css": "~1.0.1" | ||
}, | ||
@@ -18,0 +18,0 @@ "engines": { |
@@ -103,4 +103,6 @@ # Inline Static Files for express / connect / nodejs | ||
`filename` is the path of your static file. If it begins with a '/', the real path will be `process.cwd() + filename`. Otherwise, the file will be looked up from the root of your inline static files, as you configured before. | ||
`filename` is the path of your static file. | ||
If it begins with a `'/'`, the real path will be `process.cwd() + filename`. Otherwise, the file will be looked up from the root of your inline static files, as you configured before. | ||
You can set available options above, except for `root` and `ttl`. A `fresh` option is available for you to set this `istatic` call always read from file directly. | ||
@@ -107,0 +109,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
13239
160
1
223
+ Addedclean-css@~1.0.1
+ Addedamdefine@1.0.1(transitive)
+ Addedclean-css@1.0.12(transitive)
+ Addedcommander@1.3.2(transitive)
+ Addedcssom@0.2.5(transitive)
+ Addeddebug@0.7.4(transitive)
+ Addedkeypress@0.1.0(transitive)
+ Addedless@1.3.3(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedsource-map@0.1.43(transitive)
+ Addedstylus@0.32.1(transitive)
+ Addeduglify-js@2.2.5(transitive)
+ Addedwordwrap@0.0.3(transitive)
+ Addedycssmin@1.0.1(transitive)
- Removeduglifycss@>= 0.0.5
- Removed@adobe/css-tools@4.3.3(transitive)
- Removed@isaacs/cliui@8.0.2(transitive)
- Removed@pkgjs/parseargs@0.11.0(transitive)
- Removedansi-regex@5.0.16.1.0(transitive)
- Removedansi-styles@4.3.06.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcopy-anything@2.0.6(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@4.4.0(transitive)
- Removedeastasianwidth@0.2.0(transitive)
- Removedemoji-regex@8.0.09.2.2(transitive)
- Removederrno@0.1.8(transitive)
- Removedforeground-child@3.3.0(transitive)
- Removedglob@10.4.5(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedimage-size@0.5.5(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-what@3.14.1(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjackspeak@3.4.3(transitive)
- Removedless@4.2.1(transitive)
- Removedlru-cache@10.4.3(transitive)
- Removedmake-dir@2.1.0(transitive)
- Removedmime@1.6.0(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedminipass@7.1.2(transitive)
- Removedms@2.1.3(transitive)
- Removedneedle@3.3.1(transitive)
- Removedpackage-json-from-dist@1.0.1(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-scurry@1.11.1(transitive)
- Removedpify@4.0.1(transitive)
- Removedprr@1.0.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.4.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@4.1.0(transitive)
- Removedsource-map@0.6.10.7.4(transitive)
- Removedstring-width@4.2.35.1.2(transitive)
- Removedstrip-ansi@6.0.17.1.0(transitive)
- Removedstylus@0.64.0(transitive)
- Removedtslib@2.8.1(transitive)
- Removeduglify-js@1.3.5(transitive)
- Removeduglifycss@0.0.29(transitive)
- Removedwhich@2.0.2(transitive)
- Removedwrap-ansi@7.0.08.1.0(transitive)
Updateddebug@~0.7.2
Updatedless@~1.3.1
Updatedstylus@~0.32.1
Updateduglify-js@~2.2.5