diff --git a/.github/workflows/bin_tests.yml b/.github/workflows/bin_tests.yml index 91f7c56..ca490e5 100644 --- a/.github/workflows/bin_tests.yml +++ b/.github/workflows/bin_tests.yml @@ -28,6 +28,6 @@ jobs: - uses: "ramsey/composer-install@v2" - - run: chmod +x ./bin/codegen + - run: chmod +x ./bin/x-graphql-codegen - - run: ./bin/codegen + - run: ./bin/x-graphql-codegen diff --git a/bin/codegen b/bin/x-graphql-codegen similarity index 54% rename from bin/codegen rename to bin/x-graphql-codegen index 63be82e..20a5db2 100755 --- a/bin/codegen +++ b/bin/x-graphql-codegen @@ -3,4 +3,4 @@ declare(strict_types=1); -require __DIR__ . '/codegen.php'; +require __DIR__ . '/x-graphql-codegen.php'; diff --git a/bin/codegen.php b/bin/x-graphql-codegen.php similarity index 88% rename from bin/codegen.php rename to bin/x-graphql-codegen.php index 3c29da0..a5fcf55 100644 --- a/bin/codegen.php +++ b/bin/x-graphql-codegen.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\EventDispatcher\EventDispatcher; -use XGraphQL\Codegen\Console\CodegenCommand; +use XGraphQL\Codegen\Console\GenerateCommand; use XGraphQL\Codegen\Console\InitConfigCommand; use XGraphQL\Codegen\Generator; @@ -56,11 +56,11 @@ private function prepareApp(): void 'config-file', '-f', InputOption::VALUE_OPTIONAL, - 'XGraphQL codegen config file path', - sprintf('%s/x-graphql-codegen.php', getcwd()), + 'XGraphQL x-graphql-codegen config file path', + sprintf('%s/x-graphql-x-graphql-x-graphql-codegen.php', getcwd()), ) ); - $app->addCommands([new CodegenCommand(), new InitConfigCommand()]); + $app->addCommands([new GenerateCommand(), new InitConfigCommand()]); $app->setDispatcher($dispatcher); $dispatcher->addListener(ConsoleEvents::COMMAND, $this->prepareConfigFileForInitCommand(...)); @@ -89,7 +89,7 @@ private function prepareGeneratorsForCodegenCommand(ConsoleCommandEvent $event): { $command = $event->getCommand(); - if (!$command instanceof CodegenCommand) { + if (!$command instanceof GenerateCommand) { return; } @@ -97,7 +97,7 @@ private function prepareGeneratorsForCodegenCommand(ConsoleCommandEvent $event): if (!file_exists($configFile)) { throw new InvalidOptionException( - sprintf('Not found config file: `%s`, use `init-config` to generate it', $configFile) + sprintf('Not found config file: `%s`, use `x-graphql:x-graphql-codegen:init-config` to generate it', $configFile) ); } diff --git a/composer.json b/composer.json index cdcbd79..914cb01 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "symplify/easy-coding-standard": "^12.1" }, "bin": [ - "bin/codegen" + "bin/x-graphql-codegen" ], "license": "MIT", "autoload": { diff --git a/resources/config.template.php b/resources/config.template.php index 19c8a59..3a85b31 100644 --- a/resources/config.template.php +++ b/resources/config.template.php @@ -2,9 +2,13 @@ return [ 'default' => [ + /// PSR 4 namespace, classes and traits generated will use. 'namespace' => 'App\GraphQL\Codegen', + /// Where storing GraphQL queries files. 'sourcePath' => __DIR__ . '/', + /// Where storing PHP generated code with namespace above. 'destinationPath' => __DIR__ . '/', + /// Generated query class name. 'queryClassName' => 'GraphQLQuery', ] ]; diff --git a/src/Console/CodegenCommand.php b/src/Console/GenerateCommand.php similarity index 86% rename from src/Console/CodegenCommand.php rename to src/Console/GenerateCommand.php index d4599b1..518bbe3 100644 --- a/src/Console/CodegenCommand.php +++ b/src/Console/GenerateCommand.php @@ -11,8 +11,8 @@ use Symfony\Component\Console\Style\SymfonyStyle; use XGraphQL\Codegen\Generator; -#[AsCommand(name: 'x-graphql:codegen', description: 'Generate PHP code for executing GraphQL')] -final class CodegenCommand extends Command +#[AsCommand(name: 'x-graphql:codegen:generate', description: 'Generate PHP code for executing GraphQL')] +final class GenerateCommand extends Command { /** * @var Generator[] diff --git a/src/Console/InitConfigCommand.php b/src/Console/InitConfigCommand.php index 932555a..aa54d13 100644 --- a/src/Console/InitConfigCommand.php +++ b/src/Console/InitConfigCommand.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -#[AsCommand(name: 'x-graphql:init-config', description: 'Help to create config file')] +#[AsCommand(name: 'x-graphql:codegen:init-config', description: 'Help to create config file')] final class InitConfigCommand extends Command { public const TEMPLATE_FILE_PATH = __DIR__ . '/../../resources/config.template.php'; @@ -35,6 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int copy(self::TEMPLATE_FILE_PATH, $this->configFile); $style->info(sprintf('Init config file: `%s` successful', $this->configFile)); + $style->info('Now you can generate code with command: `x-graphql:x-graphql-codegen:generate`'); return self::SUCCESS; } diff --git a/tests/Console/CodegenCommandTest.php b/tests/Console/GenerateCommandTest.php similarity index 89% rename from tests/Console/CodegenCommandTest.php rename to tests/Console/GenerateCommandTest.php index b04cf6e..f0df3d6 100644 --- a/tests/Console/CodegenCommandTest.php +++ b/tests/Console/GenerateCommandTest.php @@ -7,10 +7,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Filesystem\Filesystem; -use XGraphQL\Codegen\Console\CodegenCommand; +use XGraphQL\Codegen\Console\GenerateCommand; use XGraphQL\Codegen\Generator; -class CodegenCommandTest extends TestCase +class GenerateCommandTest extends TestCase { private const DESTINATION_PATH = __DIR__ . '/../generated'; @@ -28,7 +28,7 @@ protected function setUp(): void public function testRunCommand() { - $command = new CodegenCommand(); + $command = new GenerateCommand(); $command->setGenerators( [ 'test' => new Generator( @@ -47,7 +47,7 @@ public function testRunCommand() public function testRunCommandWithEmptyGenerators() { - $command = new CodegenCommand(); + $command = new GenerateCommand(); $command->setGenerators([]); $tester = new CommandTester($command); $tester->execute([]);