diff --git a/src/commands/transpile.js b/src/commands/transpile.js index ec012ee..078441c 100644 --- a/src/commands/transpile.js +++ b/src/commands/transpile.js @@ -6,10 +6,20 @@ const path = require("path"); const glob = require("glob"); const { log } = require("console"); + /** - * Transpile files based on provided patterns and options. - * @param {string[]} patterns - Glob patterns for source files. - * @param {Object} options - CLI options (`--output`, `--silent`, etc.). + * Transpiles files based on specified patterns and options. + * + * @param {string[]} patterns - Array of glob patterns to match files for transpilation. + * @param {Object} options - Options for the transpilation process. + * @param {string} [options.config] - Path to the configuration file. + * @param {string|string[]} [options.exclude] - Patterns to exclude from transpilation. + * @param {string} [options.output] - Directory to output transpiled files. + * @param {boolean} [options.silent] - If true, suppresses log output. + * @param {boolean} [options.verbose] - If true, enables verbose logging. + * + * @throws Will throw an error if an invalid log level is provided. + * @throws Will exit the process if an error occurs during file matching. */ function transpileCommand(patterns, options) { if (!Array.isArray(patterns) || typeof options !== 'object') { diff --git a/src/utils/configUtils.js b/src/utils/configUtils.js index d488381..5e0f414 100644 --- a/src/utils/configUtils.js +++ b/src/utils/configUtils.js @@ -2,6 +2,16 @@ const fs = require("fs"); const path = require("path"); const os = require("os"); +/** + * Loads and parses a configuration file from a specified path or default locations. + * + * If a `configPath` is provided, it attempts to load the configuration from that path. + * If not, it checks for a project-specific configuration file in the current working directory, + * and if not found, it checks for a global configuration file in the user's home directory. + * + * @param {string} [configPath] - Optional path to a specific configuration file. + * @returns {Object} The parsed configuration object, or an empty object if no valid configuration file is found. + */ const loadConfig = (configPath) => { const CONFIG_FILES = { PROJECT: "contract-shield.config.json", diff --git a/src/utils/logUtils.js b/src/utils/logUtils.js index 1c6fb87..ab13216 100644 --- a/src/utils/logUtils.js +++ b/src/utils/logUtils.js @@ -34,9 +34,24 @@ const levelColors = { const validLogLevels = ["error", "warn", "info", "debug"]; +/** + * Logs a message to the console with a specified log level. + * + * @param {string} level - The log level (e.g., 'info', 'error') to display. + * @param {string} message - The message to be logged. + */ const writeToConsole = (level, message) => { console.log(colors.green(`[${level.toUpperCase()}]`), message); }; + +/** + * Logs a message at a specified log level and optionally writes it to the console. + * + * @param {string} level - The log level for the message. Must be one of: "error", "warn", "info", "debug". + * @param {string} message - The message to be logged. + * @param {boolean} isSilent - If true, the message will not be written to the console. + * @throws {Error} Throws an error if the log level is invalid. + */ const logMessage = (level, message, isSilent) => { if (!validLogLevels.includes(level)) { throw new Error(