First you need to install prop-types package in your repository manually:
npm i --save prop-types
Then copy code to update.php
in your projects root:
<?php
$Directory = new RecursiveDirectoryIterator(__DIR__);
$Iterator = new RecursiveIteratorIterator($Directory);
$Regex = new RegexIterator($Iterator, '/^.+\.jsx?$/i', RecursiveRegexIterator::GET_MATCH);
$filesToUpdatePropTypes = [];
$addPropTypesImport = function ($content) {
return preg_replace(
"/(import React from ('|\")react('|\");\n)/",
"$1import * as PropTypes from \"prop-types\";\n",
$content
);
};
$replaceDeprecatedPropTypes = function ($content) {
return str_replace('React.PropTypes', 'PropTypes', $content);
};
foreach ($Regex as $file) {
$file = $file[0];
$content = file_get_contents($file);
if (strpos($content, "React.PropTypes") !== false) {
$filesToUpdatePropTypes[$file] = $content;
}
}
$filesToUpdatePropTypes = array_map($addPropTypesImport, $filesToUpdatePropTypes);
$filesToUpdatePropTypes = array_map($replaceDeprecatedPropTypes, $filesToUpdatePropTypes);
foreach ($filesToUpdatePropTypes as $filePath => $fileContent) {
file_put_contents($filePath, $fileContent);
}
you need PHP 7 CLI installed to run this script. Run it:
php update.php