Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| HydeBuildSearchCommand | |
100.00% |
21 / 21 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| createSearchPage | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| guesstimateGenerationTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getExecutionTimeInMs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Commands; |
| 4 | |
| 5 | use Hyde\Framework\Actions\GeneratesDocumentationSearchIndexFile; |
| 6 | use Hyde\Framework\Hyde; |
| 7 | use Hyde\Framework\Models\DocumentationPage; |
| 8 | use Hyde\Framework\Services\CollectionService; |
| 9 | use LaravelZero\Framework\Commands\Command; |
| 10 | |
| 11 | /** |
| 12 | * Hyde Command to run the Build Process for the DocumentationSearchIndex. |
| 13 | * |
| 14 | * @todo Add configuration option to enable/disable this feature. |
| 15 | * |
| 16 | * @see \Tests\Feature\Commands\HydeBuildSearchCommandTest |
| 17 | */ |
| 18 | class HydeBuildSearchCommand extends Command |
| 19 | { |
| 20 | /** |
| 21 | * The signature of the command. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $signature = 'build:search'; |
| 26 | |
| 27 | /** |
| 28 | * The description of the command. |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | protected $description = 'Generate the docs/search.json'; |
| 33 | |
| 34 | /** |
| 35 | * Execute the console command. |
| 36 | * |
| 37 | * @return int |
| 38 | */ |
| 39 | public function handle(): int |
| 40 | { |
| 41 | $actionTime = microtime(true); |
| 42 | |
| 43 | $this->comment('Generating documentation site search index...'); |
| 44 | $this->line('<fg=gray> > This will take an estimated '.round($this->guesstimateGenerationTime() / 1000).' seconds. Terminal may seem non-responsive.</>'); |
| 45 | GeneratesDocumentationSearchIndexFile::run(); |
| 46 | |
| 47 | $this->line(' > Created <info>'.GeneratesDocumentationSearchIndexFile::$filePath.'</> in '. |
| 48 | $this->getExecutionTimeInMs($actionTime)."ms\n"); |
| 49 | |
| 50 | if (config('docs.create_search_page', true)) { |
| 51 | $this->createSearchPage(); |
| 52 | } |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | protected function createSearchPage(): void |
| 58 | { |
| 59 | $actionTime = microtime(true); |
| 60 | |
| 61 | $this->comment('Generating search page...'); |
| 62 | file_put_contents(Hyde::path('_site/'.config('docs.output_directory', 'docs').'/search.html'), |
| 63 | view('hyde::layouts.docs')->with([ |
| 64 | 'page' => new DocumentationPage([], '', 'Search', 'search'), |
| 65 | 'title' => 'Search', |
| 66 | 'markdown' => view('hyde::pages.documentation-search')->render(), |
| 67 | 'currentPage' => ''.config('docs.output_directory', 'docs').'/search', |
| 68 | ])->render()); |
| 69 | |
| 70 | $this->line(' > Created <info>_site/'.config('docs.output_directory', 'docs').'/search.html</> in '. |
| 71 | $this->getExecutionTimeInMs($actionTime)."ms\n"); |
| 72 | } |
| 73 | |
| 74 | protected function guesstimateGenerationTime(): float |
| 75 | { |
| 76 | return count(CollectionService::getDocumentationPageList()) * 52.5; |
| 77 | } |
| 78 | |
| 79 | protected function getExecutionTimeInMs(float $timeStart): string |
| 80 | { |
| 81 | return number_format(((microtime(true) - $timeStart) * 1000), 2); |
| 82 | } |
| 83 | } |