| | |
| | | |
| | | // TODO add originPath to PathItem for better errors |
| | | /** |
| | | * Defines the path item type used by this module. |
| | | * @typedef {object} PathItem |
| | | * @property {Schema} schema the part of the schema |
| | | * @property {string} path the path in the config |
| | |
| | | /** @typedef {string | number | boolean | RegExp} Value */ |
| | | |
| | | /** |
| | | * Defines the problem type used by this module. |
| | | * @typedef {object} Problem |
| | | * @property {ProblemType} type |
| | | * @property {string} path |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the local problem type used by this module. |
| | | * @typedef {object} LocalProblem |
| | | * @property {ProblemType} type |
| | | * @property {string} path |
| | |
| | | /** @typedef {string | number | boolean | EnumValueObject | EnumValueArray | null} EnumValue */ |
| | | |
| | | /** |
| | | * Defines the argument config type used by this module. |
| | | * @typedef {object} ArgumentConfig |
| | | * @property {string=} description |
| | | * @property {string=} negatedDescription |
| | |
| | | /** @typedef {"string" | "number" | "boolean"} SimpleType */ |
| | | |
| | | /** |
| | | * Defines the argument type used by this module. |
| | | * @typedef {object} Argument |
| | | * @property {string | undefined} description |
| | | * @property {SimpleType} simpleType |
| | |
| | | /** @typedef {Record<string, EXPECTED_ANY>} ObjectConfiguration */ |
| | | |
| | | /** |
| | | * Returns object of arguments. |
| | | * @param {Schema=} schema a json schema to create arguments for (by default webpack schema is used) |
| | | * @returns {Flags} object of arguments |
| | | */ |
| | |
| | | const flags = {}; |
| | | |
| | | /** |
| | | * Path to argument name. |
| | | * @param {string} input input |
| | | * @returns {string} result |
| | | */ |
| | |
| | | .toLowerCase(); |
| | | |
| | | /** |
| | | * Returns schema part. |
| | | * @param {string} path path |
| | | * @returns {Schema} schema part |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns description. |
| | | * @param {PathItem[]} path path in the schema |
| | | * @returns {string | undefined} description |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets negated description. |
| | | * @param {PathItem[]} path path in the schema |
| | | * @returns {string | undefined} negative description |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets reset description. |
| | | * @param {PathItem[]} path path in the schema |
| | | * @returns {string | undefined} reset description |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Schema to argument config. |
| | | * @param {Schema} schemaPart schema |
| | | * @returns {Pick<ArgumentConfig, "type" | "values"> | undefined} partial argument config |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Adds the provided path to this object. |
| | | * @param {PathItem[]} path path in the schema |
| | | * @returns {void} |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Adds the provided path to this object. |
| | | * @param {PathItem[]} path full path in schema |
| | | * @param {boolean} multiple inside of an array |
| | | * @returns {number} number of arguments added |
| | |
| | | // TODO support `not` and `if/then/else` |
| | | // TODO support `const`, but we don't use it on our schema |
| | | /** |
| | | * Returns added arguments. |
| | | * @param {Schema} schemaPart the current schema |
| | | * @param {string} schemaPath the current path in the schema |
| | | * @param {PathItem[]} path all previous visited schemaParts |
| | |
| | | return flags; |
| | | }; |
| | | |
| | | /** @type {WeakMap<EXPECTED_OBJECT, number>} */ |
| | | const cliAddedItems = new WeakMap(); |
| | | |
| | | /** @typedef {string | number} Property */ |
| | | |
| | | /** |
| | | * Gets object and property. |
| | | * @param {ObjectConfiguration} config configuration |
| | | * @param {string} schemaPath path in the config |
| | | * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Updates value using the provided config. |
| | | * @param {ObjectConfiguration} config configuration |
| | | * @param {string} schemaPath path in the config |
| | | * @param {ParsedValue} value parsed value |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Process argument config. |
| | | * @param {ArgumentConfig} argConfig processing instructions |
| | | * @param {ObjectConfiguration} config configuration |
| | | * @param {Value} value the value |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets expected value. |
| | | * @param {ArgumentConfig} argConfig processing instructions |
| | | * @returns {string | undefined} expected message |
| | | */ |
| | |
| | | |
| | | /** @typedef {null | string | number | boolean | RegExp | EnumValue | []} ParsedValue */ |
| | | |
| | | const DECIMAL_NUMBER_REGEXP = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i; |
| | | |
| | | /** |
| | | * Parses value for argument config. |
| | | * @param {ArgumentConfig} argConfig processing instructions |
| | | * @param {Value} value the value |
| | | * @returns {ParsedValue | undefined} parsed value |
| | |
| | | break; |
| | | case "number": |
| | | if (typeof value === "number") return value; |
| | | if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) { |
| | | if (typeof value === "string" && DECIMAL_NUMBER_REGEXP.test(value)) { |
| | | const n = Number(value); |
| | | if (!Number.isNaN(n)) return n; |
| | | } |
| | |
| | | /** @typedef {Record<string, Value[]>} Values */ |
| | | |
| | | /** |
| | | * Processes the provided arg. |
| | | * @param {Flags} args object of arguments |
| | | * @param {ObjectConfiguration} config configuration |
| | | * @param {Values} values object with values |
| | |
| | | continue; |
| | | } |
| | | /** |
| | | * Processes the provided value. |
| | | * @param {Value} value value |
| | | * @param {number | undefined} i index |
| | | */ |
| | | const processValue = (value, i) => { |
| | | /** @type {Problem[]} */ |
| | | const currentProblems = []; |
| | | for (const argConfig of arg.configs) { |
| | | const problem = processArgumentConfig(argConfig, config, value, i); |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Checks whether this object is color supported. |
| | | * @returns {boolean} true when colors supported, otherwise false |
| | | */ |
| | | const isColorSupported = () => { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {number} index index |
| | | * @param {string} string string |
| | | * @param {string} close close |
| | |
| | | ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace)); |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {number} index index to replace |
| | | * @param {string} string string |
| | | * @param {string} open open string |
| | |
| | | /** @typedef {(value: EXPECTED_ANY) => string} PrintFunction */ |
| | | |
| | | /** |
| | | * Returns function to create color. |
| | | * @param {string} open open string |
| | | * @param {string} close close string |
| | | * @param {string=} replace extra replace |
| | |
| | | : ""; |
| | | |
| | | /** |
| | | * Returns result. |
| | | * @param {number} open open code |
| | | * @param {number} close close code |
| | | * @param {string=} replace extra replace |
| | |
| | | filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace); |
| | | |
| | | /** |
| | | * @typedef {{ |
| | | * reset: PrintFunction |
| | | * bold: PrintFunction |
| | | * dim: PrintFunction |
| | | * italic: PrintFunction |
| | | * underline: PrintFunction |
| | | * inverse: PrintFunction |
| | | * hidden: PrintFunction |
| | | * strikethrough: PrintFunction |
| | | * black: PrintFunction |
| | | * red: PrintFunction |
| | | * green: PrintFunction |
| | | * yellow: PrintFunction |
| | | * blue: PrintFunction |
| | | * magenta: PrintFunction |
| | | * cyan: PrintFunction |
| | | * white: PrintFunction |
| | | * gray: PrintFunction |
| | | * bgBlack: PrintFunction |
| | | * bgRed: PrintFunction |
| | | * bgGreen: PrintFunction |
| | | * bgYellow: PrintFunction |
| | | * bgBlue: PrintFunction |
| | | * bgMagenta: PrintFunction |
| | | * bgCyan: PrintFunction |
| | | * bgWhite: PrintFunction |
| | | * blackBright: PrintFunction |
| | | * redBright: PrintFunction |
| | | * greenBright: PrintFunction |
| | | * yellowBright: PrintFunction |
| | | * blueBright: PrintFunction |
| | | * magentaBright: PrintFunction |
| | | * cyanBright: PrintFunction |
| | | * whiteBright: PrintFunction |
| | | * bgBlackBright: PrintFunction |
| | | * bgRedBright: PrintFunction |
| | | * bgGreenBright: PrintFunction |
| | | * bgYellowBright: PrintFunction |
| | | * bgBlueBright: PrintFunction |
| | | * bgMagentaBright: PrintFunction |
| | | * bgCyanBright: PrintFunction |
| | | * bgWhiteBright: PrintFunction |
| | | }} Colors */ |
| | | * Defines the colors type used by this module. |
| | | * @typedef {{ reset: PrintFunction, bold: PrintFunction, dim: PrintFunction, italic: PrintFunction, underline: PrintFunction, inverse: PrintFunction, hidden: PrintFunction, strikethrough: PrintFunction, black: PrintFunction, red: PrintFunction, green: PrintFunction, yellow: PrintFunction, blue: PrintFunction, magenta: PrintFunction, cyan: PrintFunction, white: PrintFunction, gray: PrintFunction, bgBlack: PrintFunction, bgRed: PrintFunction, bgGreen: PrintFunction, bgYellow: PrintFunction, bgBlue: PrintFunction, bgMagenta: PrintFunction, bgCyan: PrintFunction, bgWhite: PrintFunction, blackBright: PrintFunction, redBright: PrintFunction, greenBright: PrintFunction, yellowBright: PrintFunction, blueBright: PrintFunction, magentaBright: PrintFunction, cyanBright: PrintFunction, whiteBright: PrintFunction, bgBlackBright: PrintFunction, bgRedBright: PrintFunction, bgGreenBright: PrintFunction, bgYellowBright: PrintFunction, bgBlueBright: PrintFunction, bgMagentaBright: PrintFunction, bgCyanBright: PrintFunction, bgWhiteBright: PrintFunction }} Colors |
| | | */ |
| | | |
| | | /** |
| | | * Defines the colors options type used by this module. |
| | | * @typedef {object} ColorsOptions |
| | | * @property {boolean=} useColor force use colors |
| | | */ |
| | | |
| | | /** |
| | | * Creates a colors from the provided colors option. |
| | | * @param {ColorsOptions=} options options |
| | | * @returns {Colors} colors |
| | | */ |