Skip to content

Commit 6e0b4aa

Browse files
committed
Build script
1 parent 132d157 commit 6e0b4aa

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

book

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ if (!in_array($command, $commands, true)) {
1919
exit(1);
2020
}
2121

22-
$runCommand = function (string $command) {
22+
23+
24+
$runCommand = function (string $command): int {
2325
echo $command . "\n";
2426
echo system($command, $resultCode);
25-
exit($resultCode);
27+
return $resultCode;
2628
};
2729

28-
$buildBook = function(string $book) use ($runCommand) {
30+
$buildBook = function(string $book) use ($runCommand): int {
2931
$command = <<<COMMAND
3032
cd page; hugo \
3133
--cleanDestinationDir \
@@ -35,11 +37,11 @@ cd page; hugo \
3537
--baseURL https://extensions.terminal42.ch/docs/{book}/
3638
COMMAND;
3739

38-
$runCommand(str_replace('{book}', $book, $command));
40+
return $runCommand(str_replace('{book}', $book, $command));
3941
};
4042

4143

42-
$liveBook = function(string $book) use ($runCommand) {
44+
$liveBook = function(string $book) use ($runCommand): int {
4345
$command = <<<COMMAND
4446
cd page; hugo server \
4547
--cleanDestinationDir \
@@ -48,24 +50,25 @@ cd page; hugo server \
4850
--logLevel info
4951
COMMAND;
5052

51-
$runCommand(str_replace('{book}', $book, $command));
53+
return $runCommand(str_replace('{book}', $book, $command));
5254
};
5355

5456
preg_match('/^(build|live)-(.*)/', $command, $matches);
5557

5658
if ('build-all' === $matches[0]) {
5759
foreach ($books as $book) {
58-
$buildBook($book);
60+
$result = $buildBook($book);
61+
if (0 !== $result) {
62+
exit($result);
63+
}
5964
}
60-
return;
65+
exit(0);
6166
}
6267

6368
if ('build' === $matches[1]) {
64-
$buildBook($matches[2]);
65-
return;
69+
exit($buildBook($matches[2]));
6670
}
6771

6872
if ('live' === $matches[1]) {
69-
$liveBook($matches[2]);
70-
return;
73+
exit($liveBook($matches[2]));
7174
}

0 commit comments

Comments
 (0)