How to use walk-sync - 10 common examples

To help you get started, we’ve selected a few walk-sync 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 nodejs / i18n / script / collect.js View on Github external
async function getDocsForNodeVersion (major, version) {
  const docDir = path.join(__dirname, `../content/${major}/en-US/doc`)
  const tempDir = path.join(__dirname, `../temp/${major}`)

  // TODO exit early if docs for this version have already been downloaded

  // download repo bundle and extract to a temporary directory
  const tarballUrl = `https://github.com/nodejs/node/archive/${version}.tar.gz`
  console.log('downloading', tarballUrl)
  await download(tarballUrl, tempDir, {extract: true})

  // move docs from temp dir to this repo
  const tempDocDir = path.join(tempDir, `node-${version.replace('v', '')}`, 'doc')

  // removes files other than markdown
  walk(tempDocDir, {directories: false})
    .filter(file => path.extname(file.relativePath.toLowerCase()) !== '.md')
    .forEach(file => fs.unlinkSync(path.join(tempDocDir, file.relativePath)))

  await fs.copy(tempDocDir, docDir)

  fs.remove(tempDir)
}
github jex / jex / lib / load-pages.js View on Github external
module.exports = function loadPages (jexConfig) {
  const { pagesDirectory, pagesIncludePatterns: globs, pagesExcludePatterns: ignore } = jexConfig

  const pages = walk(pagesDirectory, { globs, ignore, directories: false })
    .map(entry => new Page(entry, jexConfig))

  // add named keys to the array for fast object-like URL reference
  for (const page of pages) {
    page.permalinks.forEach(permalink => {
      pages[permalink] = page
    })
  }

  return pages
}
github ef4 / ember-browserify / lib / stub-generator.js View on Github external
StubGenerator.prototype.build = function() {
  var start = Date.now();
  var inputPath = this.inputPaths[0];
  var previous  = this._previousTree;

  // get patchset
  var input = walkSync.entries(inputPath, [ '**/*.js' ]);

  debug('input: %d', input.length);

  var next = this._previousTree = FSTree.fromEntries(input);
  var patchset = previous.calculatePatch(next);

  debug('patchset: %d', patchset.length);

  var applyPatch = Date.now();

  // process patchset
  patchset.forEach(function(patch) {
    var operation = patch[0];
    var path      = patch[1];
    var fullPath  = inputPath + '/' + path;
github linkedin / css-blocks / packages / @css-blocks / broccoli / src / Aggregate.ts View on Github external
build() {
    let output = this.outputPath;
    let input = this.inputPaths[0];
    let { id, css } = this.transport;

    // Test if anything has changed since last time. If not, skip trying to update tree.
    let newFsTree = FSTree.fromEntries(walkSync.entries(input));
    let diff = this.previous.calculatePatch(newFsTree);

    // Auto-discover common preprocessor extensions.
    if (!this._out) {
      let prev = path.parse(path.join(input, this.out));
      let origExt = prev.ext;
      prev.base = ""; // Needed for path.format to register ext change
      for (let ending of COMMON_FILE_ENDINGS) {
        prev.ext = ending;
        if (fs.existsSync(path.format(prev))) { break; }
        prev.ext = origExt;
      }
      let out = path.parse(this.out);
      out.base = ""; // Needed for path.format to register ext change
      out.ext = prev.ext;
      this._out = path.format(out);
github typed-ember / ember-cli-typescript / ts / addon.ts View on Github external
_checkAddonAppFiles() {
    // Emit a warning for addons that are under active development...
    let isDevelopingAddon = !this.app && (this.parent as Addon).isDevelopingAddon();

    // ...and are at the root of the project (i.e. not in-repo)...
    let isRootAddon = this.parent.root === this.project.root;

    // ...and have .ts files in their `app` directory.
    let appDir = `${this.parent.root}/app`;
    if (isDevelopingAddon && isRootAddon && fs.existsSync(appDir)) {
      let tsFilesInApp = walkSync(appDir, { globs: ['**/*.ts'] });
      if (tsFilesInApp.length) {
        this.ui.writeWarnLine(
          `found .ts files in ${appDir}\n` +
            "ember-cli-typescript only compiles files in an addon's `addon` folder; " +
            'see https://github.com/typed-ember/ember-cli-typescript/issues/562'
        );
      }
    }
  },
github embroider-build / embroider / packages / core / src / app-entrypoint.ts View on Github external
private writeAppJS(config: any) {
    let mainModule = join(this.outputPath, this.app.isModuleUnification ? 'src/main' : 'app');
    // standard JS file name, not customizable. It's not final anyway (that is
    // up to the final stage packager). See also updateHTML in app.ts for where
    // we're enforcing this in the HTML.
    let appJS = join(this.outputPath, `assets/${this.app.name}.js`);

    // for the app tree, we take everything
    let lazyModules = walkSync(this.inputPaths[1], {
      globs: ['**/*.{js,hbs}'],
      ignore: ['tests/**'],
      directories: false
    }).map(specifier => {
      let noJS = specifier.replace(/\.js$/, '');
      let noHBS = noJS.replace(/\.hbs$/, '');
      return {
        runtime: `${config.modulePrefix}/${noHBS}`,
        buildtime: `../${noJS}`
      };
    });

    // for the src tree, we can limit ourselves to only known resolvable
    // collections
    todo("app src tree");
github ef4 / ember-auto-import / ts / broccoli-append.ts View on Github external
private appendedPatchset() {
    let input = walkSync.entries(this.appendedDir);
    let passthroughEntries = input
      .map(e => {
        let first = e.relativePath.split('/')[0];
        let remapped = this.passthrough.get(first);
        if (remapped) {
          let o = Object.create(e);
          o.relativePath = e.relativePath.replace(new RegExp('^' + first), remapped);
          o.isPassthrough = true;
          o.originalRelativePath = e.relativePath;
          return o;
        }
      }).filter(Boolean);

    let previous = this.previousAppendedTree;
    let next = (this.previousAppendedTree = FSTree.fromEntries(input));
    return { patchset: previous.calculatePatch(next), passthroughEntries };
github phodal / adr / src / lib / update.ts View on Github external
function updateNameByTitle (): void {
  let files = walkSync.entries(savePath, { globs: ['**/*.md'], ignore: ['README.md'] })

  files.forEach(function (file) {
    let fileName = file.relativePath
    let fileData = fs.readFileSync(savePath + fileName, 'utf8')
    let firstLine = fileData.split('\n')[0]
    let title = firstLine.replace(/#\s\d+\.\s/g, '')
    let indexRegex = /#\s(\d+)\.\s/.exec(firstLine)
    let oldIndex
    if (!indexRegex) {
      oldIndex = Utils.getIndexByString(fileName)
      if (!oldIndex) {
        return
      }
    } else {
      oldIndex = indexRegex[1]
    }
github denali-js / core / dist / runtime / container.js View on Github external
registerDir(dirpath, typeName) {
    let paths = walk(dirpath);
    paths.forEach((filepath) => {
      let absolutepath = path.join(dirpath, filepath);
      let moduleName = filepath.replace(JS_EXT, '');
      if (fs.statSync(absolutepath).isFile() && JS_EXT.test(absolutepath)) {
        this.register(typeName + '/' + moduleName, require(absolutepath));
      }
    });
  },
github vinz243 / cassette / src / server / features / scanner / tree.js View on Github external
const getFolderEntries = module.exports.getFolderEntries = (path) => {
   return walkSync.entries(path)
}

walk-sync

Get an array of recursive directory contents

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular walk-sync functions

Similar packages