Skip to content

Commit 3465394

Browse files
committed
refactor: Use Codegener
1 parent 3ec520e commit 3465394

File tree

4 files changed

+10
-63
lines changed

4 files changed

+10
-63
lines changed

bootstrap/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use LaravelBridge\Scratch\Application as LaravelBridge;
4+
use MilesChou\Codegener\CodegenerServiceProvider;
45
use MilesChou\Schemarkdown\App;
56
use org\bovigo\vfs\vfsStream;
67

@@ -12,6 +13,7 @@
1213
$container = (new LaravelBridge())
1314
->setupDatabase([])
1415
->setupView(dirname(__DIR__) . '/src/templates', $vfs->url())
16+
->setupProvider(CodegenerServiceProvider::class)
1517
->bootstrap();
1618

1719
return new App($container);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"illuminate/view": "^5.6 | ^6",
2525
"laravel-bridge/scratch": "^0.5",
2626
"mikey179/vfsstream": "^1.6",
27+
"mileschou/codegener": "^1.0",
2728
"monolog/monolog": "^1.25",
2829
"symfony/console": "^4 | ^5",
2930
"symfony/yaml": "^4 | ^5",

src/CodeWriter.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Commands/GenerateCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Container\Container;
66
use Illuminate\Database\DatabaseManager;
77
use Illuminate\Log\LogManager;
8+
use MilesChou\Codegener\Writer;
89
use MilesChou\Schemarkdown\CodeBuilder;
9-
use MilesChou\Schemarkdown\CodeWriter;
1010
use MilesChou\Schemarkdown\Commands\Concerns\DatabaseConnection;
1111
use MilesChou\Schemarkdown\Commands\Concerns\Environment;
1212
use Symfony\Component\Console\Command\Command;
@@ -63,7 +63,8 @@ protected function configure()
6363
->addOption('--env', null, InputOption::VALUE_REQUIRED, '.env file', '.env')
6464
->addOption('--config-file', null, InputOption::VALUE_REQUIRED, 'Config file', 'config/database.php')
6565
->addOption('--connection', null, InputOption::VALUE_REQUIRED, 'Connection name will only build', null)
66-
->addOption('--output-dir', null, InputOption::VALUE_REQUIRED, 'Relative path with getcwd()', 'generated');
66+
->addOption('--output-dir', null, InputOption::VALUE_REQUIRED, 'Relative path with getcwd()', 'generated')
67+
->addOption('--overwrite', null, InputOption::VALUE_NONE, 'Overwrite the exist file');
6768
}
6869

6970
protected function execute(InputInterface $input, OutputInterface $output)
@@ -72,6 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7273
$configFile = $input->getOption('config-file');
7374
$connection = $input->getOption('connection');
7475
$outputDir = $input->getOption('output-dir');
76+
$overwrite = $input->getOption('overwrite');
7577

7678
$this->loadDotEnv($this->normalizePath($env));
7779

@@ -88,7 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8890

8991
$logger->info('All document build success, next will write files');
9092

91-
$this->container->make(CodeWriter::class)->generate($code, $outputDir);
93+
/** @var Writer $writer */
94+
$writer = $this->container->make(Writer::class);
95+
$writer->writeMass($code, $outputDir, $overwrite);
9296

9397
$logger->info('All document write success');
9498

0 commit comments

Comments
 (0)