ModuleParser

ModuleParser

new ModuleParser()

The ModuleParser is a utility class designed to loop through and iterate
on a directory and pull out of each .js file found, any classes or exports
that extend from GQLBase or a child of GQLBase.

Since:
  • 2.7.0
Source:

Classes

exports.ModuleParser

Methods

(static) exports.ModuleParser#importClass()

A string denoting the directory on disk where ModuleParser should be
searching for its classes.

Source:

⌾⠀findGQLBaseClasses(contents, gqlDefinitions) → {Set.<mixed>}

Given an object, typically the result of a require() or import
command, iterate over its contents and find any GQLBase derived
exports. Continually, and recursively, build this list of classes out
so that we can add them to a GQLExpressMiddleware.

Since:
  • 2.7.0
Source:
Parameters:
Name Type Description
contents Object

the object to parse for properties extending
from GQLBase

gqlDefinitions Array.<GQLBase>

the results, allowed as a second
parameter during recursion as a means to save state between calls

Returns:
Type:
Set.<mixed>

a unique set of values that are currently being
iterated over. Passed in as a third parameter to save state between calls
during recursion.

⌾⠀importClass(filePath) → {Object}

Given a file path, this method will attempt to import/require the
file in question and return the object it exported; whatever that
may be.

Since:
  • 2.7.0
Source:
Parameters:
Name Type Description
filePath string

a path to pass to require()

Returns:
Type:
Object

the object, or undefined, that was returned when
it was require()'ed.

(async) ⌾⠀parse() → {Promise.<Array.<GQLBase>>}

This method takes a instance of ModuleParser, initialized with a directory,
and walks its contents, importing files as they are found, and sorting
any exports that extend from GQLBase into an array of such classes
in a resolved promise.

Since:
  • 2.7.0
Source:
Returns:
Type:
Promise.<Array.<GQLBase>>

an array GQLBase classes, or an empty
array if none could be identified.

(async) ⌾⠀parseSync() → {Array.<GQLBase>}

This method takes a instance of ModuleParser, initialized with a directory,
and walks its contents, importing files as they are found, and sorting
any exports that extend from GQLBase into an array of such classes

Since:
  • 2.7.0
Source:
Returns:
Type:
Array.<GQLBase>

an array GQLBase classes, or an empty
array if none could be identified.

(async, inner) walk(dir, filelist) → {Promise.<Array.<string>>}

Recursively walks a directory and returns an array of asbolute file paths
to the files under the specified directory.

Since:
  • 2.7.0
Source:
Parameters:
Name Type Description
dir string

string path to the top level directory to parse

filelist Array.<string>

an array of existing absolute file paths,
or if not parameter is supplied a default empty array will be used.

Returns:
Type:
Promise.<Array.<string>>

an array of existing absolute file paths
found under the supplied dir directory.

(async, inner) walkSync(dir, filelist) → {Array.<string>}

Recursively walks a directory and returns an array of asbolute file paths
to the files under the specified directory. This version does this in a
synchronous fashion.

Since:
  • 2.7.0
Source:
Parameters:
Name Type Description
dir string

string path to the top level directory to parse

filelist Array.<string>

an array of existing absolute file paths,
or if not parameter is supplied a default empty array will be used.

Returns:
Type:
Array.<string>

an array of existing absolute file paths found
under the supplied dir directory.

(inner) ⎆⠀constructor(directory)

The constructor

Source:
Parameters:
Name Type Description
directory string

a string path to a directory containing the
various GQLBase extended classes that should be gathered.