Skip to content

Instantly share code, notes, and snippets.

@jmolivas
Last active December 31, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmolivas/96e842a7c598ee0df262ee3ac50fd9c9 to your computer and use it in GitHub Desktop.
Save jmolivas/96e842a7c598ee0df262ee3ac50fd9c9 to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Drupal\Console\Core\Style\DrupalStyle;
$argvInput = new ArgvInput();
$output = new ConsoleOutput();
$input = new ArrayInput([]);
$io = new DrupalStyle($input, $output);
$path = $argvInput->getFirstArgument();
if (!$path) {
$path = $io->ask('Enter module path (path must be relative)');
}
$realPath = __DIR__ . '/' . $path;
if (!is_dir($realPath)) {
$io->error('Invalid directory:' . PHP_EOL . $realPath);
exit (1);
}
$finder = new Finder();
$finder->files()->in($realPath);
$finder->path('Command');
$finder->path('Generator');
$replacements = [
'Drupal\Console\Command\Shared\CommandTrait' =>
'Drupal\Console\Core\Command\Shared\CommandTrait',
'Drupal\Console\Command\Shared\ContainerAwareCommandTrait' =>
'Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait',
'Drupal\Console\Style\DrupalStyle' =>
'Drupal\Console\Core\Style\DrupalStyle',
'Drupal\Console\Generator\Generator' =>
'Drupal\Console\Core\Generator\Generator',
'Drupal\Console\Utils\TwigRenderer' =>
'Drupal\Console\Core\Utils\TwigRenderer',
'Drupal\Console\Utils\ChainQueue' =>
'Drupal\Console\Core\Utils\ChainQueue',
'Drupal\Console\Utils\ShellProcess' =>
'Drupal\Console\Core\Utils\ShellProcess',
'Drupal\Console\Utils\StringConverter' =>
'Drupal\Console\Core\Utils\StringConverter',
'Drupal\Console\Command\Shared\InputTrait' =>
'Drupal\Console\Core\Command\Shared\InputTrait',
'Drupal\Console\Utils\ConfigurationManager' =>
'Drupal\Console\Core\Utils\ConfigurationManager',
'Drupal\Console\Utils\TranslatorManager' =>
'Drupal\Console\Utils\TranslatorManager',
'Drupal\Console\Utils\NestedArray' =>
'Drupal\Console\Core\Utils\NestedArray',
'Drupal\Console\Utils\ArgvInputReader' =>
'Drupal\Console\Core\Utils\ArgvInputReader',
'Drupal\Console\Bootstrap\DrupalConsoleCore' =>
'Drupal\Console\Core\Bootstrap\DrupalConsoleCore'
];
foreach ($finder as $file) {
$fileName = $file->getRealPath();
$io->simple('Processing file:', false);
$io->comment($file->getRelativePathname(), false);
$originalContent = file_get_contents($fileName);
$modifiedContent = str_replace(
array_keys($replacements),
array_values($replacements),
$originalContent
);
$status = '';
if ($originalContent != $modifiedContent) {
file_put_contents($fileName, $modifiedContent);
$status = ' - Updated';
}
$io->info($status);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment