Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/configUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions src/utils/logUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down