1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodexShaper\PWA\Commands; |
4
|
|
|
|
5
|
|
|
use CodexShaper\PWA\PwaServiceProvider; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
|
11
|
|
|
class InstallPwa extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The console command name. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'pwa:install'; |
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Install the Laravel PWA'; |
25
|
|
|
/** |
26
|
|
|
* The database Seeder Path. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $seedersPath = __DIR__.'/../../database/seeds/'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get Option. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
protected function getOptions() |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null], |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the composer command for the environment. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
protected function findComposer() |
50
|
|
|
{ |
51
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
52
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return 'composer'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Execute the console command. |
60
|
|
|
* |
61
|
|
|
* @param \Illuminate\Filesystem\Filesystem $filesystem |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function handle(Filesystem $filesystem) |
66
|
|
|
{ |
67
|
|
|
$this->info('Publishing the PWA assets, database, and config files'); |
68
|
|
|
// Publish only relevant resources on install |
69
|
|
|
$tags = ['pwa.migrations', 'pwa.tenant.migrations', 'pwa.config', 'pwa.views', 'pwa.lang']; |
70
|
|
|
$this->call('vendor:publish', ['--provider' => PwaServiceProvider::class, '--tag' => $tags]); |
71
|
|
|
|
72
|
|
|
$this->info('Migrating the database tables into your application'); |
73
|
|
|
$this->call('migrate', ['--force' => $this->option('force')]); |
74
|
|
|
|
75
|
|
|
$this->info('Dumping the autoloaded files and reloading all new files'); |
76
|
|
|
$composer = $this->findComposer(); |
77
|
|
|
$process = Process::fromShellCommandline($composer.' dump-autoload'); |
78
|
|
|
$process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time |
79
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
80
|
|
|
|
81
|
|
|
// Load Permission routes into application's 'routes/web.php' |
82
|
|
|
$this->info('Adding Permission routes to routes/web.php'); |
83
|
|
|
$routes_contents = $filesystem->get(base_path('routes/web.php')); |
84
|
|
|
if (false === strpos($routes_contents, 'PWA::routes();')) { |
85
|
|
|
$filesystem->append( |
86
|
|
|
base_path('routes/web.php'), |
87
|
|
|
"\n\PWA::routes();\n" |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
if ($filesystem->exists(base_path('routes/tenant.php'))) { |
91
|
|
|
$this->info('Adding Permission routes to routes/tenant.php'); |
92
|
|
|
$routes_contents = $filesystem->get(base_path('routes/tenant.php')); |
93
|
|
|
if (false === strpos($routes_contents, 'PWA::routes();')) { |
94
|
|
|
$filesystem->append( |
95
|
|
|
base_path('routes/tenant.php'), |
96
|
|
|
"\n\PWA::routes();\n" |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|