How to use the watch.walk function in watch

To help you get started, we’ve selected a few watch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tj / ngen / templates / modular / content / lib / loader.js View on Github external
var loader = module.exports = function(dir, context, callback) {
  if (!helpers.isDirectory(dir)) return;
  
  // Add trailing slash
  dir = dir.replace(/\/+$/, '') + '/';
  
  // Context must be defined
  context = context || {};
  
  var objects = {},
      weighted = [],
      args = Array.prototype.slice.call(arguments, 1);
      
  addInvokeMethods(context, weighted);
  
  watch.walk(dir, function(err, files_obj) {  
    if (err) {
      console.log(err);
      return;
    }
    
    var files = [];
    
    for (var file in files_obj) {
      if (!files_obj.hasOwnProperty(file)) continue;
      
      files.push(file);
    }
    
    // Replace kind of wildcard '?' with objects itself,
    // So objects can be passed to context on demand
    for (var i in context) if (context[i] === '?') context[i] = objects;
github davidmurdoch / shopify-theme-sync / app.js View on Github external
if ( prev === null ) {
						// f is a new file or directory

						// if we are a file, we can be synced with Shopify (probably)
						if ( curr.isFile() ) {
				    		updateTitle( util.format( "Creating: %s\n", f ) );

							shopify.create( f, wrap( handleResponse, f + " created" ) );
						}

						// only some directories can be synced, make sure we are one of these before trying.
						else if ( curr.isDirectory() && !filter( f, curr, validDirectories ) ) {

							// a directory was created (or just renamed), sync its files.
							watch.walk( f, options, function( err, files ) {
								for ( var _f in files ){
									if ( _f !== f ) {
										sync( _f, files[_f], null );
									}
								}
							});
						}
					}
					else if ( curr.nlink === 0 ) {
						// f was removed

						updateTitle( util.format( "Deleting: %s\n", f ) );

						shopify.delete( f, wrap( handleResponse, f + " deleted\n" ) );
					}
					else {
github mikeal / node.couchapp.js / bin.js View on Github external
function copytree (source, dest) {
  watch.walk(source, function (err  , files) {
    for (i in files) {
      (function (i) {
        if (files[i].isDirectory()) {
          try {
            fs.mkdirSync(i.replace(source, dest), 0755)
          } catch(e) {
            console.log('Could not create '+i.replace(source,dest))
          }
        } else {
          var stream = fs.createReadStream(i).pipe(fs.createWriteStream(i.replace(source, dest)));
          stream.on("error", function (err) {
              throw err;
          });
        }
      })(i);
    }
github hackoregon / civic / scripts / watch.js View on Github external
return memo.concat(curr);
  }, []);

  initialFiles.forEach(babelify);
}

const options = {
  ignoreDotFiles: true,
  ignoreNotPermitted: true,
  interval: 0.5,
  filter(filename) {
    return !blackFlagsReg.test(filename);
  }
};

walk(PKGS, options, initialWalkCallback);

if (watchFlag) {
  createMonitor(PKGS, options, watchCallback);
}
github steelmesh / steelmesh / node_modules / couchapp / main.js View on Github external
app.doc.__attachments.forEach(function (att) {
      watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
        for (i in files) { (function (f) {
          pending += 1
          fs.readFile(f, function (err, data) {
            f = f.replace(att.root, att.prefix || '');
            if (f[0] == '/') f = f.slice(1)
            if (!err) {
              var d = data.toString('base64')
                , md5 = crypto.createHash('md5')
                , mime = mimetypes.lookup(path.extname(f).slice(1))
                ;
              md5.update(d)
              md5 = md5.digest('hex')
              if (app.doc.attachments_md5[f] && app.doc._attachments[f]) {
                if (app.doc._attachments[f].revpos === app.doc.attachments_md5[f].revpos && 
                    app.doc.attachments_md5[f].md5 === md5) {   
                  pending -= 1
github mikeal / node.couchapp.js / main.js View on Github external
app.doc.__attachments.forEach(function (att) {
      watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
        pending_dirs += 1;
        var pending_files = Object.keys(files).length;
        for (i in files) { (function (f) {
          fs.readFile(f, function (err, data) {
            if(f.match(coffeeExt)){
              data = new Buffer( coffeeCompile.compile(data.toString()) );
              f = f.replace(coffeeExt,'.js');
            }
            f = f.replace(att.root, att.prefix || '').replace(/\\/g,"/");
            if (f[0] == '/') f = f.slice(1)
            if (!err) {
              var d = data.toString('base64')
                , md5 = crypto.createHash('md5')
                , mime = mimetypes.lookup(path.extname(f).slice(1))
                ;
              md5.update(d)
github maxogden / datacouch / node_modules / couchapp / main.js View on Github external
app.doc.__attachments.forEach(function (att) {
      watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
        for (i in files) { (function (f) {
          pending += 1
          fs.readFile(f, function (err, data) {
            f = f.replace(att.root, att.prefix || '');
            if (f[0] == '/') f = f.slice(1)
            if (!err) {
              var d = data.toString('base64')
                , md5 = crypto.createHash('md5')
                , mime = mimetypes.lookup(path.extname(f).slice(1))
                ;
              md5.update(d)
              md5 = md5.digest('hex')
              if (app.doc.attachments_md5[f] && app.doc._attachments[f]) {
                if (app.doc._attachments[f].revpos === app.doc.attachments_md5[f].revpos && 
                    app.doc.attachments_md5[f].md5 === md5) {   
                  pending -= 1
github kanso / kanso / packages / node-couchapp / build / eval.js View on Github external
app.doc.__attachments.forEach(function (att) {
        watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
            if (err) {
                return callback(err);
            }
            for (i in files) { (function (f) {
                pending += 1
                fs.readFile(f, function (err, data) {
                    f = f.replace(att.root, att.prefix || '');
                    if (f[0] == '/') f = f.slice(1)
                    if (!err) {
                        var d = data.toString('base64')
                    , mime = mimetypes.lookup(path.extname(f).slice(1))
                    ;
                app.doc._attachments[f] = {data:d, content_type:mime};
                    }
                pending -= 1
                    if (pending === 0) {

watch

Utilities for watching file trees.

Apache-2.0
Latest version published 8 years ago

Package Health Score

68 / 100
Full package analysis