-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0648100
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# HeroIcons Generator | ||
|
||
![Packagist Version (custom server)](https://img.shields.io/packagist/v/yemenopensource/hero-icons) | ||
|
||
HeroIcons is a Laravel package that provides a convenient command for generating hero icons as constants on a PHP class. This package is designed to simplify the process of working with hero icons in your Laravel projects. | ||
|
||
## Installation | ||
|
||
You can install the package via Composer: | ||
|
||
```bash | ||
composer require yemenopensource/hero-icons | ||
``` | ||
|
||
## Usage | ||
|
||
To generate the hero icons class, simply run the following command: | ||
|
||
```bash | ||
php artisan generate:hero-icons | ||
``` | ||
|
||
The command will scan the SVG files in the specified directory and generate a PHP class with constants representing each icon. The generated PHP class will be saved in the app/Utilities folder of your Laravel project. | ||
|
||
## Configuration | ||
|
||
|
||
The package provides a configuration file that allows you to customize its behavior. | ||
|
||
You can publish the configuration file by using the following command: | ||
|
||
```bash | ||
php artisan vendor:publish --provider="YOS\HeroIcons\ServiceProvider" --tag="config" | ||
``` | ||
|
||
After publishing the configuration file, you can find it at config/heroicons.php. Open this file and modify it according to your requirements. | ||
|
||
In the configuration file, you can modify the following settings: | ||
|
||
- `blade-ui-kit-path`: The vendor path of the Blade UI Kit package where the SVG files exist. | ||
- `namespace`: The namespace and directory path of the output of the generated class. | ||
- `class`: The output class name. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to create an issue or a pull request. | ||
|
||
## License | ||
|
||
The package is part of yemen open source and it is licensed under the MIT license. | ||
|
||
## Credits | ||
|
||
- [Muath Alsowadi](https://github.com/muath-ye) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "yemenopensource/hero-icons", | ||
"description": "Enjoy realtime input validation by passing your rules in your input itself.", | ||
"type": "library", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"autoload": { | ||
"psr-4": { | ||
"YOS\\HeroIcons\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Muath Alsowadi", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": "^7.4|^8.0|^8.1|^8.2", | ||
"illuminate/support": "^7.0|^8.0|^9.0|^10.0" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"YOS\\HeroIcons\\ServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace YOS\HeroIcons\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class GenerateHeroIconsClass extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'generate:hero-icons'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generate hero icons as constance on a PHP class'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
// <?php | ||
|
||
// Namespace where the output is located | ||
$namespace = config('heroicons.namespace'); | ||
|
||
// The name of output class | ||
$class = config('heroicons.class'); | ||
|
||
// Directory path where the SVG files are located | ||
$directory = config('heroicons.blade-ui-kit-path'); | ||
|
||
$this->line('Scanning: ' . $directory); | ||
|
||
// Get the file names from the directory | ||
$files = scandir($directory); | ||
|
||
// Initialize an array to store the constant names | ||
$constants = array(); | ||
|
||
// Iterate over the files | ||
foreach ($files as $file) { | ||
// Exclude directories and non-SVG files | ||
if (!is_dir($file) && pathinfo($file, PATHINFO_EXTENSION) === 'svg') { | ||
// Remove the file extension and convert to capitalized constant name | ||
$constantName = strtoupper(pathinfo($file, PATHINFO_FILENAME)); | ||
$constantName = str_replace('-', '_', $constantName); | ||
|
||
// Add the constant name to the array | ||
$constants[] = [ | ||
'key' => $constantName, | ||
'value' => pathinfo($file, PATHINFO_FILENAME), | ||
'file' => $file, | ||
]; | ||
} | ||
} | ||
|
||
// Generate the PHP class code | ||
$classCode = "<?php\n\n"; | ||
$classCode .= "namespace App\\".$namespace.";\n\n"; | ||
$classCode .= "/**\n"; | ||
$classCode .= " * This class is auto generated by 'php artisan generate:hero-icons'\n"; | ||
$classCode .= " * based on [blade ui kit heroicons]. don't modify it.\n"; | ||
$classCode .= " * See https://heroicons.com/ for more.\n"; | ||
$classCode .= " */\n"; | ||
$classCode .= "class $class\n"; | ||
$classCode .= "{\n"; | ||
foreach ($constants as $constant) { | ||
$key = $constant['key']; | ||
$value = $constant['value']; | ||
$file = $constant['file']; | ||
$classCode .= " /**\n"; | ||
$classCode .= " * @var string $file\n"; | ||
$classCode .= " */\n"; | ||
$classCode .= " const $key = 'heroicon-$value';\n\n"; | ||
// $classCode .= " const $key = 'heroicon-$value'; // $file \n"; | ||
} | ||
$classCode .= "}\n"; | ||
|
||
// Output folder path | ||
$outputFolder = 'app/'.$namespace.'/'; | ||
|
||
// Create the output folder if it doesn't exist | ||
if (!is_dir($outputFolder)) { | ||
mkdir($outputFolder, 0777, true); | ||
} | ||
|
||
// Save the PHP class code to a file | ||
$outputFile = $outputFolder . $class . '.php'; | ||
|
||
file_put_contents($outputFile, $classCode); | ||
|
||
$this->info("PHP class generated and saved to $outputFile"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace YOS\HeroIcons; | ||
|
||
use Illuminate\Foundation\Console\AboutCommand; | ||
use Illuminate\Support\Facades\Blade; | ||
use Illuminate\Support\ServiceProvider as SupportServiceProvider; | ||
use YOS\HeroIcons\Console\Commands\GenerateHeroIconsClass; | ||
|
||
class ServiceProvider extends SupportServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__.'/config/config.php', 'heroicons'); | ||
} | ||
|
||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
AboutCommand::add('HeroIcons List Generator', fn () => ['Version' => '1.0.0']); | ||
|
||
if ($this->app->runningInConsole()) { | ||
$this->commands([ | ||
GenerateHeroIconsClass::class, | ||
]); | ||
|
||
$this->publishes([ | ||
__DIR__.'/config/config.php' => config_path('heroicons.php'), | ||
], 'config'); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Vendor Path | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The vendor path of blade ui kit package where the svg files exist. | ||
| | ||
*/ | ||
|
||
'blade-ui-kit-path' => __DIR__ . '/../vendor/blade-ui-kit/blade-heroicons/resources/svg', | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Namespace | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The namespace and directory path of the output of the generated class. | ||
| | ||
*/ | ||
|
||
'namespace' => 'Utilities', | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Class | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The output class name | ||
| | ||
*/ | ||
|
||
'class' => 'HeroIcons', | ||
|
||
]; |