Methods
command(base:, actions:, opts:)
Parse command line arguments and execute actions based on the specified commands.
Uses commander.js to provide -V / --version to be displayed version number,
and -h / --help to be displayed help info.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
base: |
String
|
base directory where the client module is located, used as a base directory to read command file and package.json file, ideally the value would be the client's __dirname |
actions: |
Object
|
action function for each command in format: { command: { action: function () {} }}, the command name in actions object is then mapped to the command name specified in commandFile |
opts: |
Object
|
optional - commandFile: relative path to command file from base directory, defaults to 'conf/commands.json' |
exec(command:, fallthrough:, cb:)
Execute a one-liner command.
The output emitted on stderr and stdout of the child process will be written to process.stdout
and process.stderr of this process.
Fallthrough is handy in situation where there are multiple execs running in sequence/parallel,
and they all have to be executed regardless of success/error on either one of them.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
command: |
String
|
command to execute |
fallthrough: |
Boolean
|
allow error to be camouflaged as a non-error |
cb: |
function
|
standard cb(err, result) callback |
execAndCollect(command:, fallthrough:, cb:)
Execute a one-liner command and collect the output.
The output emitted on stderr and stdout of the child process will be
collected and passed on to the given callback.
Fallthrough is handy in situation where there are multiple execs running in sequence/parallel,
and they all have to be executed regardless of success/error on either one of them.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
command: |
String
|
command to execute |
fallthrough: |
Boolean
|
allow error to be camouflaged as a non-error |
cb: |
function
|
(err, stdOutOuput, stdErrOuput, result) callback |
exit(err:)
Handle process exit based on the existence of error.
This is handy for command-line tools to use as the final callback.
Exit status code 1 indicates an error, exit status code 0 indicates a success.
Error message will be logged to the console. Result object is only used for convenient debugging.
Exit is also called with a second method in the signature called 'result', but it's not declared
here due to not being used when there is no error and this function simply exits with code 0
- Source:
Parameters:
Name | Type | Description |
---|---|---|
err: |
Error
|
error object existence indicates the occurence of an error |
exitCb(errorCb:, successCb:)
A higher order function that returns a process exit callback,
with error and success callbacks to handle error and result accordingly.
Exit status code 1 indicates an error, exit status code 0 indicates a success.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
errorCb: |
function
|
error callback accepts error argument, defaults to logging to console error |
successCb: |
function
|
success callback accepts result argument, defaults to logging to console log |
files(items:, opts:) → {Array}
Get an array of files contained in specified items.
When a directory is specified, all files contained within that directory and its sub-directories will be included.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
items: |
Array
|
an array of files and/or directories |
opts: |
Object
|
optional - match: regular expression to match against the file name |
Returns:
- Type:
-
Array
all files
logStepHeading(message:, opts:)
Displays log step heading message on the console.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message: |
String
|
the heading message string to be displayed |
opts: |
Object
|
optional - labels: an array of labels to be displayed prior to the message |
logStepItemError(message:, opts:)
Displays log step error item error message on the console.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message: |
String
|
the error message string to be displayed |
opts: |
Object
|
optional - labels: an array of labels to be displayed prior to the message |
logStepItemSuccess(message:, opts:)
Displays log step item success message on the console.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message: |
String
|
the success message string to be displayed |
opts: |
Object
|
optional - labels: an array of labels to be displayed prior to the message |
logStepItemWarning(message:, opts:)
Displays log step item warning message on the console.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message: |
String
|
the warning message string to be displayed |
opts: |
Object
|
optional - labels: an array of labels to be displayed prior to the message |
lookupConfig(keys:, opts:, cb:)
Lookup config values for the specified keys in the following order:
- environment variable
- if optional file is specified, then check for the value inside the file
file type depends on extension file
- if optional enablePrompt is set to true, then prompt the user for config value
- Source:
Parameters:
Name | Type | Description |
---|---|---|
keys: |
Array
|
an array of configuration keys to be looked up |
opts: |
Object
|
optional - file: file name to look up to for the configuration value, if not supplied then no file lookup will be done - enablePrompt: if true then prompt the user for configuration value |
cb: |
function
|
standard cb(err, result) callback |
lookupFile(file:, opts:) → {String}
Synchronously read file based on these rules:
- if path is absolute, then check file at absolute path first
- if path is relative, then check file at current working directory
- if none of the above exists, check file at user home directory
- if none exists, throw an error
This allows simple file lookup which allows various locations.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
file: |
String
|
the file name to read |
opts: |
Object
|
optional - platform: needed for unit tests to override platform since node v0.11.x https://github.com/trevnorris/node/commit/c80f8fa8f108d8db598b260ddf26bafd2ec8a1f8 |
Returns:
- Type:
-
String
content of the file
spawn(command:, args:, cb:)
Execute a command with an array of arguments.
E.g. command: make, arguments: -f somemakefile target1 target2 target3
will be executed as: make -f somemakefile target1 target2 target3
NOTE: process.stdout.write and process.stderr.write are used because console.log adds a newline
- Source:
Parameters:
Name | Type | Description |
---|---|---|
command: |
String
|
command to execute |
args: |
Array
|
command arguments |
cb: |
function
|
standard cb(err, result) callback |