Skip to content

Commit aba8aee

Browse files
authored
Merge pull request #9 from ioncakephper:chore/use-quickly
update transpile.js, configUtils.js and logUtils.js
2 parents cad0775 + 9253451 commit aba8aee

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/commands/transpile.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ const path = require("path");
66
const glob = require("glob");
77
const { log } = require("console");
88

9+
910
/**
10-
* Transpile files based on provided patterns and options.
11-
* @param {string[]} patterns - Glob patterns for source files.
12-
* @param {Object} options - CLI options (`--output`, `--silent`, etc.).
11+
* Transpiles files based on specified patterns and options.
12+
*
13+
* @param {string[]} patterns - Array of glob patterns to match files for transpilation.
14+
* @param {Object} options - Options for the transpilation process.
15+
* @param {string} [options.config] - Path to the configuration file.
16+
* @param {string|string[]} [options.exclude] - Patterns to exclude from transpilation.
17+
* @param {string} [options.output] - Directory to output transpiled files.
18+
* @param {boolean} [options.silent] - If true, suppresses log output.
19+
* @param {boolean} [options.verbose] - If true, enables verbose logging.
20+
*
21+
* @throws Will throw an error if an invalid log level is provided.
22+
* @throws Will exit the process if an error occurs during file matching.
1323
*/
1424
function transpileCommand(patterns, options) {
1525
if (!Array.isArray(patterns) || typeof options !== 'object') {

src/utils/configUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ const fs = require("fs");
22
const path = require("path");
33
const os = require("os");
44

5+
/**
6+
* Loads and parses a configuration file from a specified path or default locations.
7+
*
8+
* If a `configPath` is provided, it attempts to load the configuration from that path.
9+
* If not, it checks for a project-specific configuration file in the current working directory,
10+
* and if not found, it checks for a global configuration file in the user's home directory.
11+
*
12+
* @param {string} [configPath] - Optional path to a specific configuration file.
13+
* @returns {Object} The parsed configuration object, or an empty object if no valid configuration file is found.
14+
*/
515
const loadConfig = (configPath) => {
616
const CONFIG_FILES = {
717
PROJECT: "contract-shield.config.json",

src/utils/logUtils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,24 @@ const levelColors = {
3434

3535
const validLogLevels = ["error", "warn", "info", "debug"];
3636

37+
/**
38+
* Logs a message to the console with a specified log level.
39+
*
40+
* @param {string} level - The log level (e.g., 'info', 'error') to display.
41+
* @param {string} message - The message to be logged.
42+
*/
3743
const writeToConsole = (level, message) => {
3844
console.log(colors.green(`[${level.toUpperCase()}]`), message);
3945
};
46+
47+
/**
48+
* Logs a message at a specified log level and optionally writes it to the console.
49+
*
50+
* @param {string} level - The log level for the message. Must be one of: "error", "warn", "info", "debug".
51+
* @param {string} message - The message to be logged.
52+
* @param {boolean} isSilent - If true, the message will not be written to the console.
53+
* @throws {Error} Throws an error if the log level is invalid.
54+
*/
4055
const logMessage = (level, message, isSilent) => {
4156
if (!validLogLevels.includes(level)) {
4257
throw new Error(

0 commit comments

Comments
 (0)