Last active
February 1, 2017 09:51
-
-
Save AmrAbdulrahman/70d0a602f1d952d41e3a47866f6c6d65 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
In case you have tens of files with '2 spaces' indentation that you need to convert to '4 spaces' | |
1. Install 'recursive-readdir-sync', do not add the --save label. | |
2. cd to the root of the directory you want to process | |
3. Place this script. | |
3. Run the script, commit, push, enjoy! | |
*/ | |
let fs = require('fs'); | |
let recursiveReadSync = require('recursive-readdir-sync'); | |
let files = recursiveReadSync(__dirname); | |
let extentions = [ | |
'js', | |
'less', | |
'html' | |
].map((extention) => '.' + extention); | |
let processedFilesCount = 0; | |
for (let i = 0; i < files.length; i++) { | |
let filePath = files[i]; | |
let processFile = false; | |
for (let j = 0; j < extentions.length; j++) { | |
let extention = extentions[j]; | |
if (filePath.indexOf(extention) === filePath.length - extention.length) { // ends with | |
processFile = true; | |
break; | |
} | |
} | |
if (processFile) { | |
processedFilesCount ++; | |
convert2SpacesTo4Spaces(filePath); | |
} | |
} | |
console.log(`Successfully processed ${processedFilesCount} file.`); | |
function convert2SpacesTo4Spaces(filePath) { | |
let fileContent = fs.readFileSync(filePath); | |
fileContent = fileContent.toString().replace(/ /g, ' '); | |
fs.writeFileSync(filePath, fileContent); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment