<commit_before>"use strict";

var fs = require('fs'),
    glob = require('glob'),
    debug = require('debug')('mott:watch');

module.exports = function(ctx, done){
    var lock = false;
    function onWatchEvent(event, filename){
        if(!lock){
            lock = true;
            debug(filename, event);

            // @todo (lucas) Move to an emit on ctx?
            ctx.runTask('build', function(){
                debug('rebuild', 'completed');
                if(ctx.app){
                    ctx.app.emit('change');
                }
                setTimeout(function(){
                    lock = false;
                }, 200);
            });
        }<commit_msg>Emit file events on context.  Closes #45<commit_after>"use strict";

var fs = require('fs'),
    glob = require('glob'),
    debug = require('debug')('mott:watch');

module.exports = function(ctx, done){
    var lock = false;
    function onWatchEvent(event, filename){
        if(!lock){
            lock = true;
            debug(filename, event);
            ctx.emit('file ' + event, filename);

            ctx.runTask('build', function(){
                debug('rebuild', 'completed');
                if(ctx.app){
                    ctx.app.emit('change');
                }
                setTimeout(function(){
                    lock = false;
                }, 200);
            });
        }
{'fraction_non_alphanumeric': 0.14542836573074155, 'fraction_numerical': 0.005759539236861051, 'mean_word_length': 1.5181159420289856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1633047', 'n_tokens_mistral': 381, 'n_tokens_neox': 356, 'n_words': 83}