1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Symplify |
7
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Symplify\PHP7_Sculpin\Console\Command; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symplify\PHP7_Sculpin\Application\Command\RunCommand; |
17
|
|
|
use Symplify\PHP7_Sculpin\Application\SculpinApplication; |
18
|
|
|
use Throwable; |
19
|
|
|
|
20
|
|
|
final class GenerateCommand extends Command |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $sourceDirectory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $outputDirectory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var SculpinApplication |
34
|
|
|
*/ |
35
|
|
|
private $sculpinApplication; |
36
|
|
|
|
37
|
1 |
|
public function __construct( |
38
|
|
|
string $sourceDirectory, |
39
|
|
|
string $outputDirectory, |
40
|
|
|
SculpinApplication $sculpinApplication |
41
|
|
|
) { |
42
|
1 |
|
$this->sourceDirectory = $sourceDirectory; |
43
|
1 |
|
$this->outputDirectory = $outputDirectory; |
44
|
1 |
|
$this->sculpinApplication = $sculpinApplication; |
45
|
|
|
|
46
|
1 |
|
parent::__construct(); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
protected function configure() |
50
|
|
|
{ |
51
|
1 |
|
$this->setName('generate'); |
52
|
1 |
|
$this->setDescription('Generate a site from source.'); |
53
|
1 |
|
$this->addOption('server', null, InputOption::VALUE_NONE, 'Start local server to host your generated site.'); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
|
|
try { |
59
|
1 |
|
$runCommand = new RunCommand( |
60
|
1 |
|
(bool) $input->getOption('server'), |
61
|
1 |
|
$this->sourceDirectory, |
62
|
1 |
|
$this->outputDirectory |
63
|
|
|
); |
64
|
1 |
|
$this->sculpinApplication->runCommand($runCommand); |
65
|
|
|
|
66
|
1 |
|
$output->writeln('<info>Website was successfully generated.</info>'); |
67
|
|
|
|
68
|
1 |
|
return 0; |
69
|
|
|
} catch (Throwable $throwable) { |
70
|
|
|
$output->writeln( |
71
|
|
|
sprintf('<error>%s</error>', $throwable->getMessage()) |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
return 1; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|