Skip to content

Commit

Permalink
Update Publish.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Nov 1, 2023
1 parent 51e5bd1 commit d416b1c
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/Commands/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use League\Flysystem\MountManager;
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
use League\Flysystem\Visibility;
use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;

class Publish extends Command
{
Expand Down Expand Up @@ -56,7 +59,7 @@ public function __construct(Filesystem $files)
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
$this->module = mb_strtolower($this->argument('module'));
if (!is_dir(base_path('vendor/typicms/' . $this->module))) {
Expand All @@ -68,6 +71,7 @@ public function handle()
$this->publishModule();
$this->changePathForLoadViews();
$this->uninstallFromComposer();
info(ucfirst($this->module) . ' module successfully published.');
} else {
throw new Exception($provider . ' not found, did you add it to config/app.php?');
}
Expand All @@ -86,10 +90,8 @@ private function publishModule()
if ($this->files->isDirectory($from)) {
$this->publishDirectory($from, $to);
} else {
$this->error("Can’t locate path: <{$from}>");
error("Can’t locate path: <{$from}>");
}

$this->info('Publishing complete for module [' . ucfirst($this->module) . ']!');
}

/**
Expand All @@ -116,24 +118,6 @@ protected function publishDirectory($from, $to)
$manager->write('to://' . $path, $manager->read($file['path']));
}
}

$this->status($from, $to, 'Directory');
}

/**
* Write a status message to the console.
*
* @param string $from
* @param string $to
* @param string $type
*/
protected function status($from, $to, $type)
{
$from = str_replace(base_path(), '', realpath($from));

$to = str_replace(base_path(), '', realpath($to));

$this->line('<info>Copied ' . $type . '</info> <comment>[' . $from . ']</comment> <info>To</info> <comment>[' . $to . ']</comment>');
}

/**
Expand All @@ -152,11 +136,14 @@ private function changePathForLoadViews()
*/
private function uninstallFromComposer()
{
$uninstallCommand = 'composer remove typicms/' . $this->module;
if (function_exists('system')) {
system($uninstallCommand);
if (is_callable('shell_exec') && !stripos(ini_get('disable_functions'), 'shell_exec')) {
$uninstallCommand = 'composer remove typicms/' . $this->module . ' 2> /dev/null';
spin(
fn () => shell_exec($uninstallCommand),
'Uninstall ' . $this->module . ' from composer…'
);
} else {
$this->line('You can now run ' . $uninstallCommand . '.');
info('You can now run ' . $uninstallCommand . '.');
}
}
}

0 comments on commit d416b1c

Please sign in to comment.