1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\AdminLTETemplateLaravel\Console; |
4
|
|
|
|
5
|
|
|
use Acacha\AdminLTETemplateLaravel\Console\Traits\UseComposer; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
use Symfony\Component\Console\Command\Command; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class InstallCommand. |
14
|
|
|
*/ |
15
|
|
|
class InstallCommand extends Command |
16
|
|
|
{ |
17
|
|
|
use UseComposer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get package name to install. |
21
|
|
|
*/ |
22
|
|
|
protected function getPackageName() |
23
|
|
|
{ |
24
|
|
|
return 'acacha/admin-lte-template-laravel'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Configure the command options. |
29
|
|
|
*/ |
30
|
|
|
protected function configure() |
31
|
|
|
{ |
32
|
|
|
$this->ignoreValidationErrors(); |
33
|
|
|
|
34
|
|
|
$this->setName('install') |
35
|
|
|
->setDescription('Install Acacha AdminLTE Laravel package into the current project.') |
36
|
|
|
->addOption( |
37
|
|
|
'dev', |
38
|
|
|
'-d', |
39
|
|
|
InputOption::VALUE_NONE, |
40
|
|
|
'Installs the latest "development" release' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'force', |
44
|
|
|
'-f', |
45
|
|
|
InputOption::VALUE_NONE, |
46
|
|
|
'Forces install even if the directory already exists' |
47
|
|
|
) |
48
|
|
|
->addOption( |
49
|
|
|
'use-vendor-publish', |
50
|
|
|
'-p', |
51
|
|
|
InputOption::VALUE_NONE, |
52
|
|
|
'Installs using php artisan vendor:publish --tag=adminlte --force . By default php artisan adminlte-laravel:publish is used' |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Execute the command. |
58
|
|
|
* |
59
|
|
|
* @param InputInterface $input |
60
|
|
|
* @param OutputInterface $output |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
65
|
|
|
{ |
66
|
|
|
$noansi = ''; |
67
|
|
|
if ($input->getOption('no-ansi')) { |
68
|
|
|
$noansi = ' --no-ansi'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$process = new Process( |
72
|
|
|
$this->findComposer() . ' require ' . $package = $this->getPackageName() . $this->getDevSuffix($input) . $noansi, |
73
|
|
|
null, |
74
|
|
|
null, |
75
|
|
|
null, |
76
|
|
|
null |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { |
80
|
|
|
$process->setTty(true); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$output->writeln( |
84
|
|
|
'<info>Running composer require ' . $package .'</info>' |
85
|
|
|
); |
86
|
|
|
$process->run(function ($type, $line) use ($output) { |
87
|
|
|
$output->write($line); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
$input->getOption('use-vendor-publish') ? $this->publishWithVendor($output) : $this->publish($output); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Gets dev suffix. |
95
|
|
|
* |
96
|
|
|
* @param InputInterface $input |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
private function getDevSuffix(InputInterface $input) |
100
|
|
|
{ |
101
|
|
|
return $input->getOption('dev') ? ':dev-master' : ''; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Manually publishes files to project. |
106
|
|
|
* |
107
|
|
|
* @param OutputInterface $output |
108
|
|
|
*/ |
109
|
|
|
protected function publish(OutputInterface $output) |
110
|
|
|
{ |
111
|
|
|
$output->writeln('<info>php artisan adminlte:publish</info>'); |
112
|
|
|
passthru('php artisan adminlte-laravel:publish'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Publishes files with artisan publish command. |
117
|
|
|
* |
118
|
|
|
* @param OutputInterface $output |
119
|
|
|
*/ |
120
|
|
|
protected function publishWithVendor(OutputInterface $output) |
121
|
|
|
{ |
122
|
|
|
$output->writeln('<info>php artisan vendor:publish --tag=adminlte --force</info>'); |
123
|
|
|
passthru('php artisan vendor:publish --tag=adminlte --force'); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|