jussi-kalliokoski / atom-npm-plus

npm integration for atom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Atom Multiple folders support

o-evin opened this issue · comments

At this moment there is no way to execute commands on any project folder except the first one.

That may be a great option to run npm commands based on a current file's project selection instead of a first matched project path.

function getPackageDir () {
    const editor = atom.workspace.getActivePaneItem();

    const file = editor ? editor.buffer.file : null;
    const filePath = file ? file.path : null;

    if(filePath) {
      const location = atom.project.relativizePath(filePath);

      if(location !== null) {
        return location[0];
      }
    }

    const projectPaths = atom.project.getPaths();

    for ( path of projectPaths ) {
        const filename = join(path, PACKAGE_JSON_FILENAME);
        if ( !isPackageJson(filename) ) { continue; }
        return path;
    }

    return null;
}