How to use pathwatcher - 10 common examples

To help you get started, we’ve selected a few pathwatcher 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 jupyter / atom-notebook / lib / notebook-editor.js View on Github external
loadNotebookFile(uri) {
      // console.log('LOAD NOTEBOOK FILE');
      this.file = new File(uri);
      let parsedFile = this.parseNotebookFile(this.file);
      if (parsedFile.cells) {
        parsedFile.cells = parsedFile.cells.map(cell => {
          cell.metadata.id = uuid.v4();
          cell.metadata.focus = false;
          return cell;
        });
      } else {
        parsedFile.cells = [
         {
          cell_type: 'code',
          execution_count: null,
          metadata: {
           collapsed: true
          },
          outputs: [],
github atom / atom / src / git-repository-provider.js View on Github external
function findGitDirectorySync(directory) {
  // TODO: Fix node-pathwatcher/src/directory.coffee so the following methods
  // can return cached values rather than always returning new objects:
  // getParent(), getFile(), getSubdirectory().
  let gitDir = directory.getSubdirectory('.git');
  if (typeof gitDir.getPath === 'function') {
    const gitDirPath = pathFromGitFileSync(gitDir.getPath());
    if (gitDirPath) {
      gitDir = new Directory(directory.resolve(gitDirPath));
    }
  }
  if (
    typeof gitDir.existsSync === 'function' &&
    gitDir.existsSync() &&
    isValidGitDirectorySync(gitDir)
  ) {
    return gitDir;
  } else if (directory.isRoot()) {
    return null;
  } else {
    return findGitDirectorySync(directory.getParent());
  }
}
github atom / atom / src / git-repository-provider.js View on Github external
async function isValidGitDirectory(directory) {
  // To decide whether a directory has a valid .git folder, we use
  // the heuristic adopted by the valid_repository_path() function defined in
  // node_modules/git-utils/deps/libgit2/src/repository.c.
  const commonDirFile = directory.getSubdirectory('commondir');
  let commonDir;
  if (await commonDirFile.exists()) {
    const commonDirPathBuff = await fs.readFile(commonDirFile.getPath());
    const commonDirPathString = commonDirPathBuff.toString().trim();
    commonDir = new Directory(directory.resolve(commonDirPathString));
    if (!(await commonDir.exists())) {
      return false;
    }
  } else {
    commonDir = directory;
  }
  return (
    (await directory.getFile('HEAD').exists()) &&
    (await commonDir.getSubdirectory('objects').exists()) &&
    commonDir.getSubdirectory('refs').exists()
  );
}
github alexcorre / git-blame / lib / git-blame.js View on Github external
function toggleBlame() {
  var editor = atom.workspace.getActivePaneItem()
  if (!editor) return;

  // An unsaved file has no filePath
  filePath = editor.getPath()
  if (!filePath) return;

  // blaming an empty file is useless
  if (editor.isEmpty()) return;

  return atom.project.repositoryForDirectory(new Directory(path.dirname(filePath))).then(
    function(projectRepo) {
      // Ensure this project is backed by a git repository
      if (!projectRepo) {
        errorController.showError('error-not-backed-by-git');
        return;
      }

      if (!(projectRepo.path in projectBlamers)) {
        projectBlamers[projectRepo.path] = new Blamer(projectRepo);
      }

      BlameViewController.toggleBlame(projectBlamers[projectRepo.path]);
    });
}
github atom / atom / src / git-repository-provider.js View on Github external
async function findGitDirectory(directory) {
  // TODO: Fix node-pathwatcher/src/directory.coffee so the following methods
  // can return cached values rather than always returning new objects:
  // getParent(), getFile(), getSubdirectory().
  let gitDir = directory.getSubdirectory('.git');
  if (typeof gitDir.getPath === 'function') {
    const gitDirPath = await pathFromGitFile(gitDir.getPath());
    if (gitDirPath) {
      gitDir = new Directory(directory.resolve(gitDirPath));
    }
  }
  if (
    typeof gitDir.exists === 'function' &&
    (await gitDir.exists()) &&
    isValidGitDirectory(gitDir)
  ) {
    return gitDir;
  } else if (directory.isRoot()) {
    return null;
  } else {
    return findGitDirectory(directory.getParent());
  }
}
github nylas-mail-lives / nylas-mail / packages / client-app / spec / n1-spec-runner / master-before-each.es6 View on Github external
_resetNylasEnv() {
    NylasEnv.workspaceViewParentSelector = '#jasmine-content';

    // Don't actually write to disk
    spyOn(NylasEnv, 'saveSync');

    // prevent specs from modifying N1's menus
    spyOn(NylasEnv.menu, 'sendToBrowserProcess');

    FocusedPerspectiveStore._current = MailboxPerspective.forNothing();

    spyOn(pathwatcher.File.prototype, "detectResurrectionAfterDelay").andCallFake(function detectResurrection() {
      return this.detectResurrection();
    });
  }
github nylas-mail-lives / nylas-mail / spec / n1-spec-runner / master-before-each.es6 View on Github external
_resetNylasEnv() {
    NylasEnv.testOrganizationUnit = null;

    NylasEnv.workspaceViewParentSelector = '#jasmine-content';

    // Don't actually write to disk
    spyOn(NylasEnv, 'saveSync');

    // prevent specs from modifying N1's menus
    spyOn(NylasEnv.menu, 'sendToBrowserProcess');

    FocusedPerspectiveStore._current = MailboxPerspective.forNothing();

    spyOn(pathwatcher.File.prototype, "detectResurrectionAfterDelay").andCallFake(function detectResurrection() {
      return this.detectResurrection();
    });
  }
github atom / github / lib / git / git-service.js View on Github external
this.gitRepo.getPath().then(gitDirPath => {
      // Watch the git dir path. We're really just interested in the index file,
      // but watching it directly is Tricky because it's written atomically
      // which looks like a delete + create.
      const watcher = PatchWatcher.watch(gitDirPath, () => this.didChange())
      this.subscriptions.add(new Disposable(() => watcher.close()))
    })
  }
github atom / github / lib / git / git-service.js View on Github external
this.gitRepo.getPath().then(gitDirPath => {
      // Watch the git dir path. We're really just interested in the index file,
      // but watching it directly is Tricky because it's written atomically
      // which looks like a delete + create.
      const watcher = PatchWatcher.watch(gitDirPath, () => this.didChange())
      this.subscriptions.add(new Disposable(() => watcher.close()))
    })
  }
github atom / atom / spec / git-repository-provider-spec.js View on Github external
it('resolves with null', async () => {
        const dirPath = temp.mkdirSync('dir');
        fs.writeFileSync(path.join(dirPath, '.git', 'objects'), '');
        fs.writeFileSync(path.join(dirPath, '.git', 'HEAD'), '');
        fs.writeFileSync(path.join(dirPath, '.git', 'refs'), '');

        const directory = new Directory(dirPath);
        const repo = await provider.repositoryForDirectory(directory);
        expect(repo).toBe(null);
      });
    });

pathwatcher

Watch files and directories for changes

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages