Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cjayyy/8f38e3f6919e6c4b3987b8dd6ae9df07 to your computer and use it in GitHub Desktop.
Save cjayyy/8f38e3f6919e6c4b3987b8dd6ae9df07 to your computer and use it in GitHub Desktop.
const glob = require('glob');
const fs = require('fs');
const path = require('path');
glob('src/**/*.jsx', function(error, files) {
if (error) throw error;
files.forEach(function(file) {
const fileName = path.basename(file, '.jsx');
fs.readFile(file, 'utf8', (error, content) => {
if (error) throw error;
if (~content.indexOf('export default createReactClass(')) {
let refactored =
content.replace(
'export default createReactClass(',
`const ${fileName} = createReactClass(`
) + `\n export default ${fileName};`;
fs.writeFile(file, refactored, 'utf8', (error) => {
if (error) throw error;
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment