Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into wip/trigger-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Jul 30, 2024
2 parents 0107abb + 5198a5c commit b5afa3b
Show file tree
Hide file tree
Showing 45 changed files with 977 additions and 523 deletions.
2 changes: 1 addition & 1 deletion modules/backend/console/UserCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(): int
'first_name' => $this->option('fname') ?: $this->ask('First name', ''),
'last_name' => $this->option('lname') ?: $this->ask('Last name', ''),
'role_id' => (
$role = UserRole::where(
UserRole::where(
'code',
$this->option('role') ?: $this->choice(
'Role',
Expand Down
8 changes: 5 additions & 3 deletions modules/backend/formwidgets/Relation.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php namespace Backend\FormWidgets;
<?php

namespace Backend\FormWidgets;

use Db;
use Lang;
use Backend\Classes\FormField;
use Backend\Classes\FormWidgetBase;
use Lang;
use Winter\Storm\Database\Relations\Relation as RelationBase;
use Illuminate\Database\Eloquent\Relations\Relation as RelationBase;
use Winter\Storm\Exception\SystemException;

/**
Expand Down
6 changes: 4 additions & 2 deletions modules/backend/formwidgets/TagList.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php namespace Backend\FormWidgets;
<?php

namespace Backend\FormWidgets;

use Backend\Classes\FormWidgetBase;
use Winter\Storm\Database\Relations\Relation as RelationBase;
use Illuminate\Database\Eloquent\Relations\Relation as RelationBase;

/**
* Tag List Form Widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class="field-fileupload style-file-multi is-sortable is-multi <?= count($fileLis
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $file->id ?>"
data-request-data="file_id: '<?= $file->id ?>'"
><i class="icon-times"></i></a>
</h4>
<p class="size"><?= e($file->sizeToString()) ?></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class="field-fileupload style-file-single <?= $singleFile ? 'is-populated' : ''
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $singleFile->id ?>"
data-request-data="file_id: '<?= $singleFile->id ?>'"
><i class="icon-times"></i></a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class="field-fileupload style-image-multi is-sortable is-multi <?= count($fileLi
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $file->id ?>"
data-request-data="file_id: '<?= $file->id ?>'"
><i class="icon-times"></i></a>
</h4>
<p class="size"><?= e($file->sizeToString()) ?></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class="upload-button">
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $singleFile->id ?>"
data-request-data="file_id: '<?= $singleFile->id ?>'"
><i class="icon-times"></i></a>
</h4>
<p class="size"><?= e($singleFile->sizeToString()) ?></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace System\Tests\Classes;
namespace Cms\Tests\Classes;

use System\Tests\Bootstrap\PluginTestCase;
use Cms\Classes\AutoDatasource;
Expand Down
2 changes: 1 addition & 1 deletion modules/cms/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Block;
use Cms\Classes\Controller;
use Event;
use System\Classes\Vite;
use System\Classes\Asset\Vite;
use Twig\Extension\AbstractExtension as TwigExtension;
use Twig\TwigFilter as TwigSimpleFilter;
use Twig\TwigFunction as TwigSimpleFunction;
Expand Down
12 changes: 6 additions & 6 deletions modules/system/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Config;
use DateInterval;
use Event;
use Illuminate\Foundation\Vite;
use Illuminate\Foundation\Vite as LaravelVite;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Schema;
use Markdown;
Expand Down Expand Up @@ -145,7 +145,7 @@ protected function registerSingletons()
});

// Register the Laravel Vite singleton
$this->app->singleton(Vite::class, \System\Classes\Vite::class);
$this->app->singleton(LaravelVite::class, \System\Classes\Asset\Vite::class);
}

/**
Expand Down Expand Up @@ -321,19 +321,19 @@ protected function registerConsole()
$this->registerConsoleCommand('plugin.list', \System\Console\PluginList::class);

$this->registerConsoleCommand('mix.compile', Console\Asset\Mix\MixCompile::class);
$this->registerConsoleCommand('mix.config', Console\Asset\Mix\MixConfig::class);
$this->registerConsoleCommand('mix.config', Console\Asset\Mix\MixCreate::class);
$this->registerConsoleCommand('mix.install', Console\Asset\Mix\MixInstall::class);
$this->registerConsoleCommand('mix.list', Console\Asset\Mix\MixList::class);
$this->registerConsoleCommand('mix.watch', Console\Asset\Mix\MixWatch::class);

$this->registerConsoleCommand('vite.compile', Console\Asset\Vite\ViteCompile::class);
$this->registerConsoleCommand('vite.config', Console\Asset\Vite\ViteConfig::class);
$this->registerConsoleCommand('vite.config', Console\Asset\Vite\ViteCreate::class);
$this->registerConsoleCommand('vite.install', Console\Asset\Vite\ViteInstall::class);
$this->registerConsoleCommand('vite.list', Console\Asset\Vite\ViteList::class);
$this->registerConsoleCommand('vite.watch', Console\Asset\Vite\ViteWatch::class);

$this->registerConsoleCommand('npm.run', Console\NpmRun::class);
$this->registerConsoleCommand('npm.update', Console\NpmUpdate::class);
$this->registerConsoleCommand('npm.run', Console\Asset\NpmRun::class);
$this->registerConsoleCommand('npm.update', Console\Asset\NpmUpdate::class);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion modules/system/classes/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function listRegisteredLayouts()
/**
* Registers a callback function that defines mail templates.
* The callback function should register templates by calling the manager's
* registerMailTemplates() function. Thi instance is passed to the
* registerMailTemplates() function. This instance is passed to the
* callback function as an argument. Usage:
*
* MailManager::registerCallback(function ($manager) {
Expand Down
246 changes: 246 additions & 0 deletions modules/system/classes/asset/BundleManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<?php

namespace System\Classes\Asset;

use Closure;
use Winter\Storm\Support\Traits\Singleton;

/**
* Asset Bundle manager.
*
* This class manages "asset bundles" registered by the core and plugins that are used by the
* [mix|vite]:create commands to generate & populate the required files for a given bundle.
* Bundles include information on the specific packages & versions required for the bundle
* to function in the context of the Winter package (plugin or theme) it is being used in,
* as well as dependencies specific to the desired compiler (e.g. mix or vite).
*
* @package winter\wn-system-module
* @author Jack Wilkinson <[email protected]>
* @copyright Winter CMS Maintainers
*/
class BundleManager
{
use Singleton;

protected const HANDLER_SETUP = '_setup';
protected const HANDLER_SCAFFOLD = '_scaffold';

/**
* List of packages available to install. Allows for `$compilerName` => [`CompilerSpecificPackage`]
*/
protected array $defaultPackages = [
'tailwind' => [
'tailwindcss' => '^3.4.0',
'@tailwindcss/forms' => '^0.5.3',
'@tailwindcss/typography' => '^0.5.2',
],
'vue' => [
'vue' => '^3.4.0',
'vite' => [
'@vitejs/plugin-vue' => '^5.0.5'
],
],
];

/**
* List of registered asset bundles in the system
*/
protected array $registeredBundles = [];

/**
* Initialize the singleton
*/
public function init(): void
{
// Register the default bundles
$this->registerCallback(function (self $manager) {
$manager->registerBundles($this->defaultPackages);

$manager->registerSetupHandler('tailwind', function (string $packagePath, string $packageType) {
$this->writeFile(
$packagePath . '/tailwind.config.js',
$this->getFixture('tailwind/tailwind.' . $packageType . '.config.js.fixture')
);

$this->writeFile(
$packagePath . '/postcss.config.mjs',
$this->getFixture('tailwind/postcss.config.js.fixture')
);
});

$manager->registerScaffoldHandler('tailwind', function (string $contents, string $contentType) {
return match ($contentType) {
'mix' => $contents . PHP_EOL . <<<JAVASCRIPT
mix.postCss('assets/src/css/{{packageName}}.css', 'assets/dist/css/{{packageName}}.css', [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]);
JAVASCRIPT,
'css' => $this->getFixture('css/tailwind.css.fixture'),
default => $contents
};
});

$manager->registerScaffoldHandler('vue', function (string $contents, string $contentType) {
return match ($contentType) {
'vite' => str_replace(
'}),',
<<<JAVASCRIPT
}),
vue({
template: {
transformAssetUrls: {
// The Vue plugin will re-write asset URLs, when referenced
// in Single File Components, to point to the Laravel web
// server. Setting this to `null` allows the Laravel plugin
// to instead re-write asset URLs to point to the Vite
// server instead.
base: null,
// The Vue plugin will parse absolute URLs and treat them
// as absolute paths to files on disk. Setting this to
// `false` will leave absolute URLs un-touched so they can
// reference assets in the public directory as expected.
includeAbsolute: false,
},
},
}),
JAVASCRIPT,
str_replace(
'import laravel from \'laravel-vite-plugin\';',
'import laravel from \'laravel-vite-plugin\';' . PHP_EOL . 'import vue from \'@vitejs/plugin-vue\';',
$contents
)
),
'mix' => str_replace(
'mix.js(\'assets/src/js/{{packageName}}.js\', \'assets/dist/js/{{packageName}}.js\');',
'mix.js(\'assets/src/js/{{packageName}}.js\', \'assets/dist/js/{{packageName}}.js\').vue({ version: 3 });',
$contents
),
'js' => $this->getFixture('js/vue.js.fixture'),
default => $contents
};
});
});
}

/**
* Returns a list of the registered asset bundles.
*/
public function listRegisteredBundles(): array
{
return $this->registeredBundles;
}

/**
* Get all bundles configured
*/
public function getBundles(): array
{
return array_keys($this->listRegisteredBundles());
}

/**
* Get the packages for a bundle, with compiler specific packages
*/
public function getBundlePackages(string $name, string $assetType): array
{
$config = $this->listRegisteredBundles()[$name] ?? [];

$packages = [];
foreach ($config as $key => $value) {
// Skip handlers
if (in_array($key, [static::HANDLER_SETUP, static::HANDLER_SCAFFOLD])) {
continue;
}

// Merge in any compiler specific packages for the current compiler
if (is_array($value)) {
if ($key === $assetType) {
$packages = array_merge($packages, $value);
}
continue;
}

$packages[$key] = $value;
}

return $packages;
}

/**
* Registers a callback function that defines asset bundles. The callback function
* should register bundles by calling the manager's registerBundles() function.
* This instance is passed to the callback function as an argument. Usage:
*
* BundleManager::registerCallback(function ($manager) {
* $manager->registerAssetBundles([...]);
* });
*
*/
public function registerCallback(callable $callback): static
{
$callback($this);

return $this;
}

/**
* Registers asset bundles.
*/
public function registerBundles(array $definitions): static
{
foreach ($definitions as $name => $definition) {
$this->registerBundle($name, $definition);
}

return $this;
}

/**
* Registers a single asset bundle.
*/
public function registerBundle(string $name, array $definition): static
{
$this->registeredBundles[$name] = $definition;

return $this;
}

/**
* Registers a single bundle setup handler.
*/
public function registerSetupHandler(string $name, Closure $closure): static
{
$this->registeredBundles[$name][static::HANDLER_SETUP] = $closure;

return $this;
}

/**
* Registers a single bundle scaffold handler.
*/
public function registerScaffoldHandler(string $name, Closure $closure): static
{
$this->registeredBundles[$name][static::HANDLER_SCAFFOLD] = $closure;

return $this;
}

/**
* Gets the setup handler for a bundle.
*/
public function getSetupHandler(string $name): ?Closure
{
return $this->listRegisteredBundles()[$name][static::HANDLER_SETUP] ?? null;
}

/**
* Gets the scaffold handler for a bundle.
*/
public function getScaffoldHandler(string $name): ?Closure
{
return $this->listRegisteredBundles()[$name][static::HANDLER_SCAFFOLD] ?? null;
}
}
Loading

0 comments on commit b5afa3b

Please sign in to comment.