Skip to content

Commit

Permalink
ref!: add prefix and change codegen command name
Browse files Browse the repository at this point in the history
  • Loading branch information
vuongxuongminh committed Mar 27, 2024
1 parent 380dff0 commit 5fddd09
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bin_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bin/codegen → bin/x-graphql-codegen
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

declare(strict_types=1);

require __DIR__ . '/codegen.php';
require __DIR__ . '/x-graphql-codegen.php';
12 changes: 6 additions & 6 deletions bin/codegen.php → bin/x-graphql-codegen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(...));
Expand Down Expand Up @@ -89,15 +89,15 @@ private function prepareGeneratorsForCodegenCommand(ConsoleCommandEvent $event):
{
$command = $event->getCommand();

if (!$command instanceof CodegenCommand) {
if (!$command instanceof GenerateCommand) {
return;
}

$configFile = $event->getInput()->getOption('config-file');

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)
);
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"symplify/easy-coding-standard": "^12.1"
},
"bin": [
"bin/codegen"
"bin/x-graphql-codegen"
],
"license": "MIT",
"autoload": {
Expand Down
4 changes: 4 additions & 0 deletions resources/config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
3 changes: 2 additions & 1 deletion src/Console/InitConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -28,7 +28,7 @@ protected function setUp(): void

public function testRunCommand()
{
$command = new CodegenCommand();
$command = new GenerateCommand();
$command->setGenerators(
[
'test' => new Generator(
Expand All @@ -47,7 +47,7 @@ public function testRunCommand()

public function testRunCommandWithEmptyGenerators()
{
$command = new CodegenCommand();
$command = new GenerateCommand();
$command->setGenerators([]);
$tester = new CommandTester($command);
$tester->execute([]);
Expand Down

0 comments on commit 5fddd09

Please sign in to comment.