summaryrefslogtreecommitdiff
path: root/scripts/build.php
blob: eecb67712c1133fd5ffae47f3649fa028d1e182d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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);
}

$pages = getPages($src, $geminiOutput, $wwwOutput);

buildGeminiSite($pages);

buildWWWSite($pages, $hostname, $htmlTemplateDiretory, $assetsDiretory, $wwwOutput);