node-project-dir
Search the project's root directory.
Install
npm install project-dir
Documentation
How to use
myProject/
├── .git
├── node_modules
├── aaaa
│ └── bbbb
└── abcd
└── efgh
require
const ProjectDir = ;
on NodeJS
const myProject = './' 'node_modules' console; // => '/home/user/myProject'console; // => '/home/user/myProject'
on git repository
const myProject = './' '.git' console; // => '/home/user/myProject'console; // => '/home/user/myProject'
make sure NodeJS with git repository
const myProject = './' 'node_modules' '.git' console; // => '/home/user/myProject'console; // => '/home/user/myProject'
set basename
console; // => ['node_modules', '.git'] myProjectbasename = '.git' console; // => '.git'
set basedir
myProjectbasedir = './abcd'; // => '/home/user/myProject'myProjectwd; // => '/home/user/myProject/abcd' myProjectbasedir = './abcd/efgh'; // => '/home/user/myProject'myProjectwd; // => '/home/user/myProject/abcd/efgh'
set wd (working directory)
// rootmyProjectwd = '/'; // => '/home/user/myProject' // relative pathmyProjectwd = 'abcd'; // => '/home/user/myProject/abcd'myProjectwd = 'efgh'; // => '/home/user/myProject/abcd/efgh'myProjectwd = '../'; // => '/home/user/myProject/abcd' myProjectwd = '/aaaa'; // => '/home/user/myProject/aaaa'
resolve
myProjectwd = '/';myProject; // => '/home/user/myProject/abcd' myProjectwd = '/aaaa';myProject; // => '/home/user/myProject/aaaa/bbbb' myProjectwd = '/aaaa';myProject; // => '/home/user/myProject/abcd'
retrieve
myProject; // => '/abcd' myProject; // => '/abcd/efgh' myProject; // => '/' myProject; // => 'null'
parse
myProject;
root: '/home/user/myProject' names: '.git' wd: '/home/user/myProject' path: 'abcd' abs: '/abcd' realPath: '/home/user/myProject/abcd'
myProjectwd = '/abcd';myProject;
root: '/home/user/myProject' names: '.git' wd: '/home/user/myProject/abcd' path: 'efgh' abs: '/abcd/efgh' realPath: '/home/user/myProject/abcd/efgh'
equal
myProjectwd = '/abcd'console; // => '/home/user/myProject/abcd' myProject; // => truemyProject; // => truemyProject; // => false
toRoot
let paths = ;myProject;console; // => ['/abcd/efgh', '/abcd']
API
Don't confuse ProjectPath
argument. It has a difference meaning with normal path.
When the argument takes ProjectPath
, do not use absolute path in real file system.
This moudle handles root as sub directory of base directory when argument is ProjectPath
.
eg. If base directory is "/home/user/abcd", the Path
's "/efgh" means "/efgh" and the ProjectPath
's "/efgh" means "/home/user/abcd/efgh".
constructor(<Path>, <Query>)
: Search aQuery
matched directory fromPath
to root path. and set basedir.
getter/setter
basename <Query>
: get/set basename for dominating file.basedir <Path>
: get/set project's base directory.wd <Path>
: get/set project's working directory.
methods
resolve(<ProjectPath>) -> <Path>
: Resolving path based on basedirretrieve(<Path>) -> <ProjectAbsPath>
: Retrieving project path from absolute real path.parse(<ProjectPath>) -> <Object>
: parsing path based on basedir. below output is result of path(+ sign meanspath.resolve
, * sign meanspath.relative
, path means argument, others are property name).
root: <basedir> names: <basename> wd: <wd> path: <wd*path> abs: <basedir*wd+path> realPath: <wd+path>
equal(<ProjectPath>, <ProjectPath>) -> <boolean>
: Compare with two project path is same.toRoot(<ProjectPath>, [<Object>, ]<Function>)
: Recursively access fromProjectPath
tobasedir
and send an argument of current path toFunction
.
Unit Test
Dev Depencencies
- mocha : unit test framework
- one-mocha : mocha tester generating module
- js-doc : documentation generator
- minami : jsdoc template
Test
npm test