roc
Version:
Build modern web applications easily
1,045 lines • 188 kB
JSON
[
{
"__docId__": 0,
"kind": "file",
"static": true,
"variation": null,
"name": "src/cli/execute.js",
"memberof": null,
"longname": "src/cli/execute.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\nimport { spawn } from 'child_process';\n\n/**\n * Executes a command string.\n *\n * Quite simple in its current state and should be expected to change in the future.\n * Can manage multiple commands if they are divided by either & or &&. Important that there is spacing on both sides.\n *\n * @param {string} command - A command string that should run.\n * @returns {Promise} - A promise that is resolved when all the commands are completed.\n */\nexport function execute(command) {\n const parallelCommands = command.split(/ & /);\n return executeNext(parallelCommands);\n}\n\nfunction executeNext(parallelCommands) {\n const syncCommand = parallelCommands.shift();\n if (syncCommand) {\n return Promise.all([runCommand(syncCommand), executeNext(parallelCommands)]);\n }\n return Promise.resolve();\n}\n\nfunction runCommand(syncCommand) {\n const syncCommands = syncCommand.split(/ && /);\n const command = syncCommands.shift();\n const parts = command.split(/\\s+/g);\n const cmd = parts[0];\n const args = parts.slice(1);\n return new Promise((resolve) => {\n spawn(cmd, args, { stdio: 'inherit' })\n .on('exit', function(code) {\n if (code) {\n /* eslint-disable no-process-exit */\n return process.exit(code);\n /* eslint-enable */\n }\n executeNext(syncCommands).then(resolve);\n });\n });\n}\n"
},
{
"__docId__": 1,
"kind": "function",
"static": true,
"variation": null,
"name": "execute",
"memberof": "src/cli/execute.js",
"longname": "src/cli/execute.js~execute",
"access": null,
"export": true,
"importPath": "roc/lib/cli/execute.js",
"importStyle": "{execute}",
"description": "Executes a command string.\n\nQuite simple in its current state and should be expected to change in the future.\nCan manage multiple commands if they are divided by either & or &&. Important that there is spacing on both sides.",
"lineNumber": 14,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Promise} - A promise that is resolved when all the commands are completed."
}
],
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "command",
"description": "A command string that should run."
}
],
"return": {
"nullable": null,
"types": [
"Promise"
],
"spread": false,
"description": "A promise that is resolved when all the commands are completed."
},
"generator": false
},
{
"__docId__": 2,
"kind": "function",
"static": true,
"variation": null,
"name": "executeNext",
"memberof": "src/cli/execute.js",
"longname": "src/cli/execute.js~executeNext",
"access": null,
"export": false,
"importPath": "roc/lib/cli/execute.js",
"importStyle": null,
"description": null,
"lineNumber": 19,
"undocument": true,
"params": [
{
"name": "parallelCommands",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 3,
"kind": "function",
"static": true,
"variation": null,
"name": "runCommand",
"memberof": "src/cli/execute.js",
"longname": "src/cli/execute.js~runCommand",
"access": null,
"export": false,
"importPath": "roc/lib/cli/execute.js",
"importStyle": null,
"description": null,
"lineNumber": 27,
"undocument": true,
"params": [
{
"name": "syncCommand",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 4,
"kind": "file",
"static": true,
"variation": null,
"name": "src/cli/helpers.js",
"memberof": null,
"longname": "src/cli/helpers.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\nimport chalk from 'chalk';\nimport { isPlainObject, isBoolean, isString, set, difference } from 'lodash';\nimport resolve from 'resolve';\nimport leven from 'leven';\nimport trimNewlines from 'trim-newlines';\nimport redent from 'redent';\n\nimport { merge } from '../configuration';\nimport buildDocumentationObject from '../documentation/build-documentation-object';\nimport generateTable from '../documentation/generate-table';\nimport { getDefaultValue } from '../documentation/helpers';\nimport { fileExists, getRocDependencies, getPackageJson } from '../helpers';\nimport { throwError } from '../validation';\nimport { isValid } from '../validation';\nimport { warning, importantLabel, errorLabel, warningLabel } from '../helpers/style';\n\n/**\n * Builds the complete configuration objects.\n *\n * @param {boolean} debug - If debug mode should be enabled, logs some extra information.\n * @param {rocConfig} config - The base configuration.\n * @param {rocMetaConfig} meta - The base meta configuration.\n * @param {rocConfig} newConfig - The new configuration to base the merge on.\n * @param {rocMetaConfig} newMeta - The new meta configuration to base the merge on.\n * @param {string} [directory=process.cwd()] - The directory to resolve relative paths from.\n * @param {boolean} [validate=true] - If the newConfig and the newMeta structure should be validated.\n *\n * @returns {Object} - The result of with the built configurations.\n * @property {rocConfig} extensionConfig - The extensions merged configurations\n * @property {rocConfig} config - The final configuration, with application configuration.\n * @property {rocMetaConfig} meta - The merged meta configuration.\n */\nexport function buildCompleteConfig(\n debug, config = {}, meta = {}, newConfig = {}, newMeta = {}, directory = process.cwd(), validate = true\n) {\n let finalConfig = { ...config };\n let finalMeta = { ...meta };\n\n let usedExtensions = [];\n const mergeExtension = (extensionName) => {\n const { baseConfig, metaConfig = {} } = getExtension(extensionName, directory);\n\n if (baseConfig) {\n usedExtensions.push(extensionName);\n finalConfig = merge(finalConfig, baseConfig);\n finalMeta = merge(finalMeta, metaConfig);\n }\n };\n\n if (fileExists('package.json', directory)) {\n // If extensions are defined we will use them to merge the configurations\n if (newConfig.extensions && newConfig.extensions.length) {\n newConfig.extensions.forEach(mergeExtension);\n } else {\n const packageJson = getPackageJson(directory);\n getRocDependencies(packageJson)\n .forEach(mergeExtension);\n }\n\n if (usedExtensions.length && debug) {\n console.log(importantLabel('The following Roc extensions will be used:'), usedExtensions, '\\n');\n }\n\n // Check for a mismatch between application configuration and extensions.\n if (validate) {\n if (Object.keys(newConfig).length) {\n console.log(validateConfigurationStructure(finalConfig, newConfig));\n }\n if (Object.keys(newMeta).length) {\n console.log(validateConfigurationStructure(finalMeta, newMeta));\n }\n }\n }\n\n return {\n extensionConfig: finalConfig,\n config: merge(finalConfig, newConfig),\n meta: merge(finalMeta, newMeta)\n };\n}\n\nfunction getExtension(extensionName, directory) {\n try {\n const { baseConfig, metaConfig } = require(resolve.sync(extensionName, { basedir: directory }));\n return { baseConfig, metaConfig };\n } catch (err) {\n console.log(\n errorLabel(\n 'Failed to load Roc extension ' + chalk.bold(extensionName) + '. ' +\n 'Make sure you have it installed. Try running:'\n ) + ' ' +\n chalk.underline('npm install --save ' + extensionName)\n , '\\n');\n return {};\n }\n}\n\nfunction validateConfigurationStructure(config, applicationConfig) {\n const getKeys = (obj, oldPath = '', allKeys = []) => {\n Object.keys(obj).forEach((key) => {\n const value = obj[key];\n const newPath = oldPath + key;\n\n if (isPlainObject(value)) {\n getKeys(value, newPath + '.', allKeys);\n } else {\n allKeys.push(newPath);\n }\n });\n\n return allKeys;\n };\n const info = [];\n const keys = getKeys(config);\n const diff = difference(getKeys(applicationConfig), keys);\n if (diff.length > 0) {\n info.push(errorLabel('Configuration problem') +\n ' There was a mismatch in the application configuration structure, make sure this is correct.\\n');\n info.push(getSuggestions(diff, keys));\n info.push('');\n }\n // }\n return info.join('\\n');\n}\n\n/**\n * Will create a string with suggestions for possible typos.\n *\n * @param {string[]} current - The current values that might be incorrect.\n * @param {string[]} possible - All the possible correct values.\n * @param {boolean} [command=false] - If the suggestion should be managed as a command.\n *\n * @returns {string} - A string with possible suggestions for typos.\n */\nexport function getSuggestions(current, possible, command = false) {\n const info = [];\n\n current.forEach((currentKey) => {\n let shortest = 0;\n let closest;\n\n for (let key of possible) {\n let distance = leven(currentKey, key);\n\n if (distance <= 0 || distance > 4) {\n continue;\n }\n\n if (shortest && distance >= shortest) {\n continue;\n }\n\n closest = key;\n shortest = distance;\n }\n\n const extra = command ? '--' : '';\n if (closest) {\n info.push('Did not understand ' + chalk.underline(extra + currentKey) +\n ' - Did you mean ' + chalk.underline(extra + closest));\n } else {\n info.push('Did not understand ' + chalk.underline(extra + currentKey));\n }\n });\n\n return info.join('\\n');\n}\n\n/**\n * Generates a string with information about all the possible commands.\n *\n * @param {rocConfig} commands - The Roc config object, uses commands from it.\n * @param {rocMetaConfig} commandsmeta - The Roc meta config object, uses commands from it.\n *\n * @returns {string} - A string with documentation based on the available commands.\n */\nexport function generateCommandsDocumentation({ commands }, { commands: commandsMeta }) {\n const header = {\n name: true,\n description: true\n };\n\n const noCommands = {'No commands available.': ''};\n commandsMeta = commandsMeta || {};\n\n let body = [{\n name: 'Commands',\n objects: Object.keys(commands || noCommands).map((command) => {\n const options = commandsMeta[command] ?\n ' ' + getCommandOptionsAsString(commandsMeta[command]) :\n '';\n const description = commandsMeta[command] && commandsMeta[command].description ?\n commandsMeta[command].description :\n '';\n\n return {\n name: (command + options),\n description\n };\n })\n }];\n\n return generateCommandDocsHelper(body, header, 'Options', 'name');\n}\n\nfunction getCommandOptionsAsString(command = {}) {\n let options = '';\n (command.options || []).forEach((option) => {\n options += option.required ? `<${option.name}> ` : `[${option.name}] `;\n });\n\n return options;\n}\n\n /**\n * Generates a string with information about a specific command.\n *\n * @param {rocConfig} settings - The Roc config object, uses settings from it.\n * @param {rocMetaConfig} commands+meta - The Roc meta config object, uses commands and settings from it.\n * @param {string} command - The selected command.\n * @param {string} name - The name of the cli.\n *\n * @returns {string} - A string with documentation based on the selected commands.\n */\nexport function generateCommandDocumentation({ settings }, { commands = {}, settings: meta }, command, name) {\n const rows = [];\n rows.push('Usage: ' + name + ' ' + command + ' ' + getCommandOptionsAsString(commands[command]));\n rows.push('');\n\n if (commands[command] && commands[command].help) {\n rows.push(redent(trimNewlines(commands[command].help)));\n rows.push('');\n }\n\n let body = [];\n\n // Generate the options table\n if (commands[command] && commands[command].settings) {\n rows.push('Options:');\n rows.push('');\n\n const filter = commands[command].settings === true ? [] : commands[command].settings;\n\n body = buildDocumentationObject(settings, meta, filter);\n }\n\n const header = {\n cli: true,\n description: {\n name: 'Description',\n padding: false\n },\n defaultValue: {\n name: 'Default',\n renderer: (input) => {\n input = getDefaultValue(input);\n\n if (input === undefined) {\n return '';\n }\n\n if (!input) {\n return warning('No default value');\n }\n\n return chalk.cyan(input);\n }\n }\n };\n\n rows.push(generateCommandDocsHelper(body, header, 'CLI options', 'cli'));\n\n return rows.join('\\n');\n}\n\nfunction generateCommandDocsHelper(body, header, options, name) {\n body.push({\n name: options,\n objects: [{\n [name]: '-h, --help',\n description: 'Output usage information.'\n }, {\n [name]: '-v, --version',\n description: 'Output version number.'\n }, {\n [name]: '-d, --debug',\n description: 'Enable debug mode.'\n }, {\n [name]: '-c, --config',\n description: `Path to configuration file, will default to ${chalk.bold('roc.config.js')} in current ` +\n `working directory.`\n }, {\n [name]: '-D, --directory',\n description: 'Path to working directory, will default to the current working directory. Can be either ' +\n 'absolute or relative.'\n }]\n });\n\n return generateTable(body, header, {\n compact: true,\n titleWrapper: (input) => input + ':',\n cellDivider: '',\n rowWrapper: (input) => `${input}`,\n header: false,\n groupTitleWrapper: (input) => input + ':'\n });\n}\n\n/**\n * Parses options and validates them.\n *\n * @param {string} command - The command to parse options for.\n * @param {Object} commands - commands from {@link rocMetaConfig}.\n * @param {Object[]} options - Options parsed by minimist.\n *\n * @returns {Object} - Parsed options.\n * @property {object[]} options - The parsed options that was matched against the meta configuration for the command.\n * @property {object[]} rest - The rest of the options that could not be matched against the configuration.\n */\nexport function parseOptions(command, commands, options) {\n // If the command supports options\n if (commands[command] && commands[command].options) {\n let parsedOptions = {};\n commands[command].options.forEach((option, index) => {\n const value = options[index];\n\n if (option.required && !value) {\n throw new Error(`Required option \"${option.name}\" was not provided.`);\n }\n\n if (value && option.validation) {\n const validationResult = isValid(value, option.validation);\n if (validationResult !== true) {\n try {\n throwError(option.name, validationResult, value, 'option');\n } catch (err) {\n /* eslint-disable no-process-exit, no-console */\n console.log(errorLabel('Arguments problem') + ' An option was not valid.\\n');\n console.log(err.message);\n process.exit(1);\n /* eslint-enable */\n }\n }\n }\n\n parsedOptions[option.name] = value;\n });\n\n return {\n options: parsedOptions,\n rest: options.splice(Object.keys(parsedOptions).length)\n };\n }\n\n return {\n options: undefined,\n rest: options\n };\n}\n\n/**\n * Creates mappings between cli commands to their \"path\" in the configuration structure, their validator and type\n * convertor.\n *\n * @param {rocDocumentationObject} documentationObject - Documentation object to create mappings for.\n *\n * @returns {Object} - Properties are the cli command without leading dashes that maps to a {@link rocMapObject}.\n */\nexport function getMappings(documentationObject) {\n const recursiveHelper = (groups) => {\n let mappings = {};\n\n groups.forEach((group) => {\n group.objects.forEach((element) => {\n // Remove the two dashes in the beginning to match correctly\n mappings[element.cli.substr(2)] = {\n name: element.cli,\n path: element.path,\n convertor: getConvertor(element.defaultValue, element.cli),\n validator: element.validator\n };\n });\n\n mappings = Object.assign({}, mappings, recursiveHelper(group.children));\n });\n\n return mappings;\n };\n\n return recursiveHelper(documentationObject);\n}\n\n// Convert values based on their default value\nfunction getConvertor(value, name) {\n if (isBoolean(value)) {\n return (input) => {\n if (isBoolean(input)) {\n return input;\n }\n if (input === 'true' || input === 'false') {\n return input === 'true';\n }\n\n console.log(\n warningLabel(`Invalid value given for ${chalk.bold(name)}.`),\n `Will use the default ${chalk.bold(value)}.`\n );\n\n return value;\n };\n } else if (Array.isArray(value)) {\n return (input) => {\n let parsed;\n try {\n parsed = JSON.parse(input);\n } catch (err) {\n // Ignore this case\n }\n\n if (Array.isArray(parsed)) {\n return parsed;\n }\n\n return input.toString().split(',');\n };\n } else if (Number.isInteger(value)) {\n return (input) => parseInt(input, 10);\n } else if (!isString(value) && (!value || Object.keys(value).length === 0)) {\n return (input) => JSON.parse(input);\n }\n\n return (input) => input;\n}\n\n/**\n * Converts a set of arguments to {@link rocConfigSettings} object.\n *\n * @param {Object} args - Arguments parsed from minimist.\n * @param {Object} mappings - Result from {@link getMappings}.\n *\n * @returns {Object} - The mapped Roc configuration settings object.\n */\nexport function parseArguments(args, mappings) {\n const config = {};\n const info = [];\n\n Object.keys(args).forEach((key) => {\n if (mappings[key]) {\n const value = convert(args[key], mappings[key]);\n set(config, mappings[key].path, value);\n } else {\n // We did not find a match\n info.push(getSuggestions([key], Object.keys(mappings), true));\n }\n });\n\n if (info.length > 0) {\n console.log(errorLabel('CLI problem'), 'Some commands were not understood.\\n');\n console.log(info.join('\\n') + '\\n');\n }\n\n return config;\n}\n\nfunction convert(value, mapping) {\n const val = mapping.convertor(value);\n const validationResult = isValid(val, mapping.validator);\n if (validationResult === true) {\n return val;\n }\n\n console.log(\n warning(`There was a problem when trying to automatically convert ${chalk.bold(mapping.name)}. This ` +\n `value will be ignored.`)\n );\n console.log(\n `Received ${chalk.underline(value)} and it was converted to ${chalk.underline(val)}.`, validationResult, '\\n'\n );\n}\n"
},
{
"__docId__": 5,
"kind": "function",
"static": true,
"variation": null,
"name": "buildCompleteConfig",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~buildCompleteConfig",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{buildCompleteConfig}",
"description": "Builds the complete configuration objects.",
"lineNumber": 35,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Object} - The result of with the built configurations."
}
],
"params": [
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": false,
"name": "debug",
"description": "If debug mode should be enabled, logs some extra information."
},
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "config",
"description": "The base configuration."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "meta",
"description": "The base meta configuration."
},
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "newConfig",
"description": "The new configuration to base the merge on."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "newMeta",
"description": "The new meta configuration to base the merge on."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": true,
"defaultValue": "process.cwd()",
"defaultRaw": "process.cwd()",
"name": "directory",
"description": "The directory to resolve relative paths from."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": true,
"defaultValue": "true",
"defaultRaw": true,
"name": "validate",
"description": "If the newConfig and the newMeta structure should be validated."
}
],
"properties": [
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "extensionConfig",
"description": "The extensions merged configurations"
},
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "config",
"description": "The final configuration, with application configuration."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "meta",
"description": "The merged meta configuration."
}
],
"return": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": "The result of with the built configurations."
},
"generator": false
},
{
"__docId__": 6,
"kind": "function",
"static": true,
"variation": null,
"name": "getExtension",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~getExtension",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 84,
"undocument": true,
"params": [
{
"name": "extensionName",
"types": [
"*"
]
},
{
"name": "directory",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 7,
"kind": "function",
"static": true,
"variation": null,
"name": "validateConfigurationStructure",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~validateConfigurationStructure",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 100,
"undocument": true,
"params": [
{
"name": "config",
"types": [
"*"
]
},
{
"name": "applicationConfig",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 8,
"kind": "function",
"static": true,
"variation": null,
"name": "getSuggestions",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~getSuggestions",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{getSuggestions}",
"description": "Will create a string with suggestions for possible typos.",
"lineNumber": 137,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{string} - A string with possible suggestions for typos."
}
],
"params": [
{
"nullable": null,
"types": [
"string[]"
],
"spread": false,
"optional": false,
"name": "current",
"description": "The current values that might be incorrect."
},
{
"nullable": null,
"types": [
"string[]"
],
"spread": false,
"optional": false,
"name": "possible",
"description": "All the possible correct values."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": true,
"defaultValue": "false",
"defaultRaw": false,
"name": "command",
"description": "If the suggestion should be managed as a command."
}
],
"return": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": "A string with possible suggestions for typos."
},
"generator": false
},
{
"__docId__": 9,
"kind": "function",
"static": true,
"variation": null,
"name": "generateCommandsDocumentation",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~generateCommandsDocumentation",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{generateCommandsDocumentation}",
"description": "Generates a string with information about all the possible commands.",
"lineNumber": 179,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{string} - A string with documentation based on the available commands."
}
],
"params": [
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "commands",
"description": "The Roc config object, uses commands from it."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "commandsmeta",
"description": "The Roc meta config object, uses commands from it."
}
],
"return": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": "A string with documentation based on the available commands."
},
"generator": false
},
{
"__docId__": 10,
"kind": "function",
"static": true,
"variation": null,
"name": "getCommandOptionsAsString",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~getCommandOptionsAsString",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 208,
"undocument": true,
"params": [
{
"name": "command",
"optional": true,
"types": [
"{}"
],
"defaultRaw": {},
"defaultValue": "{}"
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 11,
"kind": "function",
"static": true,
"variation": null,
"name": "generateCommandDocumentation",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~generateCommandDocumentation",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{generateCommandDocumentation}",
"description": "Generates a string with information about a specific command.",
"lineNumber": 227,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{string} - A string with documentation based on the selected commands."
}
],
"params": [
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "settings",
"description": "The Roc config object, uses settings from it."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "commands+meta",
"description": "The Roc meta config object, uses commands and settings from it."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "command",
"description": "The selected command."
},
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "name",
"description": "The name of the cli."
}
],
"return": {
"nullable": null,
"types": [
"string"
],
"spread": false,
"description": "A string with documentation based on the selected commands."
},
"generator": false
},
{
"__docId__": 12,
"kind": "function",
"static": true,
"variation": null,
"name": "generateCommandDocsHelper",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~generateCommandDocsHelper",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 278,
"undocument": true,
"params": [
{
"name": "body",
"types": [
"*"
]
},
{
"name": "header",
"types": [
"*"
]
},
{
"name": "options",
"types": [
"*"
]
},
{
"name": "name",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 13,
"kind": "function",
"static": true,
"variation": null,
"name": "parseOptions",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~parseOptions",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{parseOptions}",
"description": "Parses options and validates them.",
"lineNumber": 322,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Object} - Parsed options."
}
],
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "command",
"description": "The command to parse options for."
},
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "commands",
"description": "commands from {@link rocMetaConfig}."
},
{
"nullable": null,
"types": [
"Object[]"
],
"spread": false,
"optional": false,
"name": "options",
"description": "Options parsed by minimist."
}
],
"properties": [
{
"nullable": null,
"types": [
"object[]"
],
"spread": false,
"optional": false,
"name": "options",
"description": "The parsed options that was matched against the meta configuration for the command."
},
{
"nullable": null,
"types": [
"object[]"
],
"spread": false,
"optional": false,
"name": "rest",
"description": "The rest of the options that could not be matched against the configuration."
}
],
"return": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": "Parsed options."
},
"generator": false
},
{
"__docId__": 14,
"kind": "function",
"static": true,
"variation": null,
"name": "getMappings",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~getMappings",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{getMappings}",
"description": "Creates mappings between cli commands to their \"path\" in the configuration structure, their validator and type\nconvertor.",
"lineNumber": 371,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Object} - Properties are the cli command without leading dashes that maps to a {@link rocMapObject}."
}
],
"params": [
{
"nullable": null,
"types": [
"rocDocumentationObject"
],
"spread": false,
"optional": false,
"name": "documentationObject",
"description": "Documentation object to create mappings for."
}
],
"return": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": "Properties are the cli command without leading dashes that maps to a {@link rocMapObject}."
},
"generator": false
},
{
"__docId__": 15,
"kind": "function",
"static": true,
"variation": null,
"name": "getConvertor",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~getConvertor",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 396,
"undocument": true,
"params": [
{
"name": "value",
"types": [
"*"
]
},
{
"name": "name",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 16,
"kind": "function",
"static": true,
"variation": null,
"name": "parseArguments",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~parseArguments",
"access": null,
"export": true,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": "{parseArguments}",
"description": "Converts a set of arguments to {@link rocConfigSettings} object.",
"lineNumber": 445,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{Object} - The mapped Roc configuration settings object."
}
],
"params": [
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "args",
"description": "Arguments parsed from minimist."
},
{
"nullable": null,
"types": [
"Object"
],
"spread": false,
"optional": false,
"name": "mappings",
"description": "Result from {@link getMappings}."
}
],
"return": {
"nullable": null,
"types": [
"Object"
],
"spread": false,
"description": "The mapped Roc configuration settings object."
},
"generator": false
},
{
"__docId__": 17,
"kind": "function",
"static": true,
"variation": null,
"name": "convert",
"memberof": "src/cli/helpers.js",
"longname": "src/cli/helpers.js~convert",
"access": null,
"export": false,
"importPath": "roc/lib/cli/helpers.js",
"importStyle": null,
"description": null,
"lineNumber": 467,
"undocument": true,
"params": [
{
"name": "value",
"types": [
"*"
]
},
{
"name": "mapping",
"types": [
"*"
]
}
],
"return": {
"types": [
"*"
]
},
"generator": false
},
{
"__docId__": 18,
"kind": "file",
"static": true,
"variation": null,
"name": "src/cli/index.js",
"memberof": null,
"longname": "src/cli/index.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\nimport minimist from 'minimist';\nimport { isString } from 'lodash';\n\nimport { execute } from './execute';\nimport { getAbsolutePath } from '../helpers';\nimport { validate } from '../validation';\nimport { merge, appendConfig } from '../configuration';\nimport buildDocumentationObject from '../documentation/build-documentation-object';\nimport { getApplicationConfig } from '../configuration/helpers';\nimport {\n buildCompleteConfig,\n generateCommandsDocumentation,\n generateCommandDocumentation,\n parseOptions,\n getMappings,\n parseArguments,\n getSuggestions\n} from './helpers';\nimport { error as styleError } from '../helpers/style';\n\n/**\n * Invokes the Roc cli.\n *\n * @param {{version: string, name: string}} info - Information about the cli.\n * @param {rocConfig} initalConfig - The inital configuration, will be merged with the selected extensions and\n * application.\n * @param {rocMetaConfig} initalMeta - The inital meta configuration, will be merged with the selected extensions.\n * @param {string[]} [args=process.argv] - From where it should parse the arguments.\n *\n * @returns {undefined}\n */\nexport function runCli(info = {version: 'Unknown', name: 'Unknown'}, initalConfig, initalMeta, args = process.argv) {\n const {_, h, help, d, debug, v, version, c, config, D, directory, ...restArgs} = minimist(args.slice(2));\n\n // The first should be our command if there is one\n const [command, ...options] = _;\n\n // If version is selected output that and stop\n if (version || v) {\n return console.log(info.version);\n }\n\n // Possibe to set a command in debug mode\n const debugEnabled = (debug || d) ? true : false;\n\n // Get the application configuration path\n const applicationConfigPath = config || c;\n\n // Get the directory Path\n const directoryPath = getAbsolutePath(directory || D);\n\n // Build the complete config object\n const applicationConfig = getApplicationConfig(applicationConfigPath, directoryPath, debugEnabled);\n let { extensionConfig, config: configObject, meta: metaObject } =\n buildCompleteConfig(debugEnabled, initalConfig, initalMeta, applicationConfig, undefined, directoryPath);\n\n // If we have no command we will display some help information about all possible commands\n if (!command) {\n return console.log(generateCommandsDocumentation(extensionConfig, metaObject));\n }\n\n // If the command does not exist show error\n // Will ignore application configuration\n if (!extensionConfig.commands || !extensionConfig.commands[command]) {\n console.log(styleError('Invalid command'), '\\n');\n return console.log(getSuggestions([command], Object.keys(extensionConfig.commands)), '\\n');\n }\n\n // Show command help information if requested\n // Will ignore application configuration\n if (help || h) {\n return console.log(generateCommandDocumentation(extensionConfig, metaObject, command, info.name));\n }\n\n const parsedOptions = parseOptions(command, metaObject.commands, options);\n\n // Only parse arguments if the command accepts it\n if (metaObject.commands[command] && metaObject.commands[command].settings) {\n // Get config from application and only parse options that this command cares about.\n const filter = metaObject.commands[command].settings === true ? [] : metaObject.commands[command].settings;\n const documentationObject = buildDocumentationObject(configObject.settings, metaObject.settings, filter);\n\n const configuration = parseArguments(restArgs, getMappings(documentationObject));\n configObject = merge(configObject, {\n settings: configuration\n });\n\n // Validate configuration\n validate(configObject.settings, metaObject.settings, metaObject.commands[command].settings);\n }\n\n // Set the configuration object\n appendConfig(configObject);\n\n // If string run as shell command\n if (isString(configObject.commands[command])) {\n return execute(configObject.commands[command]);\n }\n\n // Run the command\n return configObject.commands[command]({\n debug: debugEnabled,\n configObject,\n metaObject,\n extensionConfig,\n parsedOptions\n });\n}\n"
},
{
"__docId__": 19,
"kind": "function",
"static": true,
"variation": null,
"name": "runCli",
"memberof": "src/cli/index.js",
"longname": "src/cli/index.js~runCli",
"access": null,
"export": true,
"importPath": "roc/lib/cli/index.js",
"importStyle": "{runCli}",
"description": "Invokes the Roc cli.",
"lineNumber": 34,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{undefined}"
}
],
"params": [
{
"nullable": null,
"types": [
"{version: string, name: string}"
],
"spread": false,
"optional": false,
"name": "info",
"description": "Information about the cli."
},
{
"nullable": null,
"types": [
"rocConfig"
],
"spread": false,
"optional": false,
"name": "initalConfig",
"description": "The inital configuration, will be merged with the selected extensions and\n application."
},
{
"nullable": null,
"types": [
"rocMetaConfig"
],
"spread": false,
"optional": false,
"name": "initalMeta",
"description": "The inital meta configuration, will be merged with the selected extensions."
},
{
"nullable": null,
"types": [
"string[]"
],
"spread": false,
"optional": true,
"defaultValue": "process.argv",
"defaultRaw": "process.argv",
"name": "args",
"description": "From where it should parse the arguments."
}
],
"return": {
"nullable": null,
"types": [
"undefined"
],
"spread": false,
"description": ""
},
"generator": false
},
{
"__docId__": 20,
"kind": "file",
"static": true,
"variation": null,
"name": "src/commands/helpers/default-prompt.js",
"memberof": null,
"longname": "src/commands/helpers/default-prompt.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\n/**\n * The default prompt options.\n */\nexport const defaultPrompt = [{\n type: 'input',\n name: 'rocAppName',\n message: 'What\\'s the name of your application?',\n default: 'my-roc-app',\n filter: (input) => input.toLowerCase().split(' ').join('-')\n}, {\n type: 'input',\n name: 'rocAppDesc',\n message: 'What\\'s the description for the application?',\n default: 'My Roc Application'\n}, {\n type: 'input',\n name: 'rocAppAuthor',\n message: 'Who\\'s the author of the application?',\n default: 'John Doe'\n}, {\n type: 'input',\n name: 'rocAppLicense',\n message: 'What\\'s the license for the application?',\n default: 'MIT'\n}];\n"
},
{
"__docId__": 21,
"kind": "variable",
"static": true,
"variation": null,
"name": "defaultPrompt",
"memberof": "src/commands/helpers/default-prompt.js",
"longname": "src/commands/helpers/default-prompt.js~defaultPrompt",
"access": null,
"export": true,
"importPath": "roc/lib/commands/helpers/default-prompt.js",
"importStyle": "{defaultPrompt}",
"description": "The default prompt options.",
"lineNumber": 6,
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 22,
"kind": "file",
"static": true,
"variation": null,
"name": "src/commands/helpers/general.js",
"memberof": null,
"longname": "src/commands/helpers/general.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\nimport { isObject } from 'lodash';\nimport { fileExists, getRocDependencies, getPackageJson } from '../../helpers';\n\n/**\n * Validates if a directory seems to be a Roc application project.\n * A valid Roc project should have a package.json file that contains some dependecy that match 'roc-*' or\n * a `roc.config.js` file.\n *\n * @param {string} directory - The directory to validate.\n *\n * @returns {boolean} - Whether or not it is a valid Roc project.\n */\nexport function validRocProject(directory) {\n const packageJson = getPackageJson(directory);\n\n return !(!isObject(packageJson) ||\n !fileExists('roc.config.js', directory) && !getRocDependencies(packageJson).length);\n}\n"
},
{
"__docId__": 23,
"kind": "function",
"static": true,
"variation": null,
"name": "validRocProject",
"memberof": "src/commands/helpers/general.js",
"longname": "src/commands/helpers/general.js~validRocProject",
"access": null,
"export": true,
"importPath": "roc/lib/commands/helpers/general.js",
"importStyle": "{validRocProject}",
"description": "Validates if a directory seems to be a Roc application project.\nA valid Roc project should have a package.json file that contains some dependecy that match 'roc-*' or\na `roc.config.js` file.",
"lineNumber": 15,
"unknown": [
{
"tagName": "@returns",
"tagValue": "{boolean} - Whether or not it is a valid Roc project."
}
],
"params": [
{
"nullable": null,
"types": [
"string"
],
"spread": false,
"optional": false,
"name": "directory",
"description": "The directory to validate."
}
],
"return": {
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"description": "Whether or not it is a valid Roc project."
},
"generator": false
},
{
"__docId__": 24,
"kind": "file",
"static": true,
"variation": null,
"name": "src/commands/helpers/github.js",
"memberof": null,
"longname": "src/commands/helpers/github.js",
"access": null,
"description": null,
"lineNumber": 1,
"content": "import 'source-map-support/register';\n\nimport request from 'request';\nimport tar from 'tar';\nimport zlib from 'zlib';\nimport temp from 'temp';\n\n// Automatically track and cleanup files at exit\ntemp.track();\n\n/**\n * Fetches an array of all the tags for a Github repo, used as possible versions for a template.\n *\n * @param {string} packageName - A package name, expected to match \"username/repo\"\n *\n * @returns {object[]} - Array of tags/versions for the package\n */\nexport function getVersions(packageName) {\n if (!packageName) {\n throw new Error('No packageName was given.');\n }\n\n return new Promise((resolve, reject) => {\n request.get({\n url: `https://api.github.com/repos/${packageName}/tags`,\n headers: {\n 'User-Agent': 'request'\n }\n }, (error, resp, body) => {\n if (error) {\n return reject(error);\n }\n\n if (resp.statusCode !== 200) {\n return reject(new Error(packageName + ': returned ' + resp.statusCode + '\\n\\nbody:\\n' + body));\n }\n\n return resolve(JSON.parse(body