Skip to content

Commit 08ee8ed

Browse files
committed
chore: change a bit codebase
1 parent b949a2f commit 08ee8ed

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "A package that helps you remove all js logs!",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"build": "node index.js"
98
},
109
"repository": {

src/index.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,46 @@ const traverse = require("@babel/traverse").default;
77
const generator = require("@babel/generator").default;
88

99
const consoleMethods = [
10-
"assert", "clear", "count", "countReset", "debug", "dir", "dirxml",
11-
"error", "group", "groupCollapsed", "groupEnd", "info", "log",
12-
"table", "time", "timeEnd", "timeLog", "timeStamp", "trace", "warn"
10+
"assert",
11+
"clear",
12+
"count",
13+
"countReset",
14+
"debug",
15+
"dir",
16+
"dirxml",
17+
"error",
18+
"group",
19+
"groupCollapsed",
20+
"groupEnd",
21+
"info",
22+
"log",
23+
"table",
24+
"time",
25+
"timeEnd",
26+
"timeLog",
27+
"timeStamp",
28+
"trace",
29+
"warn",
1330
];
1431

15-
const args = process.argv.slice(3);
16-
const removeAllLogs = args.includes("all");
17-
const allowedMethods = removeAllLogs
18-
? consoleMethods
19-
: args[0]?.split(",") || ["log"];
20-
2132
function removeConsoleLogsFromFile(filePath) {
2233
let code = fs.readFileSync(filePath, "utf-8");
23-
2434
const ast = parser.parse(code, { sourceType: "module", plugins: ["jsx"] });
35+
const args = process.argv.slice(3);
36+
const allowedMethods = args.includes("all")
37+
? consoleMethods
38+
: args[0]?.split(",") || ["log"];
2539

2640
traverse(ast, {
2741
CallExpression(path) {
2842
const { callee } = path.node;
2943
if (
30-
callee.object?.name === "console" &&
44+
callee.object?.name === "console" &&
3145
allowedMethods.includes(callee.property?.name)
3246
) {
3347
path.remove();
3448
}
35-
}
49+
},
3650
});
3751

3852
const { code: newCode } = generator(ast, { retainLines: true });
@@ -44,7 +58,9 @@ function processDirectory(dirPath) {
4458
const fullPath = path.join(dirPath, file);
4559
if (fs.statSync(fullPath).isDirectory()) {
4660
processDirectory(fullPath);
47-
} else if ([".js", ".ts", ".jsx", ".tsx"].some(ext => file.endsWith(ext))) {
61+
} else if (
62+
[".js", ".ts", ".jsx", ".tsx"].some((ext) => file.endsWith(ext))
63+
) {
4864
removeConsoleLogsFromFile(fullPath);
4965
console.log(`Processed: ${fullPath}`);
5066
}

0 commit comments

Comments
 (0)