Skip to content

Commit

Permalink
fix: fixed vite multi module support and enhanced version of all pack…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
devansh-webkul committed Sep 1, 2023
1 parent e93acaa commit 1dce243
Show file tree
Hide file tree
Showing 31 changed files with 118 additions and 40 deletions.
24 changes: 24 additions & 0 deletions config/bagisto-vite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Bagisto Vite Configuration
|--------------------------------------------------------------------------
|
| Please add your Vite registry here to seamlessly support the `bagisto_assets` function.
|
*/

'viters' => [
'admin' => [
'hot_file' => 'admin-default-vite.hot',
'build_directory' => 'themes/admin/default/build',
],

'shop' => [
'hot_file' => 'shop-default-vite.hot',
'build_directory' => 'themes/shop/default/build',
],
],
];
18 changes: 18 additions & 0 deletions config/themes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Shop Theme Configuration
|--------------------------------------------------------------------------
|
| All the configurations are related to the shop themes.
|
*/

'default' => 'default',

'themes' => [
Expand All @@ -16,6 +25,15 @@
],
],

/*
|--------------------------------------------------------------------------
| Admin Theme Configuration
|--------------------------------------------------------------------------
|
| All the configurations are related to the admin themes.
|
*/

'admin-default' => 'default',

'admin-themes' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public function __construct(protected DashboardService $dashboardService)
*/
public function index()
{
// $customer = \Webkul\Customer\Models\Customer::find(1);

// return view('shop::emails.customers.registration', compact('customer'));

if (request()->ajax()) {
$statistics = $this->dashboardService
->setStartDate(request()->date('start'))
Expand All @@ -30,8 +26,8 @@ public function index()

return response()->json([
'statistics' => $statistics,
'startDate' => $this->dashboardService->getStartDate()->format('d M'),
'endDate' => $this->dashboardService->getEndDate()->format('d M'),
'startDate' => $this->dashboardService->getStartDate()->format('d M'),
'endDate' => $this->dashboardService->getEndDate()->format('d M'),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Admin',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Attribute/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Attributes',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/CMS/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto CMS',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/CartRule/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Cart Rule',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/CatalogRule/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Catalog Rule',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Category/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Categories',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Checkout/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Checkout',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Core/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Core',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Customer/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Customer',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Inventory/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Inventory',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Marketing/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Marketing',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Payment/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Payment',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Paypal/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Paypal',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Product/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Product',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Rule/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Rule',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Sales/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Sales',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Shipping/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Shipping',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Shop/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Shop',
'version' => '0.0.1',
'version' => core()->version(),
];
6 changes: 6 additions & 0 deletions packages/Webkul/Sitemap/src/Resources/manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'name' => 'Webkul Bagisto Sitemap',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/SocialLogin/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Social Login',
'version' => '0.0.1',
'version' => core()->version(),
];
2 changes: 1 addition & 1 deletion packages/Webkul/Tax/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Tax',
'version' => '0.0.1',
'version' => core()->version(),
];
17 changes: 17 additions & 0 deletions packages/Webkul/Theme/src/Exceptions/ViterNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Webkul\Theme\Exceptions;

class ViterNotFound extends \Exception
{
/**
* Create an instance.
*
* @param string $theme
* @return void
*/
public function __construct($namespace)
{
parent::__construct("Viter with `$namespace` namespace not found. Please add `$namespace` namespace in the `config/bagisto-vite.php` file.", 1);
}
}
6 changes: 2 additions & 4 deletions packages/Webkul/Theme/src/Http/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ function themes()
/**
* Bagisto asset.
*
* @param string $path
* @param string $secure
* @return string
*/
function bagisto_asset($path, $secure = null)
function bagisto_asset(string $path, ?string $namespace = null)
{
return themes()->url($path, $secure);
return themes()->url($path, $namespace);
}
}

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/Webkul/Theme/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto Theme',
'version' => '0.0.1',
'version' => core()->version(),
];
28 changes: 24 additions & 4 deletions packages/Webkul/Theme/src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Webkul\Theme;

use Illuminate\Support\Facades\Vite;
use Webkul\Theme\Exceptions\ViterNotFound;

class Theme
{
Expand Down Expand Up @@ -84,10 +85,9 @@ public function getViewPaths()
/**
* Convert to asset url based on current theme.
*
* @param string $url
* @return string
*/
public function url($url)
public function url(string $url, ?string $namespace)
{
$url = trim($url, '/');

Expand All @@ -96,8 +96,28 @@ public function url($url)
*/
$viteUrl = 'src/Resources/assets/' . $url;

return Vite::useHotFile($this->vite['hot_file'])
->useBuildDirectory($this->vite['build_directory'])
/**
* If the namespace is null, it means the theming system is activated. We use the request URI to
* detect the theme and provide Vite assets based on the current theme.
*/
if (empty($namespace)) {
return Vite::useHotFile($this->vite['hot_file'])
->useBuildDirectory($this->vite['build_directory'])
->asset($viteUrl);
}

/**
* If a namespace is provided, it means the developer knows what they are doing and must create the
* registry in the provided configuration. We will analyze based on that.
*/
$viters = config('bagisto-vite.viters');

if (empty($viters[$namespace])) {
throw new ViterNotFound($namespace);
}

return Vite::useHotFile($viters[$namespace]['hot_file'])
->useBuildDirectory($viters[$namespace]['build_directory'])
->asset($viteUrl);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/Webkul/Theme/src/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ public function getLaravelViewPaths()
}

/**
* Return asset url of current theme.
* Return the asset URL of the current theme if a theme is found; otherwise, check from the namespace.
*
* @param string $themeName
* @return string
*/
public function url($filename)
public function url(string $filename, ?string $namespace)
{
return $this->current()->url($filename);
return $this->current()->url($filename, $namespace);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/User/src/Resources/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

return [
'name' => 'Webkul Bagisto User',
'version' => '0.0.1',
'version' => core()->version(),
];

0 comments on commit 1dce243

Please sign in to comment.