|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cecil\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class CommandBuild extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
protected function configure() |
|
13
|
|
|
{ |
|
14
|
|
|
$this |
|
15
|
|
|
->setName('build') |
|
16
|
|
|
->setDescription('Build the website') |
|
17
|
|
|
->setHelp('Build the website in the output directory.') |
|
18
|
|
|
->setDefinition( |
|
19
|
|
|
new InputDefinition([ |
|
20
|
|
|
new InputOption('drafts', 'd', InputOption::VALUE_NONE, 'Include drafts'), |
|
21
|
|
|
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Build without saving'), |
|
22
|
|
|
new InputOption('baseurl', null, InputOption::VALUE_REQUIRED, 'Set the base URL'), |
|
23
|
|
|
new InputOption('destination', null, InputOption::VALUE_REQUIRED, 'Set the output directory'), |
|
24
|
|
|
]) |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
29
|
|
|
{ |
|
30
|
|
|
$config = []; |
|
31
|
|
|
$options = []; |
|
32
|
|
|
|
|
33
|
|
|
if ($input->getOption('drafts')) { |
|
34
|
|
|
$options['drafts'] = true; |
|
35
|
|
|
$messageOpt .= ' with drafts'; |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
if ($input->getOption('dry-run')) { |
|
38
|
|
|
$options['dry-run'] = true; |
|
39
|
|
|
$messageOpt .= ' dry-run'; |
|
40
|
|
|
} |
|
41
|
|
|
if ($input->getOption('baseurl')) { |
|
42
|
|
|
$config['site']['baseurl'] = $input->getOption('baseurl'); |
|
43
|
|
|
} |
|
44
|
|
|
if ($input->getOption('destination')) { |
|
45
|
|
|
$config['site']['output']['dir'] = $input->getOption('destination'); |
|
46
|
|
|
$this->fs->dumpFile($this->getPath() . '/' . Serve::$tmpDir . '/output', $input->getOption('destination')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
try { |
|
50
|
|
|
if (!$this->quiet) { |
|
|
|
|
|
|
51
|
|
|
$output->writeln(sprintf('Building website%s...', $messageOpt)); |
|
52
|
|
|
$output->writeln(sprintf('<comment>Path: %s</comment>', $this->getPath())); |
|
53
|
|
|
} |
|
54
|
|
|
$this->getBuilder($output, $config, $options)->build($options); |
|
55
|
|
|
//if ($this->getRoute()->getName() == 'serve') { |
|
56
|
|
|
// $this->fs->dumpFile($this->getPath() . '/' . Serve::$tmpDir . '/changes.flag', ''); |
|
57
|
|
|
//} |
|
58
|
|
|
} catch (\Exception $e) { |
|
59
|
|
|
throw new \Exception(sprintf('%s', $e->getMessage())); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return 0; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.