code-dir

0.3.0 • Public • Published

code-dir Build status for code-dir on Circle CI.

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.

  1. Fork it.
  2. Make a feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

MPL-2.0 © Seth Holladay

Go make something, dang it.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    1
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i code-dir

Weekly Downloads

1

Version

0.3.0

License

MPL-2.0

Last publish

Collaborators

  • sholladay