common-roots
Version:
find root directories (containing .git or other)
35 lines (22 loc) • 1.55 kB
Markdown
# common-roots
**Given some files, find their root directories (containing some identifying file like `.git`, `package.json`, etc). For files in the same root directory, it does a single lookup.**
[](https://www.npmjs.org/package/common-roots) [](https://www.npmjs.org/package/common-roots) [](http://travis-ci.org/vweevers/common-roots) [](https://ci.appveyor.com/project/vweevers/common-roots) [](https://david-dm.org/vweevers/common-roots)
## example
```js
const roots = require('common-roots')
const files = ['/repo1/a.js', '/repo2/lib', '/repo1/a/b/c']
roots(files, '.git', (err, roots) => {
// roots is ['/repo1', '/repo2']
})
```
## `roots(files, id, done)`
- files: array of files (relative paths are resolved from cwd)
- id: relative path to some file that identifies the root directory
- callback: receives an error (if one of the files has no root directory) or an array of absolute root directories.
## install
With [npm](https://npmjs.org) do:
```
npm install common-roots
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers