CommonServices

CommonServices

new CommonServices()

Source:
Provides static methods of common services

Methods

(static) getServerName(targetDiropt, nameOverrideopt) → {string}

Source:
Get the name based on nameOverride/mastery.run.json/package.json/default server name
Example
process.chdir('build');
getServerName();

// returns a project name from mastery.run.json:name inside build directory
Parameters:
Name Type Attributes Default Description
targetDir string <optional>
.
nameOverride string <optional>
Returns:
Project name
Type
string

(static) getTargetBabelRecipe(targetDiropt) → {Object|Boolean}

Source:
Return a mastery.run.json file content
Example
getTargetBabelRecipe();

// returns .babelrc file content from 'root' directory if exists
Parameters:
Name Type Attributes Default Description
targetDir string <optional>
. Relative path of target directory to retrieve its mastery.run.json
Returns:
.babelrc file content or false
Type
Object | Boolean

(static) getTargetPackage(targetDiropt) → {Object|Boolean}

Source:
Return a package.json file content
Example
process.chdir('build');
getTargetPackage();

// returns package.json file content from 'build' directory
Parameters:
Name Type Attributes Default Description
targetDir string <optional>
. Relative path of target directory to retrieve its package.json
Returns:
Requiring result
Type
Object | Boolean

(static) getTargetRunConf(targetDiropt) → {Object|Boolean}

Source:
Return a mastery.run.json file content
Example
process.chdir('build');
getTargetRunConf();

// returns mastery.run.json file content from 'build' directory if exists
Parameters:
Name Type Attributes Default Description
targetDir string <optional>
. Relative path of target directory to retrieve its mastery.run.json
Returns:
Requiring result
Type
Object | Boolean

(static) globSyncMultiple(patterns) → {Array.<string>}

Source:
Allow to use glob.sync with multiple patterns
Example
globSyncMultiple(path.resolve(path.join(rootPath, '../*package.json')));

// returns ['root/package.json']
Parameters:
Name Type Description
patterns string | Array.<string> Glob patterns
Returns:
file paths
Type
Array.<string>

(static) requireAll(pattern) → {Array.<any>}

Source:
Requiring multiple files at once, populate each result to an object identified by index number
Example
requireAll(path.resolve(path.join(rootPath, '../package.json')));

// returns package.json file content
Parameters:
Name Type Description
pattern string | Array.<string> Glob patterns
Returns:
file contents
Type
Array.<any>

(static) requireF(file) → {any}

Source:
Require a file relatives to project parent path (src/build)
Example
requireF('../package.json');

// returns package.json file content
Parameters:
Name Type Description
file string Relative path from rootPath (src/build)
Returns:
file content
Type
any

(static) transformOption(optionValue, transformTo) → {string}

Source:
Transform a commander option value to another CLI parameter
Example
transformOption(5858, '--debug-brk');

// returns '--debug-brk 5858'
Parameters:
Name Type Description
optionValue any
transformTo string
Returns:
Transformed option, empty if optionValue is undefined
Type
string