mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-07-10 01:56:20 +02:00
Added copying of files to build folder
This commit is contained in:
@ -7,6 +7,7 @@ return [
|
||||
'code_dir' => __DIR__ . '/code',
|
||||
'templates_dir' => __DIR__ . '/assets/templates',
|
||||
'output_dir' => __DIR__ . '/.build',
|
||||
'files_dir' => __DIR__ . '/assets/files',
|
||||
'pages' => [
|
||||
Page::create('index', 'index.phtml'),
|
||||
Page::create('credits', 'credits.phtml'),
|
||||
|
@ -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;
|
||||
|
@ -9,7 +9,6 @@ class BuildTest extends BaseTestCase
|
||||
public function setUp()
|
||||
{
|
||||
load_config(__DIR__ . '/static/config.php');
|
||||
mkdir('/tmp/apprentice_output');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
@ -53,5 +52,7 @@ class BuildTest extends BaseTestCase
|
||||
|
||||
$this->assertEquals($expectedHtml, $html);
|
||||
$this->assertEquals($expectedHtml2, $html2);
|
||||
$this->assertTrue(file_exists('/tmp/apprentice_output/test.txt'));
|
||||
$this->assertTrue(file_exists('/tmp/apprentice_output/TEST'));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ return [
|
||||
'code_dir' => __DIR__ . '/code',
|
||||
'templates_dir' => __DIR__ . '/templates',
|
||||
'output_dir' => '/tmp/apprentice_output',
|
||||
'files_dir' => __DIR__ . '/files',
|
||||
'pages' => [
|
||||
Page::create('index', 'index.phtml'),
|
||||
Page::create('test', null, 'test.php', [
|
||||
|
0
test/static/files/TEST
Normal file
0
test/static/files/TEST
Normal file
0
test/static/files/test.txt
Normal file
0
test/static/files/test.txt
Normal file
Reference in New Issue
Block a user