forked from twigphp/Twig
-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.php
executable file
·56 lines (46 loc) · 2.15 KB
/
build.php
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
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use SymfonyDocsBuilder\BuildConfig;
use SymfonyDocsBuilder\DocBuilder;
(new Application('Twig docs Builder', '1.0'))
->register('build-docs')
->addOption('disable-cache', null, InputOption::VALUE_NONE, 'Use this option to force a full regeneration of all doc contents')
->setCode(function (InputInterface $input, OutputInterface $output) {
$io = new SymfonyStyle($input, $output);
$io->text('Building all Twig docs...');
$outputDir = __DIR__.'/output';
$buildConfig = (new BuildConfig())
->setContentDir(__DIR__.'/..')
->setOutputDir($outputDir)
->setImagesDir(__DIR__.'/output/_images')
->setImagesPublicPrefix('_images')
->setTheme('rtd')
;
$buildConfig->setExcludedPaths(['vendor/']);
$buildConfig->disableJsonFileGeneration();
$buildConfig->disableBuildCache();
$result = (new DocBuilder())->build($buildConfig);
if ($result->isSuccessful()) {
// fix assets URLs to make them absolute (otherwise, they don't work in subdirectories)
foreach (glob($outputDir.'/**/*.html') as $htmlFilePath) {
$htmlContents = file_get_contents($htmlFilePath);
file_put_contents($htmlFilePath, str_replace('href="assets/', 'href="/assets/', $htmlContents));
}
$io->success(sprintf('The Twig docs were successfully built at %s', realpath($outputDir)));
} else {
$io->error(sprintf("There were some errors while building the docs:\n\n%s\n", $result->getErrorTrace()));
$io->newLine();
$io->comment('Tip: you can add the -v, -vv or -vvv flags to this command to get debug information.');
return 1;
}
return 0;
})
->getApplication()
->setDefaultCommand('build-docs', true)
->run();