ProjectDir

index~ ProjectDir

project-dir main class

Constructor

new ProjectDir()

Version:
  • 0.1.4
Since:
  • 0.0.1
Source:

Methods

constructor(currentPath, basename)

Generating new project directory object.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
currentPath Path Starting point for search base directory. This path must be an existing file or directory.
basename Query Dominating file or directory names.
Example
const myProject = new ProjectDir('./', 'node_modules')

const myProject2 = new ProjectDir('./', '.git')

const myProject3 = new ProjectDir('./', ['node_modules', '.git']) // has node_modules and .git directory

equal(_path1, _path2) → {boolean}

Check same directory in project directory
Version:
  • 0.1.4
Since:
  • 0.1.2
Source:
Parameters:
Name Type Description
_path1 ProjectPath | ProjectAbsPath To check project path
_path2 ProjectPath | ProjectAbsPath To check project path
Throws:
Type error
Type
Error
Returns:
Type:
boolean
If same directory, returns true
Example
myProject.wd = '/abcd'
console.log(myProject.wd); // => '/home/user/myProject/abcd'

myProject.equal('/abcd/efgh', 'efgh'); // => true
myProject.equal('/aaaa', '../aaaa'); // => true
myProject.equal('/abcd', 'abcd'); // => false

fromRoot(_path, func) → {Path}

Go to _path from root path of current project.
Version:
  • 0.1.4
Since:
  • 0.1.4
Source:
Parameters:
Name Type Description
_path ProjectPath | ProjectAbsPath End point of project path.
func function Recursively executed function. the argument is current path.
Returns:
Type:
Path
_path directory of project if no breaks.

get_basedir() → {Path}

Get base directory of current project.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Returns:
Type:
Path
Current base directory's absolute path.
Example
myProject.basedir // => '/home/user/myProject'

get_basename() → {Path}

Get basename of current project
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Returns:
Type:
Path
Current basenames.
Example
myProject.basename // => ['.git', 'package.json']

get_wd() → {Path}

Get current working directory.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Returns:
Type:
Path
Current working directory's absolute path.
Example
myProject.wd // => '/home/user/myProject/abcd'

parse(_path) → {Object}

Parsing a path.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
_path ProjectPath to parse path.
Throws:
_path is not a string type.
Type
Error
Returns:
Type:
Object
parsed path's object.
Example
myProject.parse('/abcd');
// {
//   root: '/home/user/myProject',
//   names: '.git',
//   wd: '/home/user/myProject',
//   path: 'abcd',
//   abs: '/abcd',
//   realPath: '/home/user/myProject/abcd'
// }

myProject.wd = '/abcd';
myProject.parse('efgh');
// {
//   root: '/home/user/myProject',
//   names: '.git',
//   wd: '/home/user/myProject/abcd',
//   path: 'efgh',
//   abs: '/abcd/efgh',
//   realPath: '/home/user/myProject/abcd/efgh'
// }

resolve(_path) → {null|Path}

Resolving the path based on current project's base directory.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
_path ProjectPath to resolve path.
Throws:
_path is not a string type.
Type
Error
Returns:
Type:
null | Path
resolved path or null out of range in root path.
Example
myProject.wd = '/';
myProject.resolve('abcd'); // => '/home/user/myProject/abcd'

myProject.wd = '/aaaa';
myProject.resolve('bbbb'); // => '/home/user/myProject/aaaa/bbbb'

myProject.wd = '/aaaa';
myProject.resolve('/abcd'); // => '/home/user/myProject/abcd'

retrieve(_path) → {ProjectAbsPath}

Retrieve project path from absolute real path.
Version:
  • 0.1.4
Since:
  • 0.0.5
Source:
Parameters:
Name Type Description
_path AbsPath absolute real path.
Throws:
If not a string type, If not an absolute path.
Type
Error
Returns:
Type:
ProjectAbsPath
absolute project path.
Example
myProject.retrieve('/home/user/myProject/abcd'); // => '/abcd'

myProject.retrieve('/home/user/myProject/abcd/efgh'); // => '/abcd/efgh'

myProject.retrieve('/home/user/myProject'); // => '/'

myProject.retrieve('/home/user'); // => 'null'

set_basedir(_path)

Set project's base directory.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
_path Path Strting point for search base directory.
Throws:
Failed searching base directory of project.
Type
Error
Example
myProject.basedir = './abcd'; // => '/home/user/myProject'
myProject.wd; // => '/home/user/myProject/abcd'

myProject.basedir = './abcd/efgh'; // => '/home/user/myProject'
myProject.wd; // => '/home/user/myProject/abcd/efgh'

set_basename(basename)

Set dominating file or directory names.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
basename Query Dominating file or directory names.
Throws:
Not a Query type.
Type
Error
Example
myProject.basename = ['.git', 'package.json']

set_wd(_path)

Set working directory based on current project's base directory.
Version:
  • 0.1.4
Since:
  • 0.0.1
Source:
Parameters:
Name Type Description
_path ProjectPath Sub path of base directory.
Throws:
Out of range in root path.
Type
Error
Example
// root
myProject.wd = '/'; // => '/home/user/myProject'

// relative path
myProject.wd = 'abcd'; // => '/home/user/myProject/abcd'
myProject.wd = 'efgh'; // => '/home/user/myProject/abcd/efgh'
myProject.wd = '../'; // => '/home/user/myProject/abcd'

myProject.wd = '/aaaa'; // => '/home/user/myProject/aaaa'

toRoot(_path, func) → {Path}

Go to root directory
Version:
  • 0.1.4
Since:
  • 0.1.2
Source:
Parameters:
Name Type Description
_path ProjectPath | ProjectAbsPath Start point of project path.
func function Recursively executed function. the argument is current path.
Returns:
Type:
Path
Root directory of project.