1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Cecil/Cecil package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cecil\Command; |
12
|
|
|
|
13
|
|
|
use phpDocumentor\Reflection\Types\Boolean; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
class Build extends Command |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('build') |
29
|
|
|
->setDescription('Build the website') |
30
|
|
|
->setDefinition( |
31
|
|
|
new InputDefinition([ |
32
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
33
|
|
|
new InputOption('drafts', 'd', InputOption::VALUE_NONE, 'Include drafts'), |
34
|
|
|
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Build without saving'), |
35
|
|
|
new InputOption('baseurl', null, InputOption::VALUE_REQUIRED, 'Set the base URL'), |
36
|
|
|
new InputOption('destination', null, InputOption::VALUE_REQUIRED, 'Set the output directory'), |
37
|
|
|
new InputOption('optimize', null, InputOption::VALUE_OPTIONAL, 'Optimize output (disable with "no")', false), |
38
|
|
|
]) |
39
|
|
|
) |
40
|
|
|
->setHelp('Build the website in the output directory.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
$config = []; |
49
|
|
|
$options = []; |
50
|
|
|
$messageOpt = ''; |
51
|
|
|
|
52
|
|
|
if ($input->getOption('drafts')) { |
53
|
|
|
$options['drafts'] = true; |
54
|
|
|
$messageOpt .= ' with drafts'; |
55
|
|
|
} |
56
|
|
|
if ($input->getOption('dry-run')) { |
57
|
|
|
$options['dry-run'] = true; |
58
|
|
|
$messageOpt .= ' dry-run'; |
59
|
|
|
} |
60
|
|
|
if ($input->getOption('baseurl')) { |
61
|
|
|
$config['baseurl'] = $input->getOption('baseurl'); |
62
|
|
|
} |
63
|
|
|
if ($input->getOption('destination')) { |
64
|
|
|
$config['output']['dir'] = $input->getOption('destination'); |
65
|
|
|
$this->fs->dumpFile($this->getPath().'/'.self::TMP_DIR.'/output', $input->getOption('destination')); |
66
|
|
|
} |
67
|
|
|
if ($input->getOption('optimize') === null) { |
68
|
|
|
$config['optimize']['enabled'] = true; |
69
|
|
|
} |
70
|
|
|
if ($input->getOption('optimize') === false || $input->getOption('optimize') == 'no') { |
71
|
|
|
$config['optimize']['enabled'] = false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
try { |
75
|
|
|
$output->writeln(sprintf('Building website%s...', $messageOpt)); |
76
|
|
|
$output->writeln(sprintf('<comment>Path: %s</comment>', $this->getPath())); |
77
|
|
|
$this->getBuilder($output, $config)->build($options); |
78
|
|
|
$this->fs->dumpFile($this->getPath().'/'.self::TMP_DIR.'/changes.flag', time()); |
79
|
|
|
} catch (\Exception $e) { |
80
|
|
|
throw new \Exception(sprintf('%s', $e->getMessage())); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return 0; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|