Home Reference Source Repository

Function

Static Public Summary
public

addPadding(string: string, length: number): string

Pads a string to a given length with spaces.

public

appendConfig(configObject: rocConfig): rocConfig

Appends to the configuration object.

public

Appends settings to the configuration object.

public

buildCompleteConfig(debug: boolean, config: rocConfig, meta: rocMetaConfig, newConfig: rocConfig, newMeta: rocMetaConfig, directory: string, validate: boolean): Object

Builds the complete configuration objects.

public
public

error(text: string): string

Formats a string suitable for error output.

public

Formats a string suitable for error labels.

public

execute(command: string): Promise

Executes a command string.

public

fileExists(filepath: string, directory: string): boolean

Verifys if a file exists.

public

generateCommandDocumentation(settings: rocConfig, commands+meta: rocMetaConfig, command: string, name: string): string

Generates a string with information about a specific command.

public

Generates a string with information about all the possible commands.

public

Generates markdown documentation for the provided configuration object.

public

generateTable(initalDocumentationObject: rocDocumentationObject, header: rocTableHeader, settings: rocTableSettings): string

Creates a table based on a rocDocumentationObject.

public

generateTextDocumentation(config: rocConfig, metaConfig: rocMetaConfig, filter: string[]): string

Generates plain text documentation for the provided configuration object.

public

get(packageName: string, version: string): string

Fetches the tarball for a repository on Github.

public

getAbsolutePath(filepath: string, directory: string): string

Makes a path absolute if not already is that.

public

getApplicationConfig(applicationConfigPath: string, directory: string, debug: boolean): object

Gets the application configuration by reading a file.

public

Gets the current configuration object.

public

Converts an object to a string.

public

getMappings(documentationObject: rocDocumentationObject): Object

Creates mappings between cli commands to their "path" in the configuration structure, their validator and type convertor.

public

Reads a package.json file.

public

getRocDependencies(packageJson: Object): string[]

Gets the Roc dependencies from a package.json.

public

Gets the settings in the configuration object.

public

getSuggestions(current: string[], possible: string[], command: boolean): string

Will create a string with suggestions for possible typos.

public

getVersions(packageName: string): object[]

Fetches an array of all the tags for a Github repo, used as possible versions for a template.

public

Formats a string suitable for important messages.

public

Formats a string suitable for important labels.

public

init(parsedArguments: rocCommandObject): Promise

Command used to init a new Roc project.

public

isArray(validator: function | RegExp): function

Validates an array using a validator.

public

Validates an pontential array using a validator.

public

Validates an string.

public

Validates an string.

public

isObject(validator: function | RegExp): function

Validates an object using a validator.

public

Validates an string.

public

Validates an string.

public

isValid(value: object, validator: function | RegExp): boolean

Helper to use a validator.

public

Merges two configuration objects.

public

ok(text: string): string

Formats a string suitable for confirmations.

public

Formats a string suitable for confirmation labels.

public

oneOf(validators: ...function): function

Validates against a list of validators.

public

pad(length: number, character: string): string

Returns a string to pad with.

public

parseArguments(args: Object, mappings: Object): Object

Converts a set of arguments to rocConfigSettings object.

public

parseOptions(command: string, commands: Object, options: Object[]): Object

Parses options and validates them.

public

required(validator: function): function

Marks that the value is required

public

runCli(info: {version: string, name: string}, initalConfig: rocConfig, initalMeta: rocMetaConfig, args: string[]): undefined

Invokes the Roc cli.

public

throwError(name: string, message: string, value: object, type: string)

Throws error for failed validations.

public

toCliFlag(configPaths: string[]): string

Takes a configuration path array and convertes it to a cli flag.

public

Validates if a directory seems to be a Roc application project.

public

validate(settings: rocSettings, metaSettings: rocMetaSettings, toValidate: array | boolean)

Validates the provided configuration object.

public

validateMightThrow(settings: rocSettings, validations: Object)

Validates the provided configuration object.

public

Formats a string suitable for warnings.

public

Formats a string suitable for warning labels.

Static Public

public addPadding(string: string, length: number): string source

import {addPadding} from 'roc/lib/documentation/helpers.js'

Pads a string to a given length with spaces.

Params:

NameTypeAttributeDescription
string string

The string to be padded.

length number

The desired length of the new string.

Return:

string

A string matching the input.

public appendConfig(configObject: rocConfig): rocConfig source

import {appendConfig} from 'roc/lib/configuration/index.js'

Appends to the configuration object.

Will merge with the already existing configuration object meaning that this function can be called multiple times and the configuration will be a merge of all those calls.

Params:

NameTypeAttributeDescription
configObject rocConfig
  • nullable: false

A configuration object.

Return:

rocConfig

The configuration object.

public appendSettings(settingsObject: rocSettings): rocSettings source

import {appendSettings} from 'roc/lib/configuration/index.js'

Appends settings to the configuration object.

Will merge with the already existing settings object meaning that this function can be called multiple times and the settings will be a merge of all those calls.

Params:

NameTypeAttributeDescription
settingsObject rocSettings
  • nullable: false

A settings object.

Return:

rocSettings

The settings object.

public buildCompleteConfig(debug: boolean, config: rocConfig, meta: rocMetaConfig, newConfig: rocConfig, newMeta: rocMetaConfig, directory: string, validate: boolean): Object source

import {buildCompleteConfig} from 'roc/lib/cli/helpers.js'

Builds the complete configuration objects.

Params:

NameTypeAttributeDescription
debug boolean

If debug mode should be enabled, logs some extra information.

config rocConfig

The base configuration.

meta rocMetaConfig

The base meta configuration.

newConfig rocConfig

The new configuration to base the merge on.

newMeta rocMetaConfig

The new meta configuration to base the merge on.

directory string
  • optional
  • default: process.cwd()

The directory to resolve relative paths from.

validate boolean
  • optional
  • default: true

If the newConfig and the newMeta structure should be validated.

Return:

Object

The result of with the built configurations.

Return Properties:

NameTypeAttributeDescription
extensionConfig rocConfig

The extensions merged configurations

config rocConfig

The final configuration, with application configuration.

meta rocMetaConfig

The merged meta configuration.

public buildDocumentationObject(initalObject: Object, meta: rocMetaSettings, initalFilter: string[]): rocDocumentationObject source

import buildDocumentationObject from 'roc/lib/documentation/build-documentation-object.js'

Creates a rocDocumentationObject.

Params:

NameTypeAttributeDescription
initalObject Object

The object to create a rocDocumentationObject of.

meta rocMetaSettings

The meta object to use.

initalFilter string[]
  • optional
  • default: []

The groups that should be used, will default to all groups.

Return:

rocDocumentationObject

The completed documentation object.

public error(text: string): string source

import {error} from 'roc/lib/helpers/style.js'

Formats a string suitable for error output.

Params:

NameTypeAttributeDescription
text string

The text to format for errors.

Return:

string

The formatted text.

public errorLabel(text: string): string source

import {errorLabel} from 'roc/lib/helpers/style.js'

Formats a string suitable for error labels.

Params:

NameTypeAttributeDescription
text string

The text to format for error labels.

Return:

string

The formatted text.

public execute(command: string): Promise source

import {execute} from 'roc/lib/cli/execute.js'

Executes a command string.

Quite simple in its current state and should be expected to change in the future. Can manage multiple commands if they are divided by either & or &&. Important that there is spacing on both sides.

Params:

NameTypeAttributeDescription
command string

A command string that should run.

Return:

Promise

A promise that is resolved when all the commands are completed.

public fileExists(filepath: string, directory: string): boolean source

import {fileExists} from 'roc/lib/helpers/index.js'

Verifys if a file exists.

Params:

NameTypeAttributeDescription
filepath string

The filepath to check. Will make it absolute if not already using getAbsolutePath.

directory string
  • optional

The directory to base the filepath on.

Return:

boolean

Whether or not it is a file.

public generateCommandDocumentation(settings: rocConfig, commands+meta: rocMetaConfig, command: string, name: string): string source

import {generateCommandDocumentation} from 'roc/lib/cli/helpers.js'

Generates a string with information about a specific command.

Params:

NameTypeAttributeDescription
settings rocConfig

The Roc config object, uses settings from it.

commands+meta rocMetaConfig

The Roc meta config object, uses commands and settings from it.

command string

The selected command.

name string

The name of the cli.

Return:

string

A string with documentation based on the selected commands.

public generateCommandsDocumentation(commands: rocConfig, commandsmeta: rocMetaConfig): string source

import {generateCommandsDocumentation} from 'roc/lib/cli/helpers.js'

Generates a string with information about all the possible commands.

Params:

NameTypeAttributeDescription
commands rocConfig

The Roc config object, uses commands from it.

commandsmeta rocMetaConfig

The Roc meta config object, uses commands from it.

Return:

string

A string with documentation based on the available commands.

public generateMarkdownDocumentation(config: rocConfig, metaConfig: rocMetaConfig, filter: string[]): string source

import {generateMarkdownDocumentation} from 'roc/lib/documentation/index.js'

Generates markdown documentation for the provided configuration object.

Params:

NameTypeAttributeDescription
config rocConfig

The configuration object to generate documentation for.

metaConfig rocMetaConfig

The meta configuration object that has information about the config object.

filter string[]
  • optional
  • default: []

The groups that should be includes, by default all will be used.

Return:

string

A markdown table as a string.

public generateTable(initalDocumentationObject: rocDocumentationObject, header: rocTableHeader, settings: rocTableSettings): string source

import generateTable from 'roc/lib/documentation/generate-table.js'

Creates a table based on a rocDocumentationObject.

Params:

NameTypeAttributeDescription
initalDocumentationObject rocDocumentationObject

The documentation object to create a table of.

header rocTableHeader

Header object to use.

settings rocTableSettings

The settings to use.

Return:

string

A table.

public generateTextDocumentation(config: rocConfig, metaConfig: rocMetaConfig, filter: string[]): string source

import {generateTextDocumentation} from 'roc/lib/documentation/index.js'

Generates plain text documentation for the provided configuration object.

Params:

NameTypeAttributeDescription
config rocConfig

The configuration object to generate documentation for.

metaConfig rocMetaConfig

The meta configuration object that has information about the config object.

filter string[]
  • optional
  • default: []

The groups that should be includes, by default all will be used.

Return:

string

A table as a string.

public get(packageName: string, version: string): string source

Fetches the tarball for a repository on Github.

Params:

NameTypeAttributeDescription
packageName string

A package name, expected to match "username/repo".

version string
  • optional
  • default: "master"

The tag/version to fetch.

Return:

string

The path to the temporary directory where the unarchived tarball is located.

public getAbsolutePath(filepath: string, directory: string): string source

import {getAbsolutePath} from 'roc/lib/helpers/index.js'

Makes a path absolute if not already is that.

Params:

NameTypeAttributeDescription
filepath string

The filepath to make absolute.

directory string
  • optional
  • default: process.cwd()

The directory to resolve relative paths to. By default will use the current working directory.

Return:

string

An absolute path.

public getApplicationConfig(applicationConfigPath: string, directory: string, debug: boolean): object source

import {getApplicationConfig} from 'roc/lib/configuration/helpers.js'

Gets the application configuration by reading a file.

Will give a warning if ROC_CONFIG_PATH has been set since that will then be used as the path to get the configuration file, even if one is provided to the function.

Reads configuration files in this manner:

  1. Environment variable ROC_CONFIG_PATH.
  2. Path given as applicationConfigPath.
  3. Default by trying to read "roc.config.js" in the current working directory.
  4. Return a empty object along with a warning.

Params:

NameTypeAttributeDescription
applicationConfigPath string

Path to application configuration file. Can be either relative or absolute.

directory string
  • optional
  • default: process.cwd()

The directory to resolve realative paths to. By default will use the current working directory.

debug boolean
  • optional
  • default: false

If extra information should be printed.

Return:

object

The application configuration object.

Throw:

Error

When an invalid path override is specified.

public getConfig(): rocConfig source

import {getConfig} from 'roc/lib/configuration/index.js'

Gets the current configuration object.

Return:

rocConfig

The application configuration object.

public getDefaultValue(object: Object): string | null source

import {getDefaultValue} from 'roc/lib/documentation/helpers.js'

Converts an object to a string.

Params:

NameTypeAttributeDescription
object Object

The object to convert to a string.

Return:

string | null

The converted object or null if the object is empty.

public getMappings(documentationObject: rocDocumentationObject): Object source

import {getMappings} from 'roc/lib/cli/helpers.js'

Creates mappings between cli commands to their "path" in the configuration structure, their validator and type convertor.

Params:

NameTypeAttributeDescription
documentationObject rocDocumentationObject

Documentation object to create mappings for.

Return:

Object

Properties are the cli command without leading dashes that maps to a rocMapObject.

public getPackageJson(directory: string): Object | undefined source

import {getPackageJson} from 'roc/lib/helpers/index.js'

Reads a package.json file.

Params:

NameTypeAttributeDescription
directory string
  • optional
  • default: processs.cwd()

In what directory to look for the package.json.

Return:

Object | undefined

The object in the package.json or undefined if it did not exists.

public getRocDependencies(packageJson: Object): string[] source

import {getRocDependencies} from 'roc/lib/helpers/index.js'

Gets the Roc dependencies from a package.json.

Params:

NameTypeAttributeDescription
packageJson Object

A package.json file to fetch Roc dependencies from.

Return:

string[]

An array with Roc extensions that exists in the package.json.

public getSettings(key: string): rocSettings | Object source

import {getSettings} from 'roc/lib/configuration/index.js'

Gets the settings in the configuration object.

Will by default get all settings.

Params:

NameTypeAttributeDescription
key string
  • optional

The settings key to fetch.

Return:

rocSettings | Object

The application settings object.

public getSuggestions(current: string[], possible: string[], command: boolean): string source

import {getSuggestions} from 'roc/lib/cli/helpers.js'

Will create a string with suggestions for possible typos.

Params:

NameTypeAttributeDescription
current string[]

The current values that might be incorrect.

possible string[]

All the possible correct values.

command boolean
  • optional
  • default: false

If the suggestion should be managed as a command.

Return:

string

A string with possible suggestions for typos.

public getVersions(packageName: string): object[] source

import {getVersions} from 'roc/lib/commands/helpers/github.js'

Fetches an array of all the tags for a Github repo, used as possible versions for a template.

Params:

NameTypeAttributeDescription
packageName string

A package name, expected to match "username/repo"

Return:

object[]

Array of tags/versions for the package

public important(text: string): string source

import {important} from 'roc/lib/helpers/style.js'

Formats a string suitable for important messages.

Params:

NameTypeAttributeDescription
text string

The text to format for important messages.

Return:

string

The formatted text.

public importantLabel(text: string): string source

import {importantLabel} from 'roc/lib/helpers/style.js'

Formats a string suitable for important labels.

Params:

NameTypeAttributeDescription
text string

The text to format for important labels.

Return:

string

The formatted text.

public init(parsedArguments: rocCommandObject): Promise source

import init from 'roc/lib/commands/init.js'

Command used to init a new Roc project.

Params:

NameTypeAttributeDescription
parsedArguments rocCommandObject

The Roc command object, uses parsedArguments from it.

Return:

Promise

Promise for the command.

public isArray(validator: function | RegExp): function source

import {isArray} from 'roc/lib/validation/validators.js'

Validates an array using a validator.

Params:

NameTypeAttributeDescription
validator function | RegExp

The validator to use on the elements in the array.

Return:

function

A function that takes a value and that returns true or false if valid or not.

public isArrayOrSingle(validator: function | RegExp): function source

import {isArrayOrSingle} from 'roc/lib/validation/validators.js'

Validates an pontential array using a validator.

Allows that a single value is given.

Params:

NameTypeAttributeDescription
validator function | RegExp

The validator to use on the elements in the array.

Return:

function

A function that takes a value and that returns true or false if valid or not.

public isBoolean(value: object, info: boolean): infoObject | boolean | string source

import {isBoolean} from 'roc/lib/validation/validators.js'

Validates an string.

Params:

NameTypeAttributeDescription
value object

Something to validate.

info boolean

If type information should be returned.

Return:

infoObject | boolean | string

Type information or if it is valid.

public isInteger(value: object, info: boolean): infoObject | boolean | string source

import {isInteger} from 'roc/lib/validation/validators.js'

Validates an string.

Params:

NameTypeAttributeDescription
value object

Something to validate.

info boolean

If type information should be returned.

Return:

infoObject | boolean | string

Type information or if it is valid.

public isObject(validator: function | RegExp): function source

import {isObject} from 'roc/lib/validation/validators.js'

Validates an object using a validator.

Params:

NameTypeAttributeDescription
validator function | RegExp

The validator to use on the elements in the object

Return:

function

A function that takes a value and that returns true or false if valid or not.

public isPath(value: object, info: boolean): infoObject | boolean | string source

import {isPath} from 'roc/lib/validation/validators.js'

Validates an string.

Params:

NameTypeAttributeDescription
value object

Something to validate.

info boolean

If type information should be returned.

Return:

infoObject | boolean | string

Type information or if it is valid.

public isString(value: object, info: boolean): infoObject | boolean | string source

import {isString} from 'roc/lib/validation/validators.js'

Validates an string.

Params:

NameTypeAttributeDescription
value object

Something to validate.

info boolean

If type information should be returned.

Return:

infoObject | boolean | string

Type information or if it is valid.

public isValid(value: object, validator: function | RegExp): boolean source

import {isValid} from 'roc/lib/validation/index.js'

Helper to use a validator.

Params:

NameTypeAttributeDescription
value object

Something to validate.

validator function | RegExp

A validator.

Return:

boolean

If valid or not.

public merge(a: Object, b: Object): Object source

import {merge} from 'roc/lib/configuration/index.js'

Merges two configuration objects.

Params:

NameTypeAttributeDescription
a Object
  • nullable: false

Configuration object to base the merge on.

b Object
  • nullable: false

Configuration object that is merged into the first, overwriting the first one.

Return:

Object

The merged configuration object

public ok(text: string): string source

import {ok} from 'roc/lib/helpers/style.js'

Formats a string suitable for confirmations.

Params:

NameTypeAttributeDescription
text string

The text to format for confirmations.

Return:

string

The formatted text.

public okLabel(text: string): string source

import {okLabel} from 'roc/lib/helpers/style.js'

Formats a string suitable for confirmation labels.

Params:

NameTypeAttributeDescription
text string

The text to format for confirmation labels.

Return:

string

The formatted text.

public oneOf(validators: ...function): function source

import {oneOf} from 'roc/lib/validation/validators.js'

Validates against a list of validators.

Params:

NameTypeAttributeDescription
validators ...function

Validators to validate against.

Return:

function

A function that takes a value and that returns true or false if valid or not.

public pad(length: number, character: string): string source

Returns a string to pad with.

Params:

NameTypeAttributeDescription
length number

The desired length of the generated string.

character string
  • optional
  • default: "

"] - The character to repat.

Return:

string

A string matching the input.

public parseArguments(args: Object, mappings: Object): Object source

import {parseArguments} from 'roc/lib/cli/helpers.js'

Converts a set of arguments to rocConfigSettings object.

Params:

NameTypeAttributeDescription
args Object

Arguments parsed from minimist.

mappings Object

Result from getMappings.

Return:

Object

The mapped Roc configuration settings object.

public parseOptions(command: string, commands: Object, options: Object[]): Object source

import {parseOptions} from 'roc/lib/cli/helpers.js'

Parses options and validates them.

Params:

NameTypeAttributeDescription
command string

The command to parse options for.

commands Object

commands from rocMetaConfig.

options Object[]

Options parsed by minimist.

Return:

Object

Parsed options.

Return Properties:

NameTypeAttributeDescription
options object[]

The parsed options that was matched against the meta configuration for the command.

rest object[]

The rest of the options that could not be matched against the configuration.

public required(validator: function): function source

import {required} from 'roc/lib/validation/validators.js'

Marks that the value is required

Params:

NameTypeAttributeDescription
validator function

Validator to validate against

Return:

function

A function that takes a value and that returns true or false if valid or not.

public runCli(info: {version: string, name: string}, initalConfig: rocConfig, initalMeta: rocMetaConfig, args: string[]): undefined source

import {runCli} from 'roc/lib/cli/index.js'

Invokes the Roc cli.

Params:

NameTypeAttributeDescription
info {version: string, name: string}

Information about the cli.

initalConfig rocConfig

The inital configuration, will be merged with the selected extensions and application.

initalMeta rocMetaConfig

The inital meta configuration, will be merged with the selected extensions.

args string[]
  • optional
  • default: process.argv

From where it should parse the arguments.

Return:

undefined

public throwError(name: string, message: string, value: object, type: string) source

import {throwError} from 'roc/lib/validation/index.js'

Throws error for failed validations.

Params:

NameTypeAttributeDescription
name string

String with the name of what failed the validation.

message string

Potential message from the validating function.

value object

The value that was provided.

type string
  • optional
  • default: 'field'

What the failed validation value was.

Throw:

Error

Throws error if the configuration is invalid.

public toCliFlag(configPaths: string[]): string source

import {toCliFlag} from 'roc/lib/documentation/helpers.js'

Takes a configuration path array and convertes it to a cli flag.

Params:

NameTypeAttributeDescription
configPaths string[]

The configuration path, a array consiting of properties.

Return:

string

The cli flag to set the given configuration option.

public validRocProject(directory: string): boolean source

import {validRocProject} from 'roc/lib/commands/helpers/general.js'

Validates if a directory seems to be a Roc application project. A valid Roc project should have a package.json file that contains some dependecy that match 'roc-*' or a roc.config.js file.

Params:

NameTypeAttributeDescription
directory string

The directory to validate.

Return:

boolean

Whether or not it is a valid Roc project.

public validate(settings: rocSettings, metaSettings: rocMetaSettings, toValidate: array | boolean) source

import {validate} from 'roc/lib/validation/index.js'

Validates the provided configuration object.

Params:

NameTypeAttributeDescription
settings rocSettings

The settings object to validate.

metaSettings rocMetaSettings

The meta settings object that has information about how to validate.

toValidate array | boolean

What groups on settings that should be validated.

Emit:

process.exit

If the config was invalid it will print the reason and terminate with status 1.

public validateMightThrow(settings: rocSettings, validations: Object) source

import {validateMightThrow} from 'roc/lib/validation/index.js'

Validates the provided configuration object.

Params:

NameTypeAttributeDescription
settings rocSettings

The settings object to validate.

validations Object

The meta configuration object that has information about how to validate.

Throw:

Error

throws error if the configuration is invalid

public warning(text: string): string source

import {warning} from 'roc/lib/helpers/style.js'

Formats a string suitable for warnings.

Params:

NameTypeAttributeDescription
text string

The text to format for warnings.

Return:

string

The formatted text.

public warningLabel(text: string): string source

import {warningLabel} from 'roc/lib/helpers/style.js'

Formats a string suitable for warning labels.

Params:

NameTypeAttributeDescription
text string

The text to format for warning labels.

Return:

string

The formatted text.