|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the PHPoole 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 PHPoole\Command; |
|
12
|
|
|
|
|
13
|
|
|
class Build extends AbstractCommand |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var bool |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $drafts; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $baseurl; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $quiet; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var bool |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $remove; |
|
31
|
|
|
|
|
32
|
|
|
public function processCommand() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->drafts = $this->route->getMatchedParam('drafts', false); |
|
35
|
|
|
$this->baseurl = $this->route->getMatchedParam('baseurl'); |
|
36
|
|
|
$this->quiet = $this->route->getMatchedParam('quiet', false); |
|
37
|
|
|
$this->remove = $this->getRoute()->getMatchedParam('remove', false); |
|
38
|
|
|
|
|
39
|
|
|
$options = []; |
|
40
|
|
|
$messageOpt = ''; |
|
41
|
|
|
|
|
42
|
|
|
if ($this->drafts) { |
|
43
|
|
|
$options['drafts'] = true; |
|
44
|
|
|
$messageOpt = ' (with drafts)'; |
|
45
|
|
|
} |
|
46
|
|
|
if ($this->baseurl) { |
|
47
|
|
|
$options['site']['baseurl'] = $this->baseurl; |
|
48
|
|
|
} |
|
49
|
|
|
if ($this->quiet) { |
|
50
|
|
|
$options['quiet'] = true; |
|
51
|
|
|
} |
|
52
|
|
|
if ($this->remove) { |
|
53
|
|
|
if ($this->fs->exists($this->getPath().'/'.$this->getPHPoole()->getConfig()->get('output.dir'))) { |
|
54
|
|
|
$this->fs->remove($this->getPath().'/'.$this->getPHPoole()->getConfig()->get('output.dir')); |
|
55
|
|
|
$this->wlDone('Output directory removed!'); |
|
56
|
|
|
exit(0); |
|
57
|
|
|
} |
|
58
|
|
|
$this->wlError('Output directory not found!'); |
|
59
|
|
|
exit(0); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
try { |
|
63
|
|
|
$this->wl(sprintf('Building website%s...', $messageOpt)); |
|
64
|
|
|
$this->getPHPoole($options)->build(); |
|
65
|
|
|
if ($this->getRoute()->getName() == 'serve') { |
|
66
|
|
|
$this->fs->dumpFile($this->getPath().'/.phpoole/changes.flag', ''); |
|
67
|
|
|
} |
|
68
|
|
|
} catch (\Exception $e) { |
|
69
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|