-
Notifications
You must be signed in to change notification settings - Fork 3
/
book
executable file
·70 lines (55 loc) · 1.48 KB
/
book
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
#!/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) {
echo $command . "\n";
echo system($command);
};
$buildBook = function(string $book) use ($runCommand) {
$command = <<<COMMAND
cd page; hugo \
--cleanDestinationDir \
--environment {book} \
--destination ../build/{book} \
--logLevel info \
--baseURL https://extensions.terminal42.ch/docs/{book}/
COMMAND;
$runCommand(str_replace('{book}', $book, $command));
};
$liveBook = function(string $book) use ($runCommand) {
$command = <<<COMMAND
cd page; hugo server \
--cleanDestinationDir \
--environment {book} \
--destination ../build/{book} \
--logLevel info
COMMAND;
$runCommand(str_replace('{book}', $book, $command));
};
preg_match('/^(build|live)-(.*)/', $command, $matches);
if ('build-all' === $matches[0]) {
foreach ($books as $book) {
$buildBook($book);
}
return;
}
if ('build' === $matches[1]) {
$buildBook($matches[2]);
return;
}
if ('live' === $matches[1]) {
$liveBook($matches[2]);
return;
}