tiny-lr
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,3 @@ { | ||
"description": "Tiny LiveReload server, background-friendly", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/mklabs/tiny-lr", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"faye-websocket": "~0.4.3", | ||
"noptify": "0.0.1" | ||
"noptify": "latest" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": { |
@@ -350,2 +350,3 @@ tiny-lr | ||
- 2013-01-12 - v0.0.2 - tasks - support for grunt 0.3.x | ||
- 2013-01-05 - v0.0.1 - Initial release |
var fs = require('fs'); | ||
var Server = require('..'); | ||
@@ -34,5 +35,7 @@ | ||
port: 35729 | ||
}); | ||
// if grunt 0.3, build up the list of mtimes to compare | ||
changed(); | ||
var done = this.async(); | ||
@@ -60,5 +63,7 @@ server = new Server(); | ||
if(!server) return; | ||
var files = changed(); | ||
grunt.log.verbose.writeln('... Reloading ' + grunt.log.wordlist(files) + ' ...'); | ||
server.changed({ | ||
body: { | ||
files: grunt.file.watchFiles.changed | ||
files: files | ||
} | ||
@@ -68,2 +73,54 @@ }); | ||
// Helpers | ||
// This normalize the list of changed files between 0.4 and 0.3. If | ||
// `watchFiles` is available, then use that. | ||
// | ||
// Otherwise, go through each watch config with `reload` as part of their | ||
// `tasks`, concat all the files, and maintain a list of mtime. A changed | ||
// files is simply a file with a "newer" mtime. | ||
function changed() { | ||
if(grunt.file.watchFiles) return grunt.file.watchFiles.changed; | ||
var watch = grunt.config('watch'); | ||
var files = Object.keys(watch).filter(function(target) { | ||
var tasks = watch[target].tasks; | ||
if(!tasks) return false; | ||
return ~tasks.indexOf('reload'); | ||
}).reduce(function(list, target) { | ||
return list.concat(watch[target].files || []); | ||
}, []); | ||
files = grunt.file.expandFiles(files).filter(ignore('node_modules')); | ||
// stat compare | ||
var stats = changed.stats = changed.stats || {}; | ||
var current = files.map(function(filepath) { | ||
var stat = fs.statSync(filepath); | ||
stat.file = filepath; | ||
return stat; | ||
}).reduce(function(o, stat) { | ||
o[stat.file] = stat.mtime.getTime(); | ||
return o; | ||
}, {}); | ||
files = Object.keys(current).filter(function(file) { | ||
if(!stats[file]) return true; | ||
return stats[file] !== current[file]; | ||
}); | ||
changed.stats = current; | ||
return files; | ||
} | ||
// filter helper | ||
function ignore(pattern) { return function(item) { | ||
return !~item.indexOf(pattern); | ||
}} | ||
}; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
352
24978
11
412
2
+ Addednoptify@0.0.3(transitive)
- Removednoptify@0.0.1(transitive)
Updatednoptify@latest