code-dir
v0.3.0
Published
Find the parent directory for top level projects.
Downloads
7
Maintainers
Readme
code-dir
Find the parent directory for top level projects.
Why?
- Simple downward search algorithm.
- Useful for operating on multiple projects.
- The end user likely visits here a lot.
Install
npm install code-dir --save
Usage
Get it into your program.
const codeDir = require('code-dir');
Find the directory where the end user stores their projects.
codeDir().then((dirPath) => {
console.log(dirPath); // => '/Users/sholladay/Code/personal'
});
API
codeDir(cwd)
Returns a Promise
for the path of the topmost project's parent directory. A project is a directory that contains either .git
or package.json
.
cwd
Type: string
Default: process.cwd()
Current working directory the search is based on. This is the deepest directory that could be returned. If neither it nor any of its parent directories are projects, then as a last resort, its children are checked to determine if any of them are projects, in case the working directory itself is the code directory, since that is a common case.
Contributing
See our contributing guidelines for more details.
- Fork it.
- Make a feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
License
Go make something, dang it.