How to use the walk.walkSync function in walk

To help you get started, we’ve selected a few walk 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 percy / react-percy / packages / react-percy-storybook / src / getStaticAssets.js View on Github external
if (fs.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
          // eslint-disable-next-line no-console
          console.warn('\n[percy][WARNING] Skipping large file: ', resourceUrl);
          return;
        }

        // TODO(fotinakis): this is synchronous and potentially memory intensive, but we don't
        // keep a reference to the content around so this should be garbage collected. Re-evaluate?
        const content = fs.readFileSync(absolutePath);

        hashToResource[encodeURI(resourceUrl)] = content;
        next();
      },
    },
  };
  walk.walkSync(buildDir, walkOptions);

  return hashToResource;
}
github jettro / nodejs-photo-indexer / app.js View on Github external
var exif = require('exif2');
var walk = require('walk');
var elasticsearch = require('elasticsearch');
var readline = require('readline');

var walker  = walk.walkSync('/Users/jettrocoenradie/Pictures/export/2013', { followLinks: false });

var client = new elasticsearch.Client({
	host: '192.168.1.10:9200',
	log:'trace'
});

walker.on('file', function(root, stat, next) {
	console.log("Walk " + stat.name);
    // Add this file to the list of files
    if (strEndsWith(stat.name.toLowerCase(),".jpg")) {
	    extractData(root + '/' + stat.name, next);
    }
    next();
});

walker.on('end', function() {
github ecomfe / htmlcs / lib / cli / helper.js View on Github external
return targets.reduce(function (files, target) {
        var stat = fs.statSync(target);

        if (stat.isFile()) {
            files.push(target);
            return files;
        }

        if (stat.isDirectory()) {
            walk.walkSync(target, {
                followLinks: false,
                filters: ['node_modules', 'bower_components', 'Temp', '_Temp'],
                listeners: {
                    file: function (root, fileStat, next) {
                        var filePath = path.join(root, fileStat.name);

                        // filter with suffix (.html)
                        if (HTML_EXT_PATTERN.test(filePath)) {
                            files.push(filePath);
                        }
                        next();
                    }
                }
            });
            return files;
        }
github percy / percy-webdriverio / src / fileSystemAssetLoader.js View on Github external
const options = this.options;
      const buildDir = options.buildDir;
      const mountPath = `${options.mountPath || ''}/`;

      let isDirectory = false;
      try {
        isDirectory = fs.statSync(buildDir).isDirectory();
      } catch (err) {
        reject(err);
        return;
      }

      if (isDirectory) {
        const resources = [];
        let errors;
        walk.walkSync(buildDir, {
          followLinks: true,
          listeners: {
            file: function file(root, fileStats, next) {
              const absolutePath = path.join(root, fileStats.name);
              let resourceUrl = absolutePath;
              if (path.sep === '\\') {
                // Windows: transform filesystem backslashes into forward-slashes for the URL.
                resourceUrl = resourceUrl.replace(/\\/g, '/');
              }

              resourceUrl = resourceUrl.replace(buildDir, '');

              if (resourceUrl.charAt(0) === '/') {
                resourceUrl = resourceUrl.substr(1);
              }
github seanmonstar / intel / test / hint.js View on Github external
'before': function() {
      walk.walkSync(path.join(__dirname, '../lib'), options);
      walk.walkSync(__dirname, options);
    },
github drd / jsxlate / bin / filesFromMixedPaths.js View on Github external
directories: function(root, dirStatsArray, next) {
                    next();
                },
                file: function(root, fileStats, next) {
                    if (jsOrJsxRegex.test(fileStats.name)) {
                        files.push(path.join(root, fileStats.name));
                    }
                    next();
                },
                errors: function(root, nodeStatsArray, next) {
                    console.error('Error with', nodeStatsArray);
                    next();
                }
            }
        }
        walk.walkSync(dirPath, options);
    });
github gnosis / truffle-nice-tools / gas / gasFixtures.js View on Github external
}

            function addGasBeforeAndAfterHooks() {
              const gasHooks = `_$gasTestingHiddenContracts = [${contractsArr}]; before(_$gasTestingHiddenStats.createGasStatCollectorBeforeHook(_$gasTestingHiddenContracts));after(_$gasTestingHiddenStats.createGasStatCollectorAfterHook(_$gasTestingHiddenContracts));`;
              let targetFile = fs.readFileSync(path.join(root, fileStats.name))
              let improvedFile = targetFile.toString().replace(/\bcontract\s*\(.*?{/g, "$&" + gasHooks);
              
              fs.writeFileSync(path.join(root, fileStats.name), improvedFile);
            }
          }
          next();
        }
      }
    };

    walk.walkSync(gasTestDirectory, walkerOptions);
  }
};
github lytics / pathforajs / gulpfile.js View on Github external
gulp.task('docs:hbs', ['build:rollup'], function () {
  let options = {
    listeners: {
      file: function (root, stat) {
        compileExample(root, stat.name);
      }
    }
  };

  walk.walkSync(EXAMPLESSRC, options);
});
github ryanflorence / ember-tools / src / commands / build.js View on Github external
appDirs.forEach(function(dirName, index, array) {
    if (dirName == 'templates' || dirName == 'config') return;
    var dirPath = getAssetPath(dirName);
    var walker = walk(dirPath);
    walker.on('file', function(dir, stats, next) {
      if (stats.name.charAt(0) !== '.') {
        var path = unroot(dir+'/'+stats.name).replace(/\.js$/, '');
        if (dirName == 'helpers') {
          helpers.push({path: path});
        } else {
          var name = inflector.objectify(path.replace(dirName, ''));
          modules.push({
            objectName: name,
            path: path
          });
        }
      }
      next();
    });
    walker.on('end', function() {
github frappe / frappejs / server / init_models.js View on Github external
module.exports = function(models_path) {
    if (!models_path) {
        return;
    }

    walk.walkSync(models_path, {
        listeners: {
            file: (basepath, file_data, next) => {
                const doctype = path.basename(path.dirname(basepath));
                const name = path.basename(basepath);
                const file_path = path.resolve(basepath, file_data.name);
                if (doctype==='doctype' && file_data.name.endsWith('.js')) {
                    frappe.modules[file_data.name.slice(0, -3)] = require(file_path);
                }
                next();
            }
        }
    });
}

walk

A node port of python's os.walk

(MIT OR Apache-2.0)
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular walk functions