From 5138d39f4271d059de0d818b6e089be19fcf3a84 Mon Sep 17 00:00:00 2001 From: Ion Gireada Date: Tue, 3 Jun 2025 20:05:25 +0300 Subject: [PATCH 1/2] update transpile.js --- src/commands/transpile.js | 112 +++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/src/commands/transpile.js b/src/commands/transpile.js index 078441c..b95e0d6 100644 --- a/src/commands/transpile.js +++ b/src/commands/transpile.js @@ -4,8 +4,6 @@ const colors = require("ansi-colors"); const fs = require("fs"); const path = require("path"); const glob = require("glob"); -const { log } = require("console"); - /** * Transpiles files based on specified patterns and options. @@ -18,62 +16,74 @@ const { log } = require("console"); * @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') { - throw new Error("Invalid input: `patterns` should be an array and `options` should be an object."); - } - - const config = loadConfig(options.config); - const finalPatterns = patterns.length ? patterns : config.patterns || ["**/*.js"]; - let excludePatterns = Array.isArray(options.exclude) ? options.exclude : [options.exclude || config.exclude || []].flat(); - - if (excludePatterns.length) { - logMessage("info", `Excluding patterns: ${excludePatterns.join(", ")}`, options.silent); - } - - const outputDir = options.output || config.output || "dist"; - const isSilent = options.silent ?? config.silent; - const isVerbose = options.verbose ?? config.verbose; - - if (isSilent && isVerbose) { - console.log(colors.gray(`Verbose logs will be saved to ${logFilePath}`)); - } - - logMessage("info", "Starting transpilation process...", isSilent); - - try { - const files = glob.sync(finalPatterns.join("|"), { ignore: excludePatterns, nodir: true }); - - if (!files.length) { - logMessage("warn", "No files matched for transpilation.", isSilent); - return; + const config = loadConfig(options.config); + + const finalPatterns = patterns.length > 0 ? patterns : config.patterns || ["**/*.js"]; + let excludePatterns = options.exclude || config.exclude || []; + if (typeof excludePatterns === "string") { + excludePatterns = [excludePatterns]; // Convert to array if needed + } + + const outputDir = options.output || config.output || "dist"; + const isSilent = options.silent ?? config.silent; + const isVerbose = options.verbose ?? config.verbose; + + logMessage("info", "Starting transpilation process...", isSilent); + + if (!isSilent && isVerbose) { + logMessage("debug", `Using output directory: ${outputDir}`, false); } - logMessage("info", `Processing ${files.length} files...`, isSilent); + try { + const files = glob.sync(finalPatterns.join("|"), { ignore: excludePatterns, nodir: true }); + + if (files.length === 0) { + logMessage("warn", "No files matched for transpilation.", isSilent); + return; + } - files.forEach(file => { - logMessage("info", `Transpiling: ${file}`, isSilent); + logMessage("info", `Processing ${files.length} files...`, isSilent); - try { - const destinationFile = path.join(outputDir, path.dirname(file), path.basename(file)); - if (!fs.existsSync(path.dirname(destinationFile))) { - fs.mkdirSync(path.dirname(destinationFile), { recursive: true }); + if (!isSilent && isVerbose) { + logMessage("debug", `Matched files: ${files.join(", ")}`, false); } - fs.copyFileSync(file, destinationFile); - logMessage("info", `Successfully transpiled: ${file} -> ${destinationFile}`, isSilent); - } catch (error) { - logMessage("error", `Failed to transpile ${file}: ${error.message}`, isSilent); - } - }); - - logMessage("info", "Transpilation process completed!", isSilent); - } catch (error) { - logMessage("error", `Error matching files: ${error.message}`, isSilent); - process.exit(1); - } + + const failedFiles = []; + + for (const file of files) { + logMessage("info", `Transpiling: ${file}`, isSilent); + + if (!isSilent && isVerbose) { + logMessage("debug", `Source directory: ${path.dirname(file)}`, false); + } + + try { + const destinationFile = path.join(outputDir, path.dirname(file), path.basename(file)); + + if (!fs.existsSync(path.dirname(destinationFile))) { + fs.mkdirSync(path.dirname(destinationFile), { recursive: true }); + } + + fs.copyFileSync(file, destinationFile); + logMessage("info", `Successfully transpiled: ${file} -> ${destinationFile}`, isSilent); + } catch (error) { + logMessage("error", `Failed to transpile ${file}: ${error.message}`, isSilent); + failedFiles.push(file); + } + } + + logMessage("info", "Transpilation process completed!", isSilent); + + if (failedFiles.length > 0) { + logMessage("warn", `Failed to transpile ${failedFiles.length} files: ${failedFiles.join(", ")}`, isSilent); + } + } catch (error) { + logMessage("error", `Error matching files: ${error.message}`, false); + process.exit(1); + } } -module.exports = { transpileCommand }; +module.exports = { transpileCommand }; \ No newline at end of file From 291fc7afc9efa3712d3f20decd8b1ec3dbc180f1 Mon Sep 17 00:00:00 2001 From: Ion Gireada Date: Tue, 3 Jun 2025 20:12:35 +0300 Subject: [PATCH 2/2] update transpile.js --- src/commands/transpile.js | 129 +++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 52 deletions(-) diff --git a/src/commands/transpile.js b/src/commands/transpile.js index b95e0d6..423aa5f 100644 --- a/src/commands/transpile.js +++ b/src/commands/transpile.js @@ -19,71 +19,96 @@ const glob = require("glob"); * @throws Will exit the process if an error occurs during file matching. */ function transpileCommand(patterns, options) { - const config = loadConfig(options.config); - - const finalPatterns = patterns.length > 0 ? patterns : config.patterns || ["**/*.js"]; - let excludePatterns = options.exclude || config.exclude || []; - if (typeof excludePatterns === "string") { - excludePatterns = [excludePatterns]; // Convert to array if needed + const config = loadConfig(options.config); + + const finalPatterns = + patterns.length > 0 ? patterns : config.patterns || ["**/*.js"]; + let excludePatterns = options.exclude || config.exclude || []; + if (typeof excludePatterns === "string") { + excludePatterns = [excludePatterns]; // Convert to array if needed + } + + const outputDir = options.output || config.output || "dist"; + const isSilent = options.silent ?? config.silent; + const isVerbose = options.verbose ?? config.verbose; + + logMessage("info", "Starting transpilation process...", isSilent); + + if (!isSilent && isVerbose) { + logMessage("debug", `Using output directory: ${outputDir}`, false); + } + + try { + const files = glob.sync(finalPatterns.join("|"), { + ignore: excludePatterns, + nodir: true, + }); + + if (files.length === 0) { + logMessage("warn", "No files matched for transpilation.", isSilent); + return; } - const outputDir = options.output || config.output || "dist"; - const isSilent = options.silent ?? config.silent; - const isVerbose = options.verbose ?? config.verbose; - - logMessage("info", "Starting transpilation process...", isSilent); + logMessage("info", `Processing ${files.length} files...`, isSilent); if (!isSilent && isVerbose) { - logMessage("debug", `Using output directory: ${outputDir}`, false); + logMessage("debug", `Matched files: ${files.join(", ")}`, false); } - try { - const files = glob.sync(finalPatterns.join("|"), { ignore: excludePatterns, nodir: true }); - - if (files.length === 0) { - logMessage("warn", "No files matched for transpilation.", isSilent); - return; - } - - logMessage("info", `Processing ${files.length} files...`, isSilent); + const failedFiles = []; - if (!isSilent && isVerbose) { - logMessage("debug", `Matched files: ${files.join(", ")}`, false); - } + for (const file of files) { + logMessage("info", `Transpiling: ${file}`, isSilent); - const failedFiles = []; + if (!isSilent && isVerbose) { + logMessage("debug", `Source directory: ${path.dirname(file)}`, false); + } - for (const file of files) { - logMessage("info", `Transpiling: ${file}`, isSilent); + try { + const destinationFile = path.join( + outputDir, + path.dirname(file), + path.basename(file) + ); - if (!isSilent && isVerbose) { - logMessage("debug", `Source directory: ${path.dirname(file)}`, false); - } - - try { - const destinationFile = path.join(outputDir, path.dirname(file), path.basename(file)); - - if (!fs.existsSync(path.dirname(destinationFile))) { - fs.mkdirSync(path.dirname(destinationFile), { recursive: true }); - } - - fs.copyFileSync(file, destinationFile); - logMessage("info", `Successfully transpiled: ${file} -> ${destinationFile}`, isSilent); - } catch (error) { - logMessage("error", `Failed to transpile ${file}: ${error.message}`, isSilent); - failedFiles.push(file); - } + if (!fs.existsSync(path.dirname(destinationFile))) { + fs.mkdirSync(path.dirname(destinationFile), { recursive: true }); } - logMessage("info", "Transpilation process completed!", isSilent); + fs.copyFileSync(file, destinationFile); + logMessage( + "info", + `Successfully transpiled: ${file} -> ${destinationFile}`, + isSilent + ); + } catch (error) { + logMessage( + "error", + `Failed to transpile ${file}: ${error.message}`, + isSilent + ); + failedFiles.push(file); + } + } - if (failedFiles.length > 0) { - logMessage("warn", `Failed to transpile ${failedFiles.length} files: ${failedFiles.join(", ")}`, isSilent); - } - } catch (error) { - logMessage("error", `Error matching files: ${error.message}`, false); - process.exit(1); + logMessage("info", "Transpilation process completed!", isSilent); + + if (failedFiles.length > 0) { + logMessage( + "warn", + `Failed to transpile ${failedFiles.length} files: ${failedFiles.join( + ", " + )}`, + isSilent + ); + process.exit(1); // Indicate partial success with some failures + } else { + process.exit(0); // Indicate full success } + } catch (error) { + logMessage("error", `Error matching files: ${error.message}`, false); + process.exit(2); // Indicate unrecoverable failure + } } -module.exports = { transpileCommand }; \ No newline at end of file +module.exports = { transpileCommand };