Skip to content

Commit

Permalink
Merge pull request #29 from Muetze42/development
Browse files Browse the repository at this point in the history
fix: dependencies compatibility
  • Loading branch information
Muetze42 authored Oct 28, 2023
2 parents 0fff6b9 + 331fd49 commit 09af9e8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ php artisan custom-assets:publish
php artisan custom-assets:publish:field
```

Publish example resources
Publish example resources (**deprecated** files)

```
php artisan vendor:publish --provider="NormanHuth\NovaAssetsChanger\PackageServiceProvider"
Expand Down Expand Up @@ -109,7 +109,6 @@ Example: [Register Page](/docs/register-page.md)
---
[![More Laravel Nova Packages](https://raw.githubusercontent.com/Muetze42/asset-repo/main/svg/more-laravel-nova-packages.svg)](https://huth.it/nova-packages)

___

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

[![Woman. Life. Freedom.](https://raw.githubusercontent.com/Muetze42/Muetze42/2033b219c6cce0cb656c34da5246434c27919bcd/files/iran-banner-big.svg)](https://linktr.ee/CurrentPetitionsFreeIran)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
},
"require": {
"laravel/nova": "^4.5.2"
"laravel/nova": "^4.27.0"
},
"extra": {
"laravel": {
Expand Down
62 changes: 38 additions & 24 deletions src/Console/Commands/CustomAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected function disableNotifications(): bool
/**
* Execute the console command.
*
* @return int
* @throws JsonException
* @return int
*/
public function handle(): int
{
Expand All @@ -86,6 +86,7 @@ public function handle(): int
$this->reinstallNova();
$this->webpack();
$this->npmInstall();
$this->postCssConfig();
$this->replaceComponents();
$this->registerPages();
$this->addCustomCSS();
Expand All @@ -105,9 +106,9 @@ protected function addCustomCSS(): void
if ($this->storage->exists($file)) {
$this->info(__('Register Nova custom CSS'));
$content = $this->storage->get($file);
$this->novaStorage->put('resources/css/'.$file, $content);
$this->novaStorage->put('resources/css/' . $file, $content);
$cssContent = $this->novaStorage->get('resources/css/app.css');
$cssContent = str_replace("@import 'nova';", "@import 'nova';\n@import '".$file."';", $cssContent);
$cssContent = str_replace("@import 'nova';", "@import 'nova';\n@import '" . $file . "';", $cssContent);
$this->novaStorage->put('resources/css/app.css', $cssContent);
}
}
Expand All @@ -121,19 +122,19 @@ protected function registerPages(): void
foreach ($files as $file) {
$info = pathinfo($file);
$basename = basename($file);
if ($this->novaStorage->exists('resources/js/pages/'.$basename)) {
if ($this->novaStorage->exists('resources/js/pages/' . $basename)) {
$this->error(__('Skip `:file`. File already exist in Nova', ['file' => $file]));
continue;
}
if ($info['extension'] == 'vue') {
$this->info('Register '.$file);
$this->info('Register ' . $file);
$content = $this->storage->get($file);
$this->novaStorage->put('resources/js/pages/'.$basename, $content);
$this->novaStorage->put('resources/js/pages/' . $basename, $content);

$content = $this->novaStorage->get('resources/js/app.js');
if (!str_contains($content, 'Nova.'.$basename)) {
if (!str_contains($content, 'Nova.' . $basename)) {
$content = str_replace("'Nova.Login': require('@/pages/Login').default,",
"'Nova.Login': require('@/pages/Login').default,\n 'Nova.".$info['filename']."': require('@/pages/".$basename."').default,",
"'Nova.Login': require('@/pages/Login').default,\n 'Nova." . $info['filename'] . "': require('@/pages/" . $basename . "').default,",
$content);

$this->novaStorage->put('resources/js/app.js', $content);
Expand All @@ -143,8 +144,8 @@ protected function registerPages(): void
}

/**
* @return void
* @throws JsonException
* @return void
*/
protected function saveCurrentNovaVersion(): void
{
Expand All @@ -159,7 +160,7 @@ protected function publishNovaAssets(): void
$this->info('Publish Nova assets');
usleep(250000);
$this->call('vendor:publish', [
'--tag' => 'nova-assets',
'--tag' => 'nova-assets',
'--force' => true,
]);
}
Expand All @@ -170,8 +171,8 @@ protected function publishNovaAssets(): void
protected function npmProduction(): void
{
$this->info('Run NPM production');
$novaPath = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->novaPath), '/\\').DIRECTORY_SEPARATOR;
$command = 'cd '.$novaPath.' && '.$this->npmCommand.' run production';
$novaPath = rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->novaPath), '/\\') . DIRECTORY_SEPARATOR;
$command = 'cd ' . $novaPath . ' && ' . $this->npmCommand . ' run production';
$this->process->runCommand($command);
foreach ($this->process->getOutput() as $output) {
$this->line($output);
Expand All @@ -185,7 +186,7 @@ protected function reinstallNova(): void
{
$this->info('Reinstall laravel/nova');
$success = false;
$this->process->runCommand($this->composerCommand.' reinstall laravel/nova');
$this->process->runCommand($this->composerCommand . ' reinstall laravel/nova');
foreach ($this->process->getOutput() as $output) {
if (str_contains($output, $this->installStrContainsCheck1) && str_contains($output, $this->installStrContainsCheck2)) {
$success = true;
Expand All @@ -200,33 +201,34 @@ protected function reinstallNova(): void

/**
* @param string $path
*
* @return void
*/
protected function replaceComponents(string $path = 'Nova'): void
{
$files = $this->storage->files($path);
foreach ($files as $file) {
$base = explode('/', $file, 2)[1];
$this->info('Processing '.$base);
if ($this->novaStorage->missing('resources/'.$base)) {
$this->error('Skip file. `'.$base.'` not found in the Nova installation');
$this->info('Processing ' . $base);
if ($this->novaStorage->missing('resources/' . $base)) {
$this->error('Skip file. `' . $base . '` not found in the Nova installation');
continue;
}
$customContent = $this->storage->get($file);
$novaContent = $this->novaStorage->get('resources/'.$base);
if ($this->storage->missing('Backup/'.$base)) {
$this->storage->put('Backup/'.$base, $novaContent);
$novaContent = $this->novaStorage->get('resources/' . $base);
if ($this->storage->missing('Backup/' . $base)) {
$this->storage->put('Backup/' . $base, $novaContent);
} else {
$backupContent = $this->storage->get('Backup/'.$base);
$backupContent = $this->storage->get('Backup/' . $base);
if (trim($backupContent) != trim($novaContent)) {
if (!$this->confirm('The `'.$base.'` file seems to have changed. Do you wish to continue and renew the backup file?')) {
if (!$this->confirm('The `' . $base . '` file seems to have changed. Do you wish to continue and renew the backup file?')) {
$this->error('Abort');
die();
}
$this->storage->put('Backup/'.$base, $novaContent);
$this->storage->put('Backup/' . $base, $novaContent);
}

$this->novaStorage->put('resources/'.$base, $customContent);
$this->novaStorage->put('resources/' . $base, $customContent);
}
}
$directories = $this->storage->directories($path);
Expand All @@ -241,12 +243,24 @@ protected function replaceComponents(string $path = 'Nova'): void
protected function npmInstall(): void
{
$this->info('Run NPM install');
$this->process->runCommand('cd '.$this->novaPath.' && '.$this->npmCommand.' i');
$this->process->runCommand('cd ' . $this->novaPath . ' && ' . $this->npmCommand . ' ci');
foreach ($this->process->getOutput() as $output) {
$this->line($output);
}
}

protected function postCssConfig(): void
{
if (!$this->novaStorage->exists('postcss.config.js')) {
$this->info('postcss.config.js');
$contents = file_get_contents(
dirname(__DIR__, 3) . '/stubs/postcss.config.js.stub'
);

$this->novaStorage->put('postcss.config.js', $contents);
}
}

/**
* @return void
*/
Expand Down
5 changes: 5 additions & 0 deletions stubs/postcss.config.js.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: [
require('autoprefixer'),
],
};

0 comments on commit 09af9e8

Please sign in to comment.