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\Builder; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Build. |
17
|
|
|
*/ |
18
|
|
|
class Build extends AbstractCommand |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $drafts; |
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $verbose; |
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected $quiet; |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $baseurl; |
36
|
|
|
/** |
37
|
|
|
* @var destination |
38
|
|
|
*/ |
39
|
|
|
protected $destination; |
40
|
|
|
/** |
41
|
|
|
* @var bool |
42
|
|
|
*/ |
43
|
|
|
protected $dryrun; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function processCommand() |
49
|
|
|
{ |
50
|
|
|
$this->drafts = $this->getRoute()->getMatchedParam('drafts', false); |
51
|
|
|
$this->verbose = $this->getRoute()->getMatchedParam('verbose', false); |
52
|
|
|
$this->quiet = $this->getRoute()->getMatchedParam('quiet', false); |
53
|
|
|
$this->baseurl = $this->getRoute()->getMatchedParam('baseurl'); |
54
|
|
|
$this->destination = $this->getRoute()->getMatchedParam('destination'); |
55
|
|
|
$this->dryrun = $this->getRoute()->getMatchedParam('dry-run', false); |
56
|
|
|
|
57
|
|
|
$config = []; |
58
|
|
|
$options = []; |
59
|
|
|
$messageOpt = ''; |
60
|
|
|
|
61
|
|
|
if ($this->drafts) { |
62
|
|
|
$options['drafts'] = true; |
63
|
|
|
$messageOpt .= ' with drafts'; |
64
|
|
|
} |
65
|
|
|
if ($this->verbose) { |
66
|
|
|
$options['verbosity'] = Builder::VERBOSITY_VERBOSE; |
67
|
|
|
} else { |
68
|
|
|
if ($this->quiet) { |
69
|
|
|
$options['verbosity'] = Builder::VERBOSITY_QUIET; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
if ($this->baseurl) { |
73
|
|
|
$config['site']['baseurl'] = $this->baseurl; |
74
|
|
|
} |
75
|
|
|
if ($this->destination) { |
76
|
|
|
$config['output']['dir'] = $this->destination; |
77
|
|
|
$this->fs->dumpFile($this->getPath().'/'.Serve::$tmpDir.'/output', $this->destination); |
78
|
|
|
} |
79
|
|
|
if ($this->dryrun) { |
80
|
|
|
$options['dry-run'] = true; |
81
|
|
|
$messageOpt .= ' dry-run'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
try { |
85
|
|
|
if (!$this->quiet) { |
86
|
|
|
$this->wl(sprintf('Building website%s...', $messageOpt)); |
87
|
|
|
} |
88
|
|
|
$this->getBuilder($config, $options)->build($options); |
89
|
|
|
if ($this->getRoute()->getName() == 'serve') { |
90
|
|
|
$this->fs->dumpFile($this->getPath().'/'.Serve::$tmpDir.'/changes.flag', ''); |
91
|
|
|
} |
92
|
|
|
} catch (\Exception $e) { |
93
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|