|
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 Cecil\Util; |
|
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
|
|
|
/** |
|
21
|
|
|
* Builds the website. |
|
22
|
|
|
*/ |
|
23
|
|
|
class Build extends AbstractCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('build') |
|
32
|
|
|
->setDescription('Builds the website') |
|
33
|
|
|
->setDefinition( |
|
34
|
|
|
new InputDefinition([ |
|
35
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
|
36
|
|
|
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Set the path to extra config files (comma-separated)'), |
|
37
|
|
|
new InputOption('drafts', 'd', InputOption::VALUE_NONE, 'Include drafts'), |
|
38
|
|
|
new InputOption('page', 'p', InputOption::VALUE_REQUIRED, 'Build a specific page'), |
|
39
|
|
|
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Build without saving'), |
|
40
|
|
|
new InputOption('baseurl', null, InputOption::VALUE_REQUIRED, 'Set the base URL'), |
|
41
|
|
|
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Set the output directory'), |
|
42
|
|
|
new InputOption('postprocess', null, InputOption::VALUE_OPTIONAL, 'Post-process output (disable with "no")', false), |
|
43
|
|
|
new InputOption('clear-cache', null, InputOption::VALUE_NONE, 'Clear cache before build'), |
|
44
|
|
|
]) |
|
45
|
|
|
) |
|
46
|
|
|
->setHelp('Builds the website in the output directory'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
53
|
|
|
{ |
|
54
|
|
|
$config = []; |
|
55
|
|
|
$options = []; |
|
56
|
|
|
$messageOpt = ''; |
|
57
|
|
|
|
|
58
|
|
|
if ($input->getOption('baseurl')) { |
|
59
|
|
|
$config['baseurl'] = $input->getOption('baseurl'); |
|
60
|
|
|
} |
|
61
|
|
|
if ($input->getOption('output')) { |
|
62
|
|
|
$config['output']['dir'] = $input->getOption('output'); |
|
63
|
|
|
$this->fs->dumpFile( |
|
64
|
|
|
Util::joinFile($this->getPath(), self::TMP_DIR, 'output'), |
|
65
|
|
|
(string) $input->getOption('output') |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
if ($input->getOption('postprocess') === null) { |
|
69
|
|
|
$config['postprocess']['enabled'] = true; |
|
70
|
|
|
} |
|
71
|
|
|
if ($input->getOption('postprocess') == 'no') { |
|
72
|
|
|
$config['postprocess']['enabled'] = false; |
|
73
|
|
|
} |
|
74
|
|
|
if ($input->getOption('clear-cache')) { |
|
75
|
|
|
$config['cache']['enabled'] = false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$builder = $this->getBuilder($config); |
|
79
|
|
|
|
|
80
|
|
|
if ($input->getOption('drafts')) { |
|
81
|
|
|
$options['drafts'] = true; |
|
82
|
|
|
$messageOpt .= ' with drafts'; |
|
83
|
|
|
} |
|
84
|
|
|
if ($input->getOption('dry-run')) { |
|
85
|
|
|
$options['dry-run'] = true; |
|
86
|
|
|
$messageOpt .= ' (dry-run)'; |
|
87
|
|
|
} |
|
88
|
|
|
if ($input->getOption('page')) { |
|
89
|
|
|
$options['page'] = $input->getOption('page'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$output->writeln(\sprintf('Building website%s...', $messageOpt)); |
|
93
|
|
|
$output->writeln( |
|
94
|
|
|
sprintf('<comment>Path: %s</comment>', $this->getPath()), |
|
95
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
|
96
|
|
|
); |
|
97
|
|
|
if (!empty($this->getConfigFiles())) { |
|
98
|
|
|
$output->writeln( |
|
99
|
|
|
sprintf('<comment>Config: %s</comment>', implode(', ', $this->getConfigFiles())), |
|
100
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
if ((bool) $this->builder->getConfig()->get('cache.enabled')) { |
|
104
|
|
|
$output->writeln( |
|
105
|
|
|
sprintf('<comment>Cache: %s</comment>', $this->builder->getConfig()->getCachePath()), |
|
106
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$builder->build($options); |
|
111
|
|
|
$this->fs->dumpFile(Util::joinFile($this->getPath(), self::TMP_DIR, 'changes.flag'), time()); |
|
112
|
|
|
$output->writeln('Done! 🎉'); |
|
113
|
|
|
|
|
114
|
|
|
return 0; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|