Last active
February 8, 2024 09:11
-
-
Save armamini/731a99289165c9a3f0538aa60082bba8 to your computer and use it in GitHub Desktop.
Delete all 'console.log' lines across anywhere of your project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Recursive function to get all .ts and .js files in a directory | |
| function getFiles(dir) { | |
| let files = []; | |
| fs.readdirSync(dir).forEach(file => { | |
| const filePath = path.join(dir, file); | |
| const stats = fs.statSync(filePath); | |
| if (stats.isDirectory()) { | |
| if (file !== 'node_modules' && file !== 'dist') { | |
| files = files.concat(getFiles(filePath)); | |
| } | |
| } else if (stats.isFile() && (filePath.endsWith('.ts') || filePath.endsWith('.js'))) { | |
| files.push(filePath); | |
| } | |
| }); | |
| return files; | |
| } | |
| // Get all .ts and .js files in the project | |
| const files = getFiles('.'); | |
| // Loop through each file | |
| files.forEach(file => { | |
| const data = fs.readFileSync(file, 'utf8'); | |
| const result = data.split('\n').filter(line => !line.includes('console.log')).join('\n'); | |
| fs.writeFileSync(file, result, 'utf8'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| FILES=$(find . -type d \( -path "./node_modules" -o -path "./dist" \) -prune -o -type f \( -name "*.ts" -o -name "*.js" \) -print) | |
| for FILE in $FILES | |
| do | |
| sed -i '/console.log/d' $FILE | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment