Skip to content

Commit

Permalink
Rename and restructure internal hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 20, 2022
1 parent a80593e commit 0562ae3
Showing 1 changed file with 42 additions and 41 deletions.
83 changes: 42 additions & 41 deletions src/Commands/HydeBuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(): int

$this->title('Building your static site!');

$this->printInitialInformation();
$this->runPreBuildActions();

$this->purge();

Expand All @@ -84,15 +84,16 @@ public function handle(): int
$this->runBuildAction(DocumentationPage::class);
}

$this->postBuildActions();
$this->runPostBuildActions();

$this->printFinishMessage($time_start);

return 0;
}


/** @internal */
protected function printInitialInformation(): void
protected function runPreBuildActions(): void
{
if ($this->option('no-api')) {
$this->info('Disabling external API calls');
Expand All @@ -109,49 +110,12 @@ protected function printInitialInformation(): void
}
}

/** @internal */
protected function printFinishMessage(float $time_start): void
{
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
$this->info('All done! Finished in '.number_format(
$execution_time,
2
).' seconds. ('.number_format(($execution_time * 1000), 2).'ms)');

$this->info('Congratulations! 🎉 Your static site has been built!');
$this->line(
'Your new homepage is stored here -> '.
DiscoveryService::createClickableFilepath(Hyde::getSiteOutputPath('index.html'))
);
}

/**
* Clear the entire output directory before running the build.
*
* @return void
*/
public function purge(): void
{
$this->warn('Removing all files from build directory.');

File::deleteDirectory(Hyde::getSiteOutputPath());
mkdir(Hyde::getSiteOutputPath());

$this->line('<fg=gray> > Directory purged');

$this->line(' > Recreating directories');
(new CreatesDefaultDirectories)->__invoke();

$this->line('</>');
}

/**
* Run any post-build actions.
*
* @return void
*/
public function postBuildActions(): void
public function runPostBuildActions(): void
{
if ($this->option('run-prettier') || $this->option('pretty')) {
if ($this->option('pretty')) {
Expand Down Expand Up @@ -187,6 +151,43 @@ public function postBuildActions(): void
}
}

/** @internal */
protected function printFinishMessage(float $time_start): void
{
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
$this->info('All done! Finished in '.number_format(
$execution_time,
2
).' seconds. ('.number_format(($execution_time * 1000), 2).'ms)');

$this->info('Congratulations! 🎉 Your static site has been built!');
$this->line(
'Your new homepage is stored here -> '.
DiscoveryService::createClickableFilepath(Hyde::getSiteOutputPath('index.html'))
);
}

/**
* Clear the entire output directory before running the build.
*
* @return void
*/
public function purge(): void
{
$this->warn('Removing all files from build directory.');

File::deleteDirectory(Hyde::getSiteOutputPath());
mkdir(Hyde::getSiteOutputPath());

$this->line('<fg=gray> > Directory purged');

$this->line(' > Recreating directories');
(new CreatesDefaultDirectories)->__invoke();

$this->line('</>');
}

/** @internal */
protected function getModelPluralName(string $model): string
{
Expand Down

0 comments on commit 0562ae3

Please sign in to comment.