Created
February 16, 2020 21:35
-
-
Save aliaspooryorik/4b4b72a38d31d2f55c7e6eef07fe0c34 to your computer and use it in GitHub Desktop.
Fix case Task
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
component { | |
variables.sourceFiles = []; | |
variables.componentPaths = []; | |
variables.verbose = true; | |
variables.updated = 0; | |
public function run() { | |
var sourceFiles = findSourceFiles(); | |
sourceFiles.each(fixDottedPath); | |
print.line("#sourceFiles.len()# processed. #variables.updated# updated"); | |
} | |
array private function findSourceFiles() { | |
if (!variables.sourceFiles.len()) { | |
var Globber = globber( getCWD() & "**.cf*" ); | |
variables.sourceFiles = Globber.matches().map((el) => el.replace(getCWD(), '')); | |
} | |
return variables.sourceFiles; | |
} | |
array private function pathsToCheck() { | |
if (!variables.componentPaths.len()) { | |
variables.componentPaths = findSourceFiles() | |
.filter((el) => el.right(4) == '.cfc') | |
.map(pathToDotted); | |
} | |
return variables.componentPaths; | |
} | |
string private function pathToDotted(el) { | |
var path = el.reReplace('\.cfc$', ''); | |
return path.replace(server.separator.file, '.', 'all'); | |
} | |
void function fixDottedPath(sourcefilepath) { | |
var fileContent = fileRead(sourcefilepath); | |
var pre = hash(fileContent); | |
var dottedPathsCorrectCase = pathsToCheck(); | |
dottedPathsCorrectCase.each((el) => { | |
fileContent = fileContent.replaceNoCase(el, el, 'all'); | |
}); | |
if (compare(hash(filecontent), pre) != 0) { | |
debug("file '#sourcefilepath#' updated"); | |
variables.updated++; | |
fileWrite(sourcefilepath, fileContent); | |
} | |
}; | |
void function debug(message) { | |
if (variables.verbose) { | |
print.line(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment