Changes to a large number of files in our codebase
enforce consistent code style
(i.e. never)
-> Technical debt
Codemods are scripts used to rewrite other scripts
Regex on steroids
write code to modify code
BabelJS uses it to transform your code from ES6 to ES5. ESLint uses it to lint your code.
Setup
npm i -g jscodeshift
jscodeshift -t path-to-transform.js input-file.js
it can be a glob/ folder
module.exports = function(fileInfo, api) {
// transform `fileInfo.source` here
// ...
// return changed source
return source;
};
let write our first codemod
learned a quick and easy way to do code refactoring
-> less reluctant to upgrade libraries and change APIs
Bonus
awesome-angular
awesome-nodejs
awesome-*