PathResolver

PathResolver

Class that creates a suite of methods cna collections useful for resolving paths within a project. Includes a directory resolver, which creates relative path resolvers for each directory in a given directory map. Support for resolver renaming and alias generation, which formats the resolver name to reflect the alias as the root rather than the full path. Aliases are suitable for use in webpack and similar libraries.

Constructor

new PathResolver(rootPath|paths, paths|optionsnullable, optionsnullable)

Creates an instance of PathResolver. Passes arguments to PathResolver#initialize to be processed.
Author:
Source:
Parameters:
Name Type Attributes Description
rootPath|paths String | Object Projects root path or Object mapping projects directory structure.
paths|options Object <nullable>
Object mapping projects directory structure or options object.
options Object <nullable>
Options object.

Members

(static, constant) defaultOptions

Properties:
Name Type Description
aliasRoot String Namespace, or property name, that should contain the alias map.
depth Number How many directory levels should be processed. Set to -1 for inifinite depth.
duplicateAliases Boolean Should both the alias and non alias resolvers be used when an alias is present.
namespace String Namespace, or property name, that should contain the directory resolver.
paths Object Object mapping projects directory structure.
resolverPrefix String Unvalidated options object.
rootPath String Root path all resolver keys and aliases will be relative to.
Source:

(static, constant) defaultConfig

Each directory can contain a config option. These options are defined by an '_' property within the directory map.
Properties:
Name Type Description
name String Rename current directory's resolver function, affecting children as well.
alias String Rename current directory's resolver function and set as the root scope, affecting children as well.
ignore Boolean Does not export the current directory as a resolver or as an alias.
duplicateAliases Boolean Does not export the current directory or it's children as a resolver or alias.
Source:
Example
let map = new PathResolver({
    _: { alias: '@root' }            // resolveRoot() -> path/to/project
    src: { _: { name: source } },    // resolveSource() -> path/to/project/src
    dist: {  _: { ignore: true },    // this route is ignored, children still render
        css: {}                      // resolveDistCss() -> path/to/project/src/css
    },
    libs: {  _: { ignoreBranch: true } // *this and child routes ignored
        ...
    }
})

Methods

initialize(rootPath|paths, paths|optionsnullable, optionsnullable)

Configures an instance of path resolver. Can be used after a PathResolver instance is created to defer the configuration. Passes arguments to the PathResolver#initialize function to be processed and validated and sets the options instance property. Then passes on the configured rootPath, paths object, and designated fileRoot
Source:
Parameters:
Name Type Attributes Description
rootPath|paths String | Object Projects root path or Object mapping projects directory structure.
paths|options Object <nullable>
Object mapping projects directory structure or options object.
options Object <nullable>
Options object.

makeRelativeResolver(rootPathnon-null) → {function}

Creates a resolver function, relative to the given path.
Source:
Parameters:
Name Type Description
rootPath String Absolute path which the resolver will be relative to.
Returns:
Type:
function
Returns a function that returns a path relative to rootPath.
Example
let resolver = makeRelativeResolver('absolute/path')
let path = resolver('index.html')

console.log(path) // absolute/path/index.html

toString() → {function}

Gets a string representation of the resolver incuding a list of all resolve functions and their resolved paths, as well as a list of aliases and their resolved paths.
Source:
Returns:
Type:
function
Returns a string representation of the resolver..

printDetails() → {function}

Prints out a string representation of the resolver, the result of the toString method. Includes a list of all resolve functions and their resolved paths, as well as a list of aliases and their resolved paths.
Source:
See:
Returns:
Type:
function
Returns a string representation of the resolver..