From d0ec26d0587aa43f28276ff774a42c93e2b4635d Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Sun, 2 Sep 2018 18:24:18 -0500 Subject: [PATCH 1/2] Added CNAME and favicon to assets --- assets/files/CNAME | 1 + assets/files/favicon-32.png | Bin 0 -> 1348 bytes 2 files changed, 1 insertion(+) create mode 100644 assets/files/CNAME create mode 100644 assets/files/favicon-32.png diff --git a/assets/files/CNAME b/assets/files/CNAME new file mode 100644 index 0000000..b495207 --- /dev/null +++ b/assets/files/CNAME @@ -0,0 +1 @@ +phpapprentice.com diff --git a/assets/files/favicon-32.png b/assets/files/favicon-32.png new file mode 100644 index 0000000000000000000000000000000000000000..9bf983c4a2ff1afb96e73cb1cbc54f5cd2611d3f GIT binary patch literal 1348 zcmV-K1-tr*P)FVmLabaP>2Ph)2RKU<4zP-Kuc5Q9#2j%7E z9~BoD*W~Bt=VfPSN8a)JODGiL0D@-d@bJ)aaB#5ga5%og{Ca$R+?^~Kk&S_Yfd>^8 z72nj<)Z8j4C{V#H*Pou?DSpXv4bioCo$ zIeg+}8Rj+Z1)FlEQdtTUK9@7^glYQw`|sD+*H2VeSJ%kp$!xv(lwdIEhfh6AhF@7x zQBiwkW#t>`1VS*uiW`x)%L;~Ad9AFh?0uMqb#;pAgpR>FJ5n>3j^q5EB?gjtU-s z7fCFk@?-^&W6a1me=>tXV$&e2-ki~rMFDwaXAaD)O-@d_X*&}$B!`^v3N45L(vk8& z6a~S|0u)d=UsWNT~7w6?bP@z~gy89<_}5GW=Grf9nAGbs7o`ue&R{caFZRe+u( zpBx(I6zA2qrF$xds6iosa9XX_hr`3ezu<8U5Rzj8L;WnexoFa(;syu&(q^-LjxwP` z%XtrVt3D?u=N>>6AzSC+UWMGGK#Lim-WMI+&qkwhdSYV2O88O*!-EM04p9(#8bmiL z?cbxLqed*r370V`+W5MY?%Wv49Z}F^zCaQ3rhGVrOUPdo0q*3Mo$nM(FJ9tki0?dJ0_{ zySuw4_{^`kjq8Y_UcFy;Wlj#T~$vgZ@*%NQ6Q5u(L+b2-37vn(Mcv!L(rAZa~8wjJ&3 z>-!OpV~QKerE3r~VPw?jaLfbL5Do5q0C0rq#(awB--4B&W@l&5Ae#|Jq?eHzCISCv zc^yuA2L;gw^Egp^95XXB5&&}6v^%T>BHmR37w`9sKK~bjZ7B3?5#q7{0000 Date: Sun, 2 Sep 2018 18:24:24 -0500 Subject: [PATCH 2/2] Added copying of files to build folder --- config.php | 1 + src/Build.php | 39 ++++++++++++++++++++++++++++++++------ test/BuildTest.php | 3 ++- test/static/config.php | 1 + test/static/files/TEST | 0 test/static/files/test.txt | 0 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 test/static/files/TEST create mode 100644 test/static/files/test.txt diff --git a/config.php b/config.php index b77d917..f3742b9 100644 --- a/config.php +++ b/config.php @@ -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'), diff --git a/src/Build.php b/src/Build.php index 50b8d5e..2dda936 100644 --- a/src/Build.php +++ b/src/Build.php @@ -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; diff --git a/test/BuildTest.php b/test/BuildTest.php index 5003a4c..6ffae18 100644 --- a/test/BuildTest.php +++ b/test/BuildTest.php @@ -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')); } } diff --git a/test/static/config.php b/test/static/config.php index 5f8b618..ea3bdaa 100644 --- a/test/static/config.php +++ b/test/static/config.php @@ -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', [ diff --git a/test/static/files/TEST b/test/static/files/TEST new file mode 100644 index 0000000..e69de29 diff --git a/test/static/files/test.txt b/test/static/files/test.txt new file mode 100644 index 0000000..e69de29