1.0.5 • Published 4 months ago

logaway v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

logaway

A CLI tool to remove console.log statements from JavaScript and TypeScript files.

Note: This tool only removes console.log() statements and will not affect other console methods like console.info(), console.error(), console.warn(), etc.

Installation

Global Installation

Package ManagerCommand
npmnpm install -g logaway
yarnyarn global add logaway
pnpmpnpm add -g logaway
bunbun add -g logaway

Local Installation (as dev dependency)

Package ManagerCommand
npmnpm install --save-dev logaway
yarnyarn add --dev logaway
pnpmpnpm add -D logaway
bunbun add -d logaway

Then add a script to your package.json:

{
  "scripts": {
    "logaway": "logaway"
  }
}

Usage

Global Usage

logaway [options]

Local Usage (with npm scripts)

npm run logaway [options]

Note: When using npm scripts, you need to add -- before passing arguments to the underlying command.

For example:

npm run logaway --targetDir=./app --preview

Options

  • --targetDir, -t - Directory to process (default: "./src")
  • --ignoredDirs, -d <dir1,dir2> - Comma-separated list of directories to ignore
  • --ignoredFiles, -f <file1,file2> - Comma-separated list of files to ignore (default: "logger.ts")
  • --extensions, -e <.js,.ts> - Comma-separated list of file extensions to process (default: ".js,.jsx,.ts,.tsx")
  • --methods, -m <method1,method2> - Comma-separated list of console methods to remove (default: "log")
  • --preview, -s - Preview changes without modifying files
  • --verbose, -v - Show detailed information for each file
  • --help, -h - Show help information

Examples

# Process the default src directory
logaway

# Specify a target directory and ignore some folders
logaway --targetDir=./app --ignoredDirs=node_modules,dist

# Using shortcuts
logaway -t ./app -d node_modules,dist -e .js,.ts

# Remove console.log, console.info and console.warn statements
logaway --methods=log,info,warn

# Dry run to preview changes
logaway --preview

Examples of Removed Logs

This tool will detect and remove various forms of console.log statements, including:

  1. Simple string log
console.log("User logged in successfully");
  1. Variable log
console.log(userId);
  1. String concatenation
console.log("User ID: " + userId);
  1. Template literals
console.log(`User ${userName} (ID: ${userId}) logged in at ${loginTime}`);
  1. Multiple arguments
console.log("Authentication:", status, "for user", userName);
  1. Object logging
console.log({ userId, userName, email, lastLogin });
  1. Array logging
console.log(userPermissions);
  1. Logging function results
console.log(calculateTotalPrice(items));
  1. Conditional logging with ternary
console.log(
  `Login ${isSuccessful ? "successful" : "failed"} for user ${userName}`
);
  1. JSON stringified object
console.log(JSON.stringify(userData, null, 2));
  1. Destructuring in log
console.log({ name, email, ...otherUserData });
  1. Multiline string log
console.log(`User profile:
  Name: ${userName}
  Email: ${email}
  Role: ${role}
  Last active: ${lastActive}`);
  1. Commented log
// console.log("Debugging user authentication");
  1. Logging with expression
console.log("Cart total: $" + (subtotal + tax).toFixed(2));
  1. Nested object logging
console.log("User settings:", user.preferences.notifications);
  1. Error context logging
console.log("Error in authentication process:", error.message);
  1. Array method result
console.log(users.filter((user) => user.isActive).map((user) => user.name));
  1. Conditional log with && operator
console.log(`#${isDebug ? "DEBUG" : "INFO"}`);
  1. Console log with spread operator
console.log("User data:", ...userData);
  1. Logging with ternary and complex expressions
console.log(
  `Payment ${
    payment.status === "completed" ? "succeeded" : "failed"
  }: ${formatCurrency(payment.amount)}`
);
  1. Optional chaining with nullish coalescing:
console.log(user?.profile?.settings ?? "No settings");
  1. Console.log with generator function results:
console.log(generator.next().value);
  1. Console.log with spread operator and nullish coalescing:
console.log("User data:", ...userData, "Default:", defaultValue ?? "No value");
  1. Console.log with computed property names in objects:
console.log({ ["computed" + "Name"]: value });
  1. Console.log with new operator
console.log(new Date());
  1. Styled console.log with CSS directives
console.log("%cStyled log message", "color: blue; font-weight: bold");
  1. Async function results
console.log(async () => await fetchUserData(userId));
  1. Console.log with multiple conditionals
console.log(
  importantData || "No data available",
  attempts > 3 ? "Retry limit exceeded" : "Retrying..."
);
  1. Console.log with immediately invoked function expression (IIFE)
console.log(
  (function () {
    return calculateComplexValue(a, b);
  })()
);
  1. Console.log with tagged template literals
console.log(debug`User authentication ${status} with token ${token}`);
  1. Console.log with complex conditional chains
console.log(
  user && user.isAdmin
    ? "Admin access"
    : user && user.isEditor
    ? "Editor access"
    : "Regular access"
);
  1. console.log() with array destructuring assignment
console.log(([a, b] = [1, 2]));
  1. console.log() with nested template literals
console.log(`User: ${`${firstName} ${lastName}`}`);
  1. console.log() with no arguments
console.log();
  1. console.log() with a regular expression
console.log(/^user-\d+$/);
  1. console.log() with chained method calls
console.log(
  users
    .find((u) => u.id === 5)
    .getPurchases()
    .filter((p) => p.active)
);
  1. console.log() with unicode escape sequences
console.log("\u0048\u0065\u006c\u006c\u006f");

License

MIT

MIT License

Copyright (c) 2021-present Tanner Linsley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

1.0.5

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.0

4 months ago