info('Publish Nova assets');
$this->call('vendor:publish', [
@@ -54,7 +69,10 @@ protected function publishNovaAssets()
]);
}
- protected function npmProduction()
+ /**
+ * @return void
+ */
+ protected function npmProduction(): void
{
$this->info('Run NPM production');
$command = 'cd '.$this->novaPath.' && '.$this->npmCommand.' run production';
@@ -64,7 +82,10 @@ protected function npmProduction()
}
}
- protected function reinstallNova()
+ /**
+ * @return void
+ */
+ protected function reinstallNova(): void
{
$this->info('Reinstall laravel/nova');
$this->process->runCommand($this->composerCommand.' reinstall laravel/nova');
@@ -73,7 +94,11 @@ protected function reinstallNova()
}
}
- protected function replaceComponents($path = 'Nova')
+ /**
+ * @param string $path
+ * @return void
+ */
+ protected function replaceComponents(string $path = 'Nova'): void
{
$files = $this->storage->files($path);
foreach ($files as $file) {
@@ -106,7 +131,10 @@ protected function replaceComponents($path = 'Nova')
}
}
- protected function npmInstall()
+ /**
+ * @return void
+ */
+ protected function npmInstall(): void
{
$this->info('Run NPM install');
$this->process->runCommand('cd '.$this->novaPath.' && '.$this->npmCommand.' i');
@@ -115,7 +143,10 @@ protected function npmInstall()
}
}
- protected function webpack()
+ /**
+ * @return void
+ */
+ protected function webpack(): void
{
if ($this->novaStorage->exists('webpack.mix.js.dist')) {
$this->info('Create webpack.mix.js');
diff --git a/src/Console/Commands/PublishCommand.php b/src/Console/Commands/PublishCommand.php
new file mode 100644
index 0000000..2780606
--- /dev/null
+++ b/src/Console/Commands/PublishCommand.php
@@ -0,0 +1,117 @@
+selectBaseDirectory();
+
+ return 0;
+ }
+
+ /**
+ * @return void
+ */
+ protected function break(): void
+ {
+ $this->newLine(3);
+ $this->comment('--------------------');
+ }
+
+ /**
+ * @return void
+ */
+ protected function selectBaseDirectory(): void
+ {
+ $i = 0;
+ foreach ($this->baseDirectories as $baseDirectory) {
+ $this->line('['.$i++.'] '.$baseDirectory);
+ }
+
+ $directory = $this->ask('Choose a directory');
+
+ if (empty($this->baseDirectories[$directory])) {
+ $this->break();
+ $this->selectBaseDirectory();
+ }
+ $this->handleDirectory($this->baseDirectories[$directory]);
+ }
+
+ /**
+ * @param $path
+ * @return void
+ */
+ protected function handleDirectory($path): void
+ {
+ $this->error($path);
+ $this->break();
+ $directories = $this->novaStorage->directories($path);
+ $i = 0;
+ $array = [];
+ if (count($directories)) {
+ $this->info('Directories: ');
+ foreach ($directories as $directory) {
+ $array[$i] = ['directory' => $directory];
+ $this->line('['.$i++.'] '.$directory);
+ }
+ }
+ $files = $this->novaStorage->files($path);
+ if (count($files)) {
+ $this->info('Files: ');
+ foreach ($files as $file) {
+ $array[$i] = $file;
+ $this->line('['.$i++.'] '.$file);
+ }
+ }
+
+ $select = $this->ask('Choose...');
+
+ if (empty($array[$select])) {
+ $this->handleDirectory($path);
+ return;
+ }
+
+ if (!empty($array[$select]['directory'])) {
+ $this->handleDirectory($array[$select]['directory']);
+ return;
+ }
+
+ $file = 'Nova/'.explode('/', $array[$select], 2)[1];
+ if ($this->storage->exists($file) && !$this->confirm('The file `'.$file.'` already exist. Overwrite this file?')) {
+ die('Abort');
+ }
+
+ $this->storage->put($file, $this->novaStorage->get($array[$select]));
+ $this->line('Copied File ['.$this->novaStorage->path($array[$select]).'] To ['.$this->storage->path($file).']');
+ }
+}
diff --git a/src/Helpers/Process.php b/src/Helpers/Process.php
index 77578f9..dc6505f 100644
--- a/src/Helpers/Process.php
+++ b/src/Helpers/Process.php
@@ -6,7 +6,7 @@
class Process
{
- protected bool $commandLogging = true;
+ protected bool $commandLogging = false;
protected bool $outputLogging = false;
protected ?array $output;
protected ?array $errorOutput;
@@ -76,7 +76,7 @@ public function getError(): ?array
*
* @param object|array|string $output
*/
- protected function outputLogging(object|array|string $output)
+ protected function outputLogging(object|array|string $output): void
{
if ($this->outputLogging) {
$this->infoLog($output);
@@ -88,7 +88,7 @@ protected function outputLogging(object|array|string $output)
*
* @param object|array|string $command
*/
- protected function commandLogging(object|array|string $command)
+ protected function commandLogging(object|array|string $command): void
{
if ($this->commandLogging) {
$this->infoLog('Run command `'.$command.'`:');
@@ -98,7 +98,7 @@ protected function commandLogging(object|array|string $command)
/**
* @param object|array|string $content
*/
- protected function infoLog(object|array|string $content)
+ protected function infoLog(object|array|string $content): void
{
if (is_array($content)) {
$content = implode("\n", $content);
@@ -110,36 +110,4 @@ protected function infoLog(object|array|string $content)
Log::info($content);
}
-
- /**
- * Disable the output logging.
- */
- public function disableOutputLogging()
- {
- $this->outputLogging = false;
- }
-
- /**
- * Enable the output logging.
- */
- public function enableOutputLogging()
- {
- $this->outputLogging = true;
- }
-
- /**
- * Disable the command logging.
- */
- public function disableCommandLogging()
- {
- $this->commandLogging = false;
- }
-
- /**
- * Enable the command logging.
- */
- public function enableCommandLogging()
- {
- $this->commandLogging = true;
- }
}
diff --git a/src/PackageServiceProvider.php b/src/PackageServiceProvider.php
index e8cd4ba..30f02ee 100644
--- a/src/PackageServiceProvider.php
+++ b/src/PackageServiceProvider.php
@@ -4,6 +4,7 @@
use Illuminate\Support\ServiceProvider;
use NormanHuth\NovaAssetsChanger\Console\Commands\CustomAssetsCommand;
+use NormanHuth\NovaAssetsChanger\Console\Commands\PublishCommand;
class PackageServiceProvider extends ServiceProvider
{
@@ -20,6 +21,7 @@ public function boot()
if ($this->app->runningInConsole()) {
$this->commands([
CustomAssetsCommand::class,
+ PublishCommand::class,
]);
}
}