Table of Contents
Loader Module
Command loader.
Component of the jsr library.
Install
npm i jsr-loader
API
var load = require('jsr-loader')
, opts = {commands: ['./commands']};
load(opts, function(err, commands) {
if(err) return console.error(err.message);
console.dir(commands);
})
Options
The load
method accepts an options
object that supports the following properties:
-
commands
: Files or directories to search for commands (array). -
override
: Allow duplicate commands, last command wins (boolean).
Commands
The commands
array is a list of files and directories to search for commands to load, when the list contains a directory it is recursively searched for files. Command files must have a .js
extension, files with other extensions will be ignored.
Commands may export either an instance of Command
or a constructor function
that should extend Command
. The command loader is quite strict about what is acceptable a valid Command
is required (class or instance) and the command must have an associated definition. When exporting a constructor a class-level definition
property should be exposed referencing the command definition, this is passed to the constructor when instantiating the command.
Internally commands are stored as an object by command definition name, if override
is not specified an error is thrown otherwise the the rule is last command wins.
The majority of the default commands export instances of Command
, however sometimes a command needs to extend the functionality of another command, in this case the super class exports the constructor. See the RENAME
and RENAMENX
command handlers for an example.
The contract for command files is defined by the exec module and you should extend those classes when creating custom commands.
Developer
Test
Tests are not included in the package, clone the repository:
npm test
Documentation
To generate all documentation:
npm run docs
Readme
To build the readme file from the partial definitions (requires mdp):
npm run readme
License
Everything is MIT. Read the license if you feel inclined.
Generated by mdp(1).