Created
April 13, 2020 14:34
-
-
Save cjayyy/8f38e3f6919e6c4b3987b8dd6ae9df07 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
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