Skip to content

Commit

Permalink
feat: added second argument support on @bagistoVite directive also
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Sep 6, 2023
1 parent 56211c8 commit 08e1a58
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 44 deletions.
8 changes: 2 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ APP_TIMEZONE=Asia/Kolkata
APP_LOCALE=en
APP_CURRENCY=USD

VITE_SHOP_HOST=
VITE_SHOP_PORT=
VITE_ADMIN_HOST=
VITE_ADMIN_PORT=

ASSET_URL=http://localhost
VITE_HOST=
VITE_PORT=

LOG_CHANNEL=stack

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"Webkul\\Sales\\": "packages/Webkul/Sales/src",
"Webkul\\Shipping\\": "packages/Webkul/Shipping/src",
"Webkul\\Shop\\": "packages/Webkul/Shop/src",
"Webkul\\ShopModule\\": "packages/Webkul/ShopModule/src",
"Webkul\\Sitemap\\": "packages/Webkul/Sitemap/src",
"Webkul\\SocialLogin\\": "packages/Webkul/SocialLogin/src",
"Webkul\\SocialShare\\": "packages/Webkul/SocialShare/src",
Expand Down
4 changes: 2 additions & 2 deletions packages/Webkul/Admin/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default defineConfig(({ mode }) => {
envDir,

server: {
host: process.env.VITE_ADMIN_HOST || "localhost",
port: process.env.VITE_ADMIN_PORT || 5173,
host: process.env.VITE_HOST || "localhost",
port: process.env.VITE_PORT || 5173,
},

plugins: [
Expand Down
4 changes: 2 additions & 2 deletions packages/Webkul/Shop/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default defineConfig(({ mode }) => {
envDir,

server: {
host: process.env.VITE_SHOP_HOST || "localhost",
port: process.env.VITE_SHOP_PORT || 5173,
host: process.env.VITE_HOST || "localhost",
port: process.env.VITE_PORT || 5173,
},

plugins: [
Expand Down
36 changes: 5 additions & 31 deletions packages/Webkul/Theme/src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Webkul\Theme;

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

class Theme
{
Expand Down Expand Up @@ -87,46 +86,21 @@ public function getViewPaths()
*
* @return string
*/
public function url(string $url, ?string $namespace)
public function url(string $url)
{
$url = trim($url, '/');
$viteUrl = trim($this->vite['package_assets_directory'], '/') . '/' . $url;

/**
* 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)) {
$viteUrl = trim($this->vite['package_assets_directory'], '/') . '/' . $url;

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);
}

$viteUrl = trim($viters[$namespace]['package_assets_directory'], '/') . '/' . $url;

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

/**
* Set bagisto vite.
*
* @param array $entryPoints
* @return \Illuminate\Foundation\Vite
*/
public function setBagistoVite($entryPoints)
public function setBagistoVite(array $entryPoints)
{
return Vite::useHotFile($this->vite['hot_file'])
->useBuildDirectory($this->vite['build_directory'])
Expand Down
52 changes: 49 additions & 3 deletions packages/Webkul/Theme/src/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Webkul\Theme;

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

class Themes
{
Expand Down Expand Up @@ -237,7 +239,31 @@ public function getLaravelViewPaths()
*/
public function url(string $filename, ?string $namespace)
{
return $this->current()->url($filename, $namespace);
$url = trim($filename, '/');

/**
* 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 $this->current()->url($url);
}

/**
* 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);
}

$viteUrl = trim($viters[$namespace]['package_assets_directory'], '/') . '/' . $url;

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

/**
Expand All @@ -246,8 +272,28 @@ public function url(string $filename, ?string $namespace)
* @param mixed $entryPoints
* @return mixed
*/
public function setBagistoVite($entryPoints)
public function setBagistoVite($entryPoints, ?string $namespace = null)
{
return $this->current()->setBagistoVite($entryPoints);
/**
* 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 $this->current()->setBagistoVite($entryPoints);
}

/**
* 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'])
->withEntryPoints($entryPoints);
}
}

0 comments on commit 08e1a58

Please sign in to comment.