Skip to content

Commit

Permalink
Merge pull request #23 from amit-webkul/2.0
Browse files Browse the repository at this point in the history
Feat: Reafctor the code.
  • Loading branch information
jitendra-webkul authored Feb 14, 2024
2 parents 73173cf + 27658d9 commit 84a0fe9
Show file tree
Hide file tree
Showing 69 changed files with 701 additions and 614 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG for v2.x.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CHANGELOG for v2.0.x

This changelog consists the bug & security fixes and new features being included in the releases listed below.

## **v2.0.0(07th of February, 2024)** - _Release_

### Features:

**Vite Config file creation command**

- Create vite config file with a single command.

**Tailwind Config file creation command**

- Create tailwind config file with a single command.

**Post Css Config file creation command**

- Create post css file with a single command.
74 changes: 63 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It packs in lots of demanding features that allows your business to scale in no

## 2. Requirements

* **Bagisto**: v1.1.2 or higher.
* **Bagisto**: v2.0 or higher.

## 3. Installation

Expand Down Expand Up @@ -59,8 +59,10 @@ Below are the list of commands,
| 25. | package:make-payment-method-provider | [Create a new payment method service provider class.](#25-create-a-new-payment-method-service-provider-class) | provider-name, payment-package-name | --force |
| 26. | package:make-shipping-method | [Create a new shipping method package.](#26-create-a-new-shipping-method-package) | shipment-package-name | --force |
| 27. | package:make-shipping-method-provider | [Create a new shipping method service provider class.](#27-create-a-new-shipping-method-service-provider-class) | provider-name, shipment-package-name | --force |
| 28. | create-a-new-theme-for-shop | [Create a new theme for shop.](#28-create-a-new-theme-for-shop) | theme-name | --force |
| 29. | create-a-new-theme-for-admin | [Create a new theme for admin.](#29-create-a-new-theme-for-admin) | theme-name | --force |
| 28. | package:make-vite-config | [Create a new vite config file.](#8-create-a-new-vite-config-file) | package-name | --force |
| 29. | package:make-tailwind-config | [Create a new tailwind config file.](#8-create-a-new-tailwind-config-file) | package-name | --force |
| 30. | package:make-postcss-config | [Create a new post css config file.](#8-create-a-new-post-css-config-file) | package-name | --force |
| 31. | create-a-new-theme-for-admin | [Create a new theme for admin.](#32-create-a-new-theme-for-admin) | theme-name | --force |


**--force** : To overwrite the files
Expand Down Expand Up @@ -451,7 +453,57 @@ If module service provider class already present then you can use force command
php artisan package:make-module-provider TestServiceProvider ACME/TestPackage --force
~~~

#### 24. Create a new payment method package
#### 24. Create a new vite config file.

This command will create a new vite config file in '**packages/ACME/TestPackage**' directory.

~~~php
php artisan package:make-vite-config vite.config ACME/TestPackage
~~~

##### This command will create a new vite config file with force command

If vite config file already present then you can use force command for overwriting.

~~~php
php artisan package:make-vite-config vite.config ACME/TestPackage --force
~~~

#### 25. Create a new tailwind config file.

This command will create a new tailwind config file in '**packages/ACME/TestPackage**' directory.

~~~php
php artisan package:make-tailwind-config tailwind.config ACME/TestPackage
~~~

##### This command will create a new tailwind config file with force command

If tailwind config file already present then you can use force command for overwriting.

~~~php
php artisan package:make-tailwind-config tailwind.config ACME/TestPackage --force
~~~

#### 26. Create a new post css config file.

This command will create a new post css config file in '**packages/ACME/TestPackage**' directory.

~~~php
php artisan package:make-postcss-config postcss.config ACME/TestPackage
~~~

##### This command will create a new postcss config file with force command

If postcss config file already present then you can use force command for overwriting.

~~~php
php artisan package:make-postcss-config tailwind.config ACME/TestPackage --force
~~~



#### 27. Create a new payment method package

This command will create a whole new payment package for you in '**packages/ACME/Stripe**' directory.

Expand All @@ -467,7 +519,7 @@ This command will overwrite whole directory structure.
php artisan package:make-payment-method ACME/Stripe --force
~~~

#### 25. Create a new payment method service provider class
#### 28. Create a new payment method service provider class

This command will create a new payment method service provider class in '**packages/ACME/Stripe/src/Providers**' directory.

Expand All @@ -483,7 +535,7 @@ If payment method service provider class already present then you can use force
php artisan package:make-payment-method-provider TestPaymentMethodServiceProvider ACME/Stripe --force
~~~

#### 26. Create a new shipping method package
#### 29. Create a new shipping method package

This command will create a whole new shipment package in '**packages/ACME/FedEx**' directory.

Expand All @@ -499,7 +551,7 @@ This command will override whole directory structure.
php artisan package:make-shipping-method ACME/FedEx --force
~~~

#### 27. Create a new shipping method service provider class
#### 30. Create a new shipping method service provider class

This command will create a new shipping method service provider class '**packages/ACME/FedEx/src/Providers**' directory.

Expand All @@ -515,17 +567,17 @@ If shipping method service provider class already present then you can use force
php artisan package:make-shipping-method-provider TestShippingMethodServiceProvider ACME/FedEx --force
~~~

#### 28. Create a new theme for shop
#### 31. Create a new theme for shop

This command will create a new theme array inside '**config/themes.php**' file under **themes** key.
This command will create a new theme array inside '**config/themes.php**' file under **shop** key.

~~~php
php artisan package:make-shop-theme test ACME/Theme --force
~~~

#### 29. Create a new theme for admin
#### 32. Create a new theme for admin

This command will create a new theme array inside '**config/themes.php**' file under **admin-themes** key.
This command will create a new theme array inside '**config/themes.php**' file under **admin** key.

~~~php
php artisan package:make-admin-theme test ACME/Theme --force
Expand Down
13 changes: 5 additions & 8 deletions src/Console/Command/AdminControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Webkul\PackageGenerator\Console\Command;

use Webkul\PackageGenerator\Generators\PackageGenerator;

class AdminControllerMakeCommand extends MakeCommand
{
/**
Expand Down Expand Up @@ -34,8 +32,9 @@ protected function getStubContents()
protected function getStubVariables()
{
return [
'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Http/Controllers/Admin'),
'CLASS' => $this->getClassName(),
'NAMESPACE' => $this->getClassNamespace($this->argument('package') . '/Http/Controllers/Admin'),
'CLASS' => $this->getClassName(),
'LOWER_NAME' => $this->getLowerName(),
];
}

Expand All @@ -44,8 +43,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Http/Controllers/Admin';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Http/Controllers/Admin' . '/' . $this->getClassName() . '.php';
}
}
}
10 changes: 3 additions & 7 deletions src/Console/Command/AdminRouteMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Webkul\PackageGenerator\Console\Command;

use Illuminate\Support\Str;
use Webkul\PackageGenerator\Generators\PackageGenerator;

class AdminRouteMakeCommand extends MakeCommand
{
/**
Expand Down Expand Up @@ -36,6 +33,7 @@ protected function getStubVariables()
{
return [
'CONTROLLER_CLASS_NAME' => $this->getClassNamespace($this->argument('package') . '/Http/Controllers/Admin/' . $this->getStudlyName() . 'Controller'),
'CLASS' => $this->getClassControllerName(),
'LOWER_NAME' => $this->getLowerName(),
];
}
Expand All @@ -45,8 +43,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Http';

return $path . '/admin-routes.php';
return base_path('packages/' . $this->argument('package')) . '/src/Routes' . '/admin-routes.php';
}
}
}
52 changes: 33 additions & 19 deletions src/Console/Command/AdminThemeMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Webkul\PackageGenerator\Console\Command;

use Illuminate\Support\Str;
use Webkul\PackageGenerator\Generators\PackageGenerator;

class AdminThemeMakeCommand extends MakeCommand
{
/**
Expand All @@ -22,6 +19,8 @@ class AdminThemeMakeCommand extends MakeCommand
protected $description = 'Create a new theme for admin.';

/**
* Returns stub file content.
*
* @return mixed
*/
protected function getStubContents()
Expand All @@ -32,50 +31,65 @@ protected function getStubContents()

$themeKey = $this->argument('key');

$themeContent['admin-themes'][$themeKey] = [
'views_path' => "resources/admin-themes/$themeKey/views",
'assets_path' => "public/admin-themes/$themeKey/assets",
$themeContent['admin'][$themeKey] = [
'name' => ucfirst($this->argument('key')),
'assets_path' => "public/themes/admin/$themeKey",
'views_path' => "resources/themes/admin/$themeKey/views",

'vite' => [
'hot_file' => "admin-$themeKey-vite.hot",
'build_directory' => "themes/admin/$themeKey/build",
'package_assets_directory' => 'src/Resources/assets',
],
];

$themeContent = $this->varexport($themeContent);

$this->createMaster($themeKey);

return "<?php\n \nreturn {$themeContent};\n?>";
return "<?php\n \nreturn {$themeContent};";
}

/**
* Returns source file path.
*
* @return string
*/
protected function getSourceFilePath()
{
$path = base_path('config/');

return $path . 'themes.php';
return base_path('config/') . 'themes.php';
}

public function varexport($expression)
{
$export = var_export($expression, TRUE);
$export = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $export);
$export = var_export($expression, true);

$export = preg_replace('/^([ ]*)(.*)/m', '$1$1$2', $export);

$array = preg_split("/\r\n|\n|\r/", $export);
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);
$export = join(PHP_EOL, array_filter(["["] + $array));

$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [null, ']$1', ' => ['], $array);

$export = implode(PHP_EOL, array_filter(['['] + $array));

return print_r($export, true);
}

public function createMaster($themeKey)
/**
* Created Master file inside the resource path.
*
* @return void
*/
public function createMaster(string $themeKey)
{
$layoutsPath = base_path('resources/admin-themes/' . $themeKey . '/views/layouts');
$layoutsPath = base_path('resources/themes/admin/' . $themeKey . '/views/dashboard');

if (! $this->filesystem->isDirectory($dir = $layoutsPath)) {
$this->filesystem->makeDirectory($dir, 0775, true);
}

$this->filesystem->put($layoutsPath . '/master.blade.php', $this->packageGenerator->getStubContents("theme-master", [
"THEME_KEY" => ucfirst($themeKey)
$this->filesystem->put($layoutsPath . '/index.blade.php', $this->packageGenerator->getStubContents('theme-master', [
'THEME_KEY' => ucfirst($themeKey),
]));
}
}
}
6 changes: 2 additions & 4 deletions src/Console/Command/CommandMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Console/Commands';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Console/Commands' . '/' . $this->getClassName() . '.php';
}
}
}
6 changes: 2 additions & 4 deletions src/Console/Command/DatagridMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Datagrids';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Datagrids' . '/' . $this->getClassName() . '.php';
}
}
}
6 changes: 2 additions & 4 deletions src/Console/Command/EventMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Events';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Events' . '/' . $this->getClassName() . '.php';
}
}
}
6 changes: 2 additions & 4 deletions src/Console/Command/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Listeners';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Listeners' . '/' . $this->getClassName() . '.php';
}
}
}
6 changes: 2 additions & 4 deletions src/Console/Command/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function getStubVariables()
*/
protected function getSourceFilePath()
{
$path = base_path('packages/' . $this->argument('package')) . '/src/Mail';

return $path . '/' . $this->getClassName() . '.php';
return base_path('packages/' . $this->argument('package')) . '/src/Mail' . '/' . $this->getClassName() . '.php';
}
}
}
Loading

0 comments on commit 84a0fe9

Please sign in to comment.