diff --git a/main.js b/main.js index a2bc259..43fe35e 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,5 @@ var path = require('path') + , sys = require('sys') , fs = require('fs') , watch = require('watch') , request = require('request') @@ -113,10 +114,35 @@ function copy (obj) { function playSound () { spawn("/usr/bin/afplay", ["/System/Library/Sounds/Blow.aiff"]); } - + function createApp (doc, url, cb) { var app = {doc:doc} + + //check if .couchappignore exists, if it does, read it in + var ignoreFiles=[]; + try{ + if(fs.statSync(path.join(process.cwd(),".couchappignore")).isFile()) + ignoreFiles = eval(fs.readFileSync(path.join(process.cwd(),".couchappignore")).toString()); + } + catch(err) {} + + console.log("ignore: " + ignoreFiles); + + //utility function to detect filtered files + var filter = function(f){ + var match=false; + ignoreFiles.forEach( + function(exp,i,arr){ + if(new RegExp(exp).test(f)) + { + match=true; + console.log("Ignoring file: " + f + " matching ignore rule: " + exp); + } + }); + return match; + } + app.fds = {}; app.prepare = function () { @@ -159,7 +185,7 @@ function createApp (doc, url, cb) { }) }) } - + app.push = function (callback) { var revpos , pending_dirs = 0 @@ -176,11 +202,12 @@ function createApp (doc, url, cb) { pending_dirs = app.doc.__attachments.length; app.doc.__attachments.forEach(function (att) { - watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) { + watch.walk(att.root, {ignoreDotFiles:true, filter:filter}, + function (err, files) { var pending_files = Object.keys(files).length; for (i in files) { (function (f) { fs.readFile(f, function (err, data) { - f = f.replace(att.root, att.prefix || '').replace(/\\/g,"/"); + f = f.replace(att.root, att.prefix || ''); if (f[0] == '/') f = f.slice(1) if (!err) { var d = data.toString('base64') @@ -231,20 +258,32 @@ function createApp (doc, url, cb) { app.push(function () { var changes = []; + //read in the .couchappignore file, if it exists + //var ignore = console.log('Watching files for changes...') + //check if .couchappignore exists, if it does, read it in + var ignoreFiles=[]; + try{ + if(fs.statSync(path.join(process.cwd(),".couchappignore")).isFile()) + ignoreFiles = eval(fs.readFileSync(path.join(process.cwd(),".couchappignore")).toString()); + } + catch(err) {} + console.log("ignore: " + ignoreFiles); + app.doc.__attachments.forEach(function (att) { var pre = att.root if (pre[pre.length - 1] !== '/') pre += '/'; - watch.createMonitor(att.root, {ignoreDotFiles:true}, function (monitor) { + watch.createMonitor(att.root, {ignoreDotFiles:true, filter:filter}, + function (monitor) { monitor.on("removed", function (f, stat) { f = f.replace(pre, ''); - changes.push([null, f]); + if(!filter(f)) changes.push([null, f]); }) monitor.on("created", function (f, stat) { - changes.push([f, f.replace(pre, ''), stat]); + if(!filter(f)) changes.push([f, f.replace(pre, ''), stat]); }) monitor.on("changed", function (f, curr, prev) { - changes.push([f, f.replace(pre, ''), curr]); + if(!filter(f)) changes.push([f, f.replace(pre, ''), curr]); }) }) }) @@ -311,4 +350,4 @@ function createApp (doc, url, cb) { exports.createApp = createApp exports.loadAttachments = loadAttachments exports.bin = require('./bin') -exports.loadFiles = loadFiles +exports.loadFiles = loadFiles \ No newline at end of file