Created
April 22, 2017 18:35
-
-
Save SuhairZain/ad6e3ce0f1d34050a6d89a3291b2bebb 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 fs = require('fs'); | |
const path = require('path'); | |
const execSync = require('child_process').execSync; | |
const regex = /^(import PropTypes from 'prop-types';)\n(\/\/ \(C\) Copyright.*)\n\n(import React(?:.*) from 'react';)([\s\S]*)$/; | |
const processDirectory = (dir) => { | |
fs.readdirSync(dir).forEach((file) => { | |
if (fs.lstatSync(path.join(dir, file)).isDirectory()) { | |
if (file !== 'base') | |
processDirectory(path.join(dir, file)); | |
} else { | |
const fileName = path.join(dir, file); | |
execSync( | |
`jscodeshift -t ../react-codemod/transforms/React-PropTypes-to-prop-types.js ${fileName}` | |
); | |
const contents = fs.readFileSync(path.join(dir, file), 'utf-8'); | |
if (regex.test(contents)) { | |
fs.writeFileSync( | |
path.join(dir, file), | |
contents.replace(regex, '$2\n\n$3\n$1$4'), | |
'utf-8'); | |
} | |
} | |
}); | |
}; | |
processDirectory(path.join(__dirname, 'src', 'js')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment