diff options
Diffstat (limited to 'scripts/build.php')
| -rw-r--r-- | scripts/build.php | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/scripts/build.php b/scripts/build.php new file mode 100644 index 0000000..ecb0d9d --- /dev/null +++ b/scripts/build.php @@ -0,0 +1,112 @@ +<?php declare(strict_types=1); + +require_once __DIR__.DIRECTORY_SEPARATOR.'functions.php'; + +$hostname = null; +$output = null; + +$opts = getopt( + 'h:o:', + [ + 'hostname:', + 'help::', + 'output:', + ] +); + +if ($opts === false) { + usage(); +} + +foreach($opts as $opt => $value) { + if ($value === false) { + continue; + } + + switch ($opt) + { + case 'h': + case 'hostname': + $hostname = $value; + break; + case 'help': + usage(); + break; + case 'o': + case 'output': + $output = $value; + break; + } +} + + +if (!$hostname || !$output) { + usage(); +} + +if (!is_dir($output)) { + echo "Unable to locate specified output directory $output.\n\n"; + exit(1); +} + +if (!is_writable($output)) { + echo "Output directory $output is not writable.\n\n"; + exit(1); +} + +$geminiOutput = "$output/gemini"; + +if (file_exists($geminiOutput)) { + echo "Gemini build directory $geminiOutput already exists.\n\n"; + exit(1); +} + +$wwwOutput = "$output/www"; + +if (file_exists($wwwOutput)) { + echo "WWW build directory $wwwOutput already exists.\n\n"; + exit(1); +} + +$src = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'; + +if (!is_dir($src)) { + echo "Unable to locate src directory $src.\n\n"; + exit(1); +} + +if (!is_readable($src)) { + echo "Src directory $src is not readable.\n\n"; + exit(1); +} + +$htmlTemplateDiretory = __DIR__.DIRECTORY_SEPARATOR.'../html_templates'; + +if (!is_dir($htmlTemplateDiretory)) { + echo "Unable to locate html template directory $htmlTemplateDiretory.\n\n"; + exit(1); +} + +if (!is_readable($htmlTemplateDiretory)) { + echo "Src directory $htmlTemplateDiretory is not readable.\n\n"; + exit(1); +} + +$assetsDiretory = __DIR__.DIRECTORY_SEPARATOR.'../www_assets'; + +if (!is_dir($assetsDiretory)) { + echo "Unable to locate assets directory $assetsDiretory.\n\n"; + exit(1); +} + +if (!is_readable($assetsDiretory)) { + echo "Src directory $assetsDiretorY is not readable.\n\n"; + exit(1); +} + +$siteMetaData = getSiteMetaData($src); + +buildGeminiSite($siteMetaData, $geminiOutput); + +buildWWWSite($siteMetaData, $wwwOutput, $htmlTemplateDiretory, $assetsDiretory); + |
