|
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 Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
class Build extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this |
|
27
|
|
|
->setName('build') |
|
28
|
|
|
->setDescription('Build the website') |
|
29
|
|
|
->setDefinition( |
|
30
|
|
|
new InputDefinition([ |
|
31
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
|
32
|
|
|
new InputOption('drafts', 'd', InputOption::VALUE_NONE, 'Include drafts'), |
|
33
|
|
|
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Build without saving'), |
|
34
|
|
|
new InputOption('baseurl', null, InputOption::VALUE_REQUIRED, 'Set the base URL'), |
|
35
|
|
|
new InputOption('destination', null, InputOption::VALUE_REQUIRED, 'Set the output directory'), |
|
36
|
|
|
new InputOption( |
|
37
|
|
|
'optimize', |
|
38
|
|
|
null, |
|
39
|
|
|
InputOption::VALUE_OPTIONAL, |
|
40
|
|
|
'Optimize output (disable with "no")', |
|
41
|
|
|
false |
|
42
|
|
|
), |
|
43
|
|
|
]) |
|
44
|
|
|
) |
|
45
|
|
|
->setHelp('Build the website in the output directory.'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
|
|
$config = []; |
|
54
|
|
|
$options = []; |
|
55
|
|
|
$messageOpt = ''; |
|
56
|
|
|
|
|
57
|
|
|
if ($input->getOption('drafts')) { |
|
58
|
|
|
$options['drafts'] = true; |
|
59
|
|
|
$messageOpt .= ' with drafts'; |
|
60
|
|
|
} |
|
61
|
|
|
if ($input->getOption('dry-run')) { |
|
62
|
|
|
$options['dry-run'] = true; |
|
63
|
|
|
$messageOpt .= ' dry-run'; |
|
64
|
|
|
} |
|
65
|
|
|
if ($input->getOption('baseurl')) { |
|
66
|
|
|
$config['baseurl'] = $input->getOption('baseurl'); |
|
67
|
|
|
} |
|
68
|
|
|
if ($input->getOption('destination')) { |
|
69
|
|
|
$config['output']['dir'] = $input->getOption('destination'); |
|
70
|
|
|
$this->fs->dumpFile( |
|
71
|
|
|
$this->getPath().'/'.self::TMP_DIR.'/output', |
|
72
|
|
|
(string) $input->getOption('destination') |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
if ($input->getOption('optimize') === null) { |
|
76
|
|
|
$config['optimize']['enabled'] = true; |
|
77
|
|
|
} |
|
78
|
|
|
if ($input->getOption('optimize') == 'no') { |
|
79
|
|
|
$config['optimize']['enabled'] = false; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$output->writeln(sprintf('Building website%s...', $messageOpt)); |
|
83
|
|
|
$output->writeln( |
|
84
|
|
|
sprintf('<comment>Path: %s</comment>', $this->getPath()), |
|
85
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$builder = $this->getBuilder($output, $config); |
|
89
|
|
|
|
|
90
|
|
|
if ((bool) $this->builder->getConfig()->get('cache.enabled')) { |
|
91
|
|
|
$output->writeln( |
|
92
|
|
|
sprintf('<comment>Cache: %s</comment>', $this->builder->getConfig()->getCachePath()), |
|
93
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$builder->build($options); |
|
98
|
|
|
$this->fs->dumpFile($this->getPath().'/'.self::TMP_DIR.'/changes.flag', time()); |
|
99
|
|
|
|
|
100
|
|
|
return 0; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|