How to use walkdir - 10 common examples

To help you get started, we’ve selected a few walkdir 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 SSENSE / node-cucumber-testrail-sync / lib / ScenarioSynchronizer.js View on Github external
function readImplementedSteps(next) {
      this.implementedSteps = [];

      mkdirp(this.config.stepDefinitionsDir);
      walk.sync(this.config.stepDefinitionsDir, function (filePath) {
        if (!fs.lstatSync(filePath).isDirectory()) {
          var fileContent = fs.readFileSync(filePath).toString();

          var re = /^this\.(Given|When|Then)\((\/|')(.+)(\/|')(\w*)/;
          var stepDefinitions = fileContent.split('\n').map(Function.prototype.call, String.prototype.trim)
          .filter(function (line) {
            return re.test(line);
          })
          .map(function (line) {
            var matches = re.exec(line);

            var keyword = matches[1];
            var pattern = matches[3];
            var isStringPattern = false;

            // String Pattern
github itchio / itch / test / chrome / static / index.html View on Github external
},
      }
    });
  }

  var Mocha = require('mocha');

  var mocha = new Mocha();
  mocha.ui('bdd').reporter(isCi ? 'tap' : 'html');

  var query = Mocha.utils.parseQuery(window.location.search || '');
  if (query.grep) mocha.grep(query.grep);
  if (query.invert) mocha.invert();

  // Read all test files.
  var walker = require('walkdir').walk(require('path').dirname(__dirname), {
    no_recurse: true
  });

  walker.on('file', function(file) {
    if (/-spec.js/.test(file))
      mocha.addFile(file);
  });

  walker.on('end', function() {
    var runner = mocha.run(function() {
      Mocha.utils.highlightTags('code');
      if (isCi) {
        ipc.send('process.exit', runner.failures);
      }
    });
  });
github itchio / itch / test / main.es6 View on Github external
import {walk} from 'walkdir'

// Read all test files.
let walker = walk(__dirname, { no_recurse: true })

walker.on('file', function (file) {
  let matches = file.match(/([^\/^\\]+-spec).js$/)
  if (!matches) return
  let modpath = `./${matches[1]}`
  require(modpath)
})
github wellcaffeinated / PhysicsJS / docs / gen-docs.js View on Github external
var dirtyFiles = [],
      ignore  = options.ignore || [],
      files   = [];

  // If more paths are given with the --source flag
  if(source.split(',').length > 1){
    var dirtyPaths = source.split(',');

    dirtyPaths.forEach(function(dirtyPath){
      dirtyFiles = dirtyFiles.concat(require('walkdir').sync(path.resolve(process.cwd(), dirtyPath),{follow_symlinks:true}));
    });
  }
  // Just one path given with the --source flag
  else {
    source  = path.resolve(process.cwd(), source);
    dirtyFiles = require('walkdir').sync(source,{follow_symlinks:true}); // tee hee!
  }

  dirtyFiles.forEach(function(file){
    file = path.relative(process.cwd(), file);

    var doNotIgnore = _.all(ignore, function(d){
      // return true if no part of the path is in the ignore list
      return (file.indexOf(d) === -1);
    });

    if ((file.substr(-2) === 'js') && doNotIgnore) {
      files.push(file);
    }
  });
  console.log(files)
  return files;
github mhevery / jasmine-node / lib / jasmine-node / spec-collection.js View on Github external
loadpaths.forEach(function(loadpath){
    wannaBeSpecs = walkdir.sync(loadpath, { follow_symlinks: true });
    for (var i = 0; i < wannaBeSpecs.length; i++) {
      var file = wannaBeSpecs[i];
      try {
        if (fs.statSync(file).isFile()) {
          if (!/.*node_modules.*/.test(path.relative(loadpath, file)) &
              matcher.test(path.basename(file))) {
            specs.push(createSpecObj(file));
          }
        }
      } catch(e) {
        // nothing to do here
      }
    }
  });
};
github jimschubert / electron-aurelia-example / spec / init.js View on Github external
var tasks = [];
  var specBaseDir = path.dirname(args.specsInit);
  var specDir = args.specsLocation;

  // creates an async task that imports a spec, then triggers the next task.
  function createTask(spec){
    return function(next){
      System.import(spec).then(function(){
        next();
      });
    }
  }

  // Synchronously walk the directory and load all specs
  walk.sync(specDir, function(file, stat){
    if (/-spec.js$/.test(file)) {
      // convert full path to relative path under spec base directory without .js extension
      // also, prefix with spec: for jspm alias (defined in test.js)
      var spec = file.replace(specBaseDir, '').replace(/^\//, '').replace(/^/, 'spec:').replace(/.js$/, '');
      tasks.push(createTask(spec));
    }
  });

  // Load all jasmine tests, then execute the test runner.
  async.waterfall(tasks, function(){
    window.jasmine.getEnv().execute();
  });
})();
github andrewrk / groovebasin / lib / library.js View on Github external
function startScan(self) {
  if (self.library != null) return;

  self.library = {};
  console.log('starting library scan');
  var start_time = new Date();
  var pend = new Pend();
  pend.max = 20;
  var musicPath = maybeAddTrailingSlash(self.musicLibPath);
  var walker = walk.walk(musicPath);
  walker.on('file', function(filename, stat) {
    if (ignoreFile(filename)) return;
    pend.go(function(cb) {
      var stream = fs.createReadStream(filename);
      var parser = new MusicMetadataParser(stream);
      var localFile = path.relative(self.musicLibPath, filename);
      var metadata = null;
      parser.on('mime', function(mime) {
        // this event is fired when we know that it is an audio file
        // we will add it to the library whether or not it has metadata.
        metadata = defaultMetaData;
      });
      parser.on('metadata', function(md) {
        metadata = md;
      });
      parser.on('done', function() {
github electron / electron / spec-main / index.js View on Github external
mochaOptions.reporterOptions = {
      reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
    }
  }
  const mocha = new Mocha(mochaOptions)

  if (!process.env.MOCHA_REPORTER) {
    mocha.ui('bdd').reporter('tap')
  }
  mocha.timeout(30000)

  if (argv.grep) mocha.grep(argv.grep)
  if (argv.invert) mocha.invert()

  // Read all test files.
  const walker = require('walkdir').walk(__dirname, {
    no_recurse: true
  })

  // This allows you to run specific modules only:
  // npm run test -match=menu
  const moduleMatch = process.env.npm_config_match
    ? new RegExp(process.env.npm_config_match, 'g')
    : null

  const testFiles = []
  walker.on('file', (file) => {
    if (/-spec\.[tj]s$/.test(file) &&
        (!moduleMatch || moduleMatch.test(file))) {
      testFiles.push(file)
    }
  })
github electron / electron / spec / static / index.html View on Github external
}
  const mocha = new Mocha(mochaOptions)

  if (!process.env.MOCHA_REPORTER) {
    mocha.ui('bdd').reporter('tap')
  }
  mocha.timeout(30000)

  const query = Mocha.utils.parseQuery(window.location.search || '')
  if (query.grep) mocha.grep(query.grep)
  if (query.invert) mocha.invert()

  const files = query.files ? query.files.split(',') : undefined

  // Read all test files.
  const walker = require('walkdir').walk(path.dirname(__dirname), {
    no_recurse: true
  })

  // This allows you to run specific modules only:
  // npm run test -match=menu
  const moduleMatch = process.env.npm_config_match
    ? new RegExp(process.env.npm_config_match, 'g')
    : null

  const testFiles = []
  walker.on('file', (file) => {
    if (/-spec\.js$/.test(file) && (!moduleMatch || moduleMatch.test(file))) {
      testFiles.push(file)
    }
  })
github Syncano / syncano-node / packages / cli / src / utils / sockets / utils.js View on Github external
const searchForSockets = (socketsPath, maxDepth = 3) => {
  if (!fs.existsSync(socketsPath)) {
    return []
  }
  const sockets = []

  const options = {
    'follow_symlinks': true,
    'max_depth': maxDepth
  }

  // TODO: optimize only diging deeper scoped modues
  walkdir.sync(socketsPath, options, (walkPath, stat) => {
    if (walkPath.match(/socket.yml$/) && !path.dirname(walkPath).match(/\/\./)) {
      const socket = YAML.load(fs.readFileSync(walkPath, 'utf8')) || {}
      sockets.push([walkPath, socket])
    }
  })

  return sockets
}

walkdir

Find files simply. Walks a directory tree emitting events based on what it finds. Presents a familiar callback/emitter/a+sync interface. Walk a tree of any depth.

MIT
Latest version published 5 years ago

Package Health Score

73 / 100
Full package analysis