Skip to content

Commit

Permalink
Improvements, fixes, & new console command.
Browse files Browse the repository at this point in the history
  • Loading branch information
munafio committed Jun 20, 2021
1 parent a259c89 commit 29fcf53
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 18 deletions.
78 changes: 60 additions & 18 deletions src/Console/InstallChatify.php → src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;

class InstallChatify extends Command
class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'chatify:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Install Chatify package';

/**
* Check Laravel version.
*
* @var bool
*/
private $isV8;

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->isV8 = explode('.',app()->version())[0] >= 8;
Expand Down Expand Up @@ -53,6 +73,13 @@ public function handle()
$this->info('[✓] Chatify installed successfully');
}

/**
* Modify models imports/namespace path according to Laravel version.
*
* @param string $targetFilePath
* @param string $model
* @return void
*/
private function modifyModelsPath($targetFilePath, $model = null){
$path = realpath(__DIR__.$targetFilePath);
$contents = File::get($path);
Expand All @@ -65,22 +92,36 @@ private function modifyModelsPath($targetFilePath, $model = null){
File::put($path, $contents);
}

/**
* Check, publish, or overwrite the assets.
*
* @param string $target
* @param string $path
* @return void
*/
private function process($target, $path)
{
$this->line('Publishing '.$target.'...');
if (!File::exists($path)) {
$this->publish($target);
$this->info('[✓] '.$target.' published.');
} else {
if ($this->shouldOverwrite($target)) {
$this->line('Overwriting '.$target.'...');
$this->publish($target,true);
} else {
$this->line('[-] Ignored, The existing '.$target.' was not overwritten');
}
return;
}
if ($this->shouldOverwrite($target)) {
$this->line('Overwriting '.$target.'...');
$this->publish($target,true);
$this->info('[✓] '.$target.' published.');
return;
}
$this->line('[-] Ignored, The existing '.$target.' was not overwritten');
}

/**
* Ask to overwrite.
*
* @param string $target
* @return void
*/
private function shouldOverwrite($target)
{
return $this->confirm(
Expand All @@ -89,17 +130,18 @@ private function shouldOverwrite($target)
);
}

/**
* Call the publish command.
*
* @param string $tag
* @param bool $forcePublish
* @return void
*/
private function publish($tag, $forcePublish = false)
{
$params = [
'--provider' => "Chatify\ChatifyServiceProvider",
'--tag' => 'chatify-'.$tag
];

if ($forcePublish === true) {
$params['--force'] = '';
}

$this->call('vendor:publish', $params);
$this->call('vendor:publish', [
'--tag' => 'chatify-'.$tag,
'--force' => $forcePublish,
]);
}
}
45 changes: 45 additions & 0 deletions src/Console/PublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Chatify\Console;

use Illuminate\Console\Command;

class PublishCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'chatify:publish {--force : Overwrite any existing files}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Publish all of the chatify assets';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->call('vendor:publish', [
'--tag' => 'chatify-config',
'--force' => $this->option('force'),
]);

$this->call('vendor:publish', [
'--tag' => 'chatify-views',
'--force' => true,
]);

$this->call('vendor:publish', [
'--tag' => 'chatify-assets',
'--force' => true,
]);
}
}

0 comments on commit 29fcf53

Please sign in to comment.