Repository: ucan-lab/laravel-dacapo (php)

Issue:
Add dacapo:config:publish

Pull request:
Add dacapo:config:publish
close #198

Patch:
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 537ebc4..e6aeec0 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -6,6 +6,7 @@ $finder = PhpCsFixer\Finder::create()
         __DIR__ . '/tests',
     ])
     ->exclude([
+        'Dacapo/Presentation/Console/DacapoConfigPublishCommand',
         'Presentation/Console/DacapoCommandTest',
     ])
 ;
diff --git a/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand.php b/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand.php
new file mode 100644
index 0000000..81fc83f
--- /dev/null
+++ b/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand.php
@@ -0,0 +1,45 @@
+<?php declare(strict_types=1);
+
+namespace UcanLab\LaravelDacapo\Dacapo\Presentation\Console;
+
+use Illuminate\Console\Command;
+use Illuminate\Console\ConfirmableTrait;
+
+/**
+ * Class DacapoConfigPublishCommand
+ */
+final class DacapoConfigPublishCommand extends Command
+{
+    use ConfirmableTrait;
+
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'dacapo:config:publish {--force : Overwrite any existing files}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Publish dacapo config that are available for customization.';
+
+    public function handle(): void
+    {
+        $configPath = $this->laravel->configPath();
+
+        $files = [
+            (string) realpath(__DIR__ . '/DacapoConfigPublishCommand/dacapo.php') => $configPath . '/dacapo.php',
+        ];
+
+        foreach ($files as $from => $to) {
+            if (! file_exists($to) || $this->option('force')) {
+                file_put_contents($to, file_get_contents($from));
+            }
+        }
+
+        $this->info('Config published successfully.');
+    }
+}
diff --git a/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand/dacapo.php b/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand/dacapo.php
new file mode 100644
index 0000000..1521196
--- /dev/null
+++ b/src/Dacapo/Presentation/Console/DacapoConfigPublishCommand/dacapo.php
@@ -0,0 +1,19 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Dacapo ignore tables
+    |--------------------------------------------------------------------------
+    |
+    | This option specifies a table that is not generated by the dacapo:make command.
+    |
+    */
+
+    'ignore_tables' => [
+        'users',
+        'password_resets',
+        'failed_jobs',
+        'personal_access_tokens',
+    ],
+];
diff --git a/src/Dacapo/Presentation/Console/DacapoMakeModelsCommand.php b/src/Dacapo/Presentation/Console/DacapoMakeModelsCommand.php
index 9b1df6a..24356f2 100644
--- a/src/Dacapo/Presentation/Console/DacapoMakeModelsCommand.php
+++ b/src/Dacapo/Presentation/Console/DacapoMakeModelsCommand.php
@@ -97,11 +97,12 @@ final class DacapoMakeModelsCommand extends Command
      */
     private function removeIgnoreTableNames(array $tableNameList): array
     {
-        $ignoreTableNameList = [
+        $ignoreTableNameList = config('dacapo.ignore_tables', [
             'users',
             'password_resets',
             'failed_jobs',
-        ];
+            'personal_access_tokens',
+        ]);
 
         return array_diff($tableNameList, $ignoreTableNameList);
     }
diff --git a/src/Providers/ConsoleServiceProvider.php b/src/Providers/ConsoleServiceProvider.php
index 1821266..511add0 100644
--- a/src/Providers/ConsoleServiceProvider.php
+++ b/src/Providers/ConsoleServiceProvider.php
@@ -21,6 +21,7 @@ use UcanLab\LaravelDacapo\Dacapo\Infra\Adapter\Stub\LaravelMigrationCreateStub;
 use UcanLab\LaravelDacapo\Dacapo\Infra\Adapter\Stub\LaravelMigrationUpdateStub;
 use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoClearCommand;
 use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoCommand;
+use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoConfigPublishCommand;
 use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoInitCommand;
 use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoMakeModelsCommand;
 use UcanLab\LaravelDacapo\Dacapo\Presentation\Console\DacapoStubPublishCommand;
@@ -46,10 +47,11 @@ final class ConsoleServiceProvider extends ServiceProvider implements Deferrable
      * @var array<int, string>
      */
     private array $commands = [
-        DacapoInitCommand::class,
+        DacapoClearCommand::class,
         DacapoCommand::class,
+        DacapoConfigPublishCommand::class,
+        DacapoInitCommand::class,
         DacapoMakeModelsCommand::class,
-        DacapoClearCommand::class,
         DacapoStubPublishCommand::class,
         DacapoUninstallCommand::class,
     ];
@@ -66,6 +68,7 @@ final class ConsoleServiceProvider extends ServiceProvider implements Deferrable
 
     /**
      * {@inheritdoc}
+     * @throws Exception
      */
     public function register(): void
     {


Test patch:
diff --git a/tests/Presentation/Console/DacapoConfigPublishCommandTest.php b/tests/Presentation/Console/DacapoConfigPublishCommandTest.php
new file mode 100644
index 0000000..6293851
--- /dev/null
+++ b/tests/Presentation/Console/DacapoConfigPublishCommandTest.php
@@ -0,0 +1,15 @@
+<?php declare(strict_types=1);
+
+namespace UcanLab\LaravelDacapo\Test\Presentation\Console;
+
+use UcanLab\LaravelDacapo\Providers\ConsoleServiceProvider;
+use UcanLab\LaravelDacapo\Test\TestCase;
+
+final class DacapoConfigPublishCommandTest extends TestCase
+{
+    public function testResolve(): void
+    {
+        $this->app->register(ConsoleServiceProvider::class);
+        $this->artisan('dacapo:config:publish')->assertExitCode(0);
+    }
+}