mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-08-12 09:44:27 +02:00
Added copying of files to build folder
This commit is contained in:
@@ -15,7 +15,9 @@ class Build
|
||||
*/
|
||||
public function buildAll(): void
|
||||
{
|
||||
$this->cleanPublicFolder();
|
||||
$this->createOutputFolder();
|
||||
$this->cleanOutputFolder();
|
||||
$this->copyFiles();
|
||||
|
||||
$pages = config('pages');
|
||||
foreach ($pages as $page) {
|
||||
@@ -31,6 +33,8 @@ class Build
|
||||
*/
|
||||
public function runSingleBuild(string $name): string
|
||||
{
|
||||
$this->createOutputFolder();
|
||||
|
||||
$pages = config('pages');
|
||||
|
||||
foreach ($pages as $page) {
|
||||
@@ -47,7 +51,7 @@ class Build
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function cleanPublicFolder(): void
|
||||
private function cleanOutputFolder(): void
|
||||
{
|
||||
$files = glob(config('output_dir') . '/*.html');
|
||||
foreach ($files as $file) {
|
||||
@@ -55,6 +59,33 @@ class Build
|
||||
}
|
||||
}
|
||||
|
||||
private function copyFiles(): void
|
||||
{
|
||||
$filesDir = config('files_dir');
|
||||
if (!file_exists($filesDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$outputDir = config('output_dir');
|
||||
foreach (glob($filesDir . '/*') as $file) {
|
||||
$name = basename($file);
|
||||
|
||||
copy($file, $outputDir . '/' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates output folder if it does not exist
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createOutputFolder(): void
|
||||
{
|
||||
if (!file_exists(config('output_dir'))) {
|
||||
mkdir(config('output_dir'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds single Page into html and
|
||||
* outputs to public directory
|
||||
@@ -76,10 +107,6 @@ class Build
|
||||
}
|
||||
$output = $this->getOutput($template, $page->variables);
|
||||
|
||||
if (!file_exists(config('output_dir'))) {
|
||||
mkdir(config('output_dir'));
|
||||
}
|
||||
|
||||
file_put_contents(config('output_dir') . '/' . $page->name . '.html', $output);
|
||||
|
||||
return $output;
|
||||
|
Reference in New Issue
Block a user