-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbook
More file actions
executable file
·72 lines (57 loc) · 1.61 KB
/
book
File metadata and controls
executable file
·72 lines (57 loc) · 1.61 KB
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
#!/usr/bin/env php
<?php
$books = $folders = array_map(function($dir) {
return basename($dir);
}, glob(__DIR__ . '/docs/*', GLOB_ONLYDIR));
$commands = ['build-all'];
foreach ($books as $book) {
$commands[] = 'build-' . $book;
$commands[] = 'live-' . $book;
}
$command = $_SERVER['argv'][1] ?? '';
if (!in_array($command, $commands, true)) {
echo 'Must run one of the following commands:' . "\n- " . implode("\n- ", $commands);
exit(1);
}
$runCommand = function (string $command): int {
echo $command . "\n";
echo system($command, $resultCode);
return $resultCode;
};
$buildBook = function(string $book) use ($runCommand): int {
$command = <<<COMMAND
cd page; hugo \
--cleanDestinationDir \
--environment {book} \
--destination ../build/{book} \
--logLevel info \
--baseURL https://extensions.terminal42.ch/docs/{book}/
COMMAND;
return $runCommand(str_replace('{book}', $book, $command));
};
$liveBook = function(string $book) use ($runCommand): int {
$command = <<<COMMAND
cd page; hugo server \
--cleanDestinationDir \
--environment {book} \
--destination ../build/{book} \
--logLevel info
COMMAND;
return $runCommand(str_replace('{book}', $book, $command));
};
preg_match('/^(build|live)-(.*)/', $command, $matches);
if ('build-all' === $matches[0]) {
foreach ($books as $book) {
$result = $buildBook($book);
if (0 !== $result) {
exit($result);
}
}
exit(0);
}
if ('build' === $matches[1]) {
exit($buildBook($matches[2]));
}
if ('live' === $matches[1]) {
exit($liveBook($matches[2]));
}