Skip to content

Commit 9c70220

Browse files
committed
first commit 🔥
0 parents  commit 9c70220

File tree

32 files changed

+561
-0
lines changed

32 files changed

+561
-0
lines changed

‎.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [3x1io]

‎CHANGELOG.md

Whitespace-only changes.

‎LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Fady Mondy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

‎README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
![Screenshot](https://github.com/tomatophp/laravel-package-generator/blob/master/art/screenshot.png)
2+
3+
# Laravel Package Generator
4+
5+
Generate your Laravel package with ease.
6+
7+
## Installation
8+
9+
```bash
10+
composer require tomatophp/laravel-package-generator
11+
```
12+
13+
## Using
14+
15+
you can start build a new package inside your packages folder with this command
16+
17+
```php
18+
php artisan package:generate
19+
```
20+
21+
i will ask you about some information about your package
22+
23+
## Support
24+
25+
you can join our discord server to get support [TomatoPHP](https://discord.gg/Xqmt35Uh)
26+
27+
## Docs
28+
29+
you can check docs of this package on [Docs](https://docs.tomatophp.com/plugins/laravel-package-generator)
30+
31+
## Changelog
32+
33+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
34+
35+
## Credits
36+
37+
- [Fady Mondy](https://github.com/3x1io)
38+
39+
## License
40+
41+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

‎SECURITY.md

Whitespace-only changes.

‎art/screenshot.png

36.5 KB
Loading

‎composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "tomatophp/laravel-package-generator",
3+
"type": "library",
4+
"description": "Generate your Laravel package with ease.",
5+
"keywords": [
6+
"php",
7+
"laravel",
8+
"template"
9+
],
10+
"license": "MIT",
11+
"autoload": {
12+
"psr-4": {
13+
"TomatoPHP\\LaravelPackageGenerator\\": "src/"
14+
}
15+
},
16+
"autoload-dev": {
17+
"psr-4": {
18+
"Tests\\": "tests/"
19+
}
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"TomatoPHP\\LaravelPackageGenerator\\LaravelPackageGeneratorServiceProvider"
25+
]
26+
}
27+
},
28+
"authors": [
29+
{
30+
"name": "Fady Mondy",
31+
"email": "EngFadyMondy@gmail.com"
32+
}
33+
],
34+
"require": {
35+
"php": "^8.0.2",
36+
"tomatophp/console-helpers": "^1.0"
37+
}
38+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
"stub-path" => __DIR__ .'/../stubs/',
5+
"packages-folder" => "packages"
6+
];

‎publish/CHANGELOG.md

Whitespace-only changes.

‎publish/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Fady Mondy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

‎publish/SECURITY.md

Whitespace-only changes.

‎publish/config/.gitkeep

Whitespace-only changes.

‎publish/database/migrations/.gitkeep

Whitespace-only changes.

‎publish/resources/js/.gitkeep

Whitespace-only changes.

‎publish/resources/views/.gitkeep

Whitespace-only changes.

‎publish/routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+

‎publish/src/Console/.gitkeep

Whitespace-only changes.

‎publish/src/Http/Controllers/.gitkeep

Whitespace-only changes.

‎publish/src/Http/Middleware/.gitkeep

Whitespace-only changes.

‎publish/src/Http/Requests/.gitkeep

Whitespace-only changes.

‎publish/src/Models/.gitkeep

Whitespace-only changes.

‎publish/tests/Feature/.gitkeep

Whitespace-only changes.

‎publish/tests/Unit/.gitkeep

Whitespace-only changes.

‎src/Console/.gitkeep

Whitespace-only changes.
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
<?php
2+
3+
namespace TomatoPHP\LaravelPackageGenerator\Console;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Str;
8+
use TomatoPHP\ConsoleHelpers\Traits\HandleFiles;
9+
use TomatoPHP\ConsoleHelpers\Traits\HandleStub;
10+
use TomatoPHP\ConsoleHelpers\Traits\RunCommand;
11+
12+
class LaravelPackageGenerator extends Command
13+
{
14+
use RunCommand;
15+
use HandleFiles;
16+
use HandleStub;
17+
18+
private string $stubPath;
19+
20+
/**
21+
* The name and signature of the console command.
22+
*
23+
* @var string
24+
*/
25+
protected $name = 'package:generate';
26+
27+
/**
28+
* The console command description.
29+
*
30+
* @var string
31+
*/
32+
protected $description = 'use this command to generate package boilerplate';
33+
34+
public function __construct()
35+
{
36+
parent::__construct();
37+
$this->publish = __DIR__ .'/../../publish/';
38+
$this->stubPath = config('laravel-package-generator.stub-path');
39+
}
40+
41+
42+
/**
43+
* Execute the console command.
44+
*
45+
* @return mixed
46+
*/
47+
public function handle()
48+
{
49+
$packageName = null;
50+
while(empty($packageName)){
51+
$packageName = $this->ask("Enter your package name");
52+
if(is_numeric($packageName[0])){
53+
$this->error("Package name can't start with a number");
54+
$packageName = null;
55+
}
56+
}
57+
$packageString = Str::of($packageName);
58+
59+
$packageVendor = null;
60+
while(empty($packageVendor)){
61+
$packageVendor = $this->ask("Enter your package vendor name");
62+
if(is_numeric($packageVendor[0])){
63+
$this->error("Vendor name can't start with a number");
64+
$packageVendor = null;
65+
}
66+
}
67+
68+
$packageVendorString = Str::of($packageVendor);
69+
70+
//Package Meta
71+
$packageDescription = $this->ask("Enter your package description", "your package description will go here");
72+
$packageAuthor = $this->ask("Enter your package author", "Queen Tech");
73+
$packageAuthorEmail = $this->ask("Enter your package author email", "git@queentechsoltions.net");
74+
75+
//Check Options
76+
$packageConfig = $this->ask("Has Config file? (yes/no)", "yes")?: "yes";
77+
$packageRoute = $this->ask("Has Routes? (yes/no)", "yes")?: "yes";
78+
$packageView = $this->ask("Has Views? (yes/no)", "yes")?: "yes";
79+
$packageMigration = $this->ask("Has Migrations? (yes/no)", "yes")?: "yes";
80+
81+
$this->info('Generating package boilerplate...');
82+
83+
//create package directory
84+
if(!File::exists(base_path(config('laravel-package-generator.packages-folder')))){
85+
File::makeDirectory(base_path(config('laravel-package-generator.packages-folder')));
86+
}
87+
88+
$packageVendorPath = $packageVendorString
89+
->replace(' ', '-')
90+
->replace('_', '-')
91+
->lower()
92+
->toString();
93+
94+
//Create vendor directory
95+
if(!File::exists(base_path(config('laravel-package-generator.packages-folder')) . "/" .$packageVendorPath)){
96+
File::makeDirectory(base_path(config('laravel-package-generator.packages-folder')) . "/" .$packageVendorPath);
97+
}
98+
99+
$packageNamePath = $packageString
100+
->replace(' ', '-')
101+
->replace('_', '-')
102+
->lower()
103+
->toString();
104+
105+
//Create package directory
106+
if(!File::exists(base_path(config('laravel-package-generator.packages-folder')) . "/" .$packageVendor . "/" . $packageNamePath)){
107+
File::makeDirectory(base_path(config('laravel-package-generator.packages-folder')) . "/" .$packageVendor . "/" . $packageNamePath);
108+
}
109+
110+
$packagePath = base_path(config('laravel-package-generator.packages-folder')) . "/" .$packageVendorPath . "/" . $packageNamePath;
111+
112+
//Build a package inside vendor directory
113+
$packageConfig !== 'yes' ? null : $this->handelFile('config', $packagePath. "/config", 'folder');
114+
$packageMigration !== 'yes' ? null : $this->handelFile('database', $packagePath. "/database", 'folder');
115+
$packageView !== 'yes' ? null : $this->handelFile('resources', $packagePath. "/resources", 'folder');
116+
$packageRoute !== 'yes' ? null : $this->handelFile('routes', $packagePath. "/routes", 'folder');
117+
$this->handelFile('src', $packagePath. "/src", 'folder');
118+
$this->handelFile('tests', $packagePath. "/tests", 'folder');
119+
$this->handelFile('LICENSE.md', $packagePath. "/LICENSE.md");
120+
$this->handelFile('CHANGELOG.md', $packagePath. "/CHANGELOG.md");
121+
$this->handelFile('SECURITY.md', $packagePath. "/SECURITY.md");
122+
123+
124+
$vendorNamespace = Str::of($packageVendorPath)->camel()->ucfirst()->toString();
125+
$packageNamespace = Str::of($packageNamePath)->camel()->ucfirst()->toString();
126+
$packageProviderName = Str::of($packageNamePath)->camel()->ucfirst()->toString() . "ServiceProvider";
127+
$fullNameSpace = $vendorNamespace . "\\". $packageNamespace;
128+
129+
//Build Stubs Files
130+
$commandClassName = $packageString->studly()->append('Install')->toString();
131+
$this->generateStubs(
132+
$this->stubPath . 'command.stub',
133+
$packagePath . '/src/Console/'. $commandClassName . ".php",
134+
[
135+
"namespace" => $fullNameSpace,
136+
"name" => $commandClassName,
137+
"command" => $packageNamePath,
138+
"packageName" => Str::of($packageNamePath)->camel()->toString(),
139+
"provider" => $packageProviderName
140+
],
141+
[
142+
$packagePath . '/src/Console/'
143+
]
144+
);
145+
146+
//Build Provider Register Methods
147+
$register = collect([]);
148+
$register->push('//Register generate command');
149+
$register->push(' $this->commands([');
150+
$register->push(' '."\\".$fullNameSpace."\\Console\\".$commandClassName.'::class,');
151+
$register->push(' ]);');
152+
$register->push(" ");
153+
if($packageConfig === 'yes'){
154+
$register->push(' //Register Config file');
155+
$register->push(' $this->mergeConfigFrom(__DIR__.\'/../config/'.$packageNamePath.'.php\', \''.$packageNamePath.'\');');
156+
$register->push(" ");
157+
$register->push(' //Publish Config');
158+
$register->push(' $this->publishes([');
159+
$register->push(' __DIR__.\'/../config/'.$packageNamePath.'.php\' => config_path(\''.$packageNamePath.'.php\'),');
160+
$register->push(' ], \'config\');');
161+
$register->push(" ");
162+
}
163+
if($packageMigration === 'yes'){
164+
$register->push(' //Register Migrations');
165+
$register->push(' $this->loadMigrationsFrom(__DIR__.\'/../database/migrations\');');
166+
$register->push(" ");
167+
$register->push(' //Publish Migrations');
168+
$register->push(' $this->publishes([');
169+
$register->push(' __DIR__.\'/../database/migrations\' => database_path(\'migrations\'),');
170+
$register->push(' ], \'migrations\');');
171+
}
172+
if($packageView === 'yes'){
173+
$register->push(' //Register views');
174+
$register->push(' $this->loadViewsFrom(__DIR__.\'/../resources/views\', \''.$packageNamePath.'\');');
175+
$register->push(" ");
176+
$register->push(' //Publish Views');
177+
$register->push(' $this->publishes([');
178+
$register->push(' __DIR__.\'/../resources/views\' => resource_path(\'views/vendor/'.$packageNamePath.'\'),');
179+
$register->push(' ], \'views\');');
180+
$register->push(" ");
181+
$register->push(' //Register Langs');
182+
$register->push(' $this->loadTranslationsFrom(__DIR__.\'/../resources/lang\', \''.$packageNamePath.'\');');
183+
$register->push(" ");
184+
$register->push(' //Publish Lang');
185+
$register->push(' $this->publishes([');
186+
$register->push(' __DIR__.\'/../resources/lang\' => resource_path(\'lang/vendor/'.$packageNamePath.'\'),');
187+
$register->push(' ], \'lang\');');
188+
$register->push(" ");
189+
}
190+
if($packageRoute === 'yes') {
191+
$register->push(' //Register Routes');
192+
$register->push(' $this->loadRoutesFrom(__DIR__.\'/../routes/web.php\');');
193+
$register->push(" ");
194+
}
195+
196+
//Generate Provider File
197+
$this->generateStubs(
198+
$this->stubPath . 'provider.stub',
199+
$packagePath . '/src/'. $packageProviderName . ".php",
200+
[
201+
"namespace" => $fullNameSpace,
202+
"name" => $packageProviderName,
203+
"register" => $register->implode("\n")
204+
],
205+
[
206+
$packagePath . '/src'
207+
]
208+
);
209+
210+
//Generate Composer.json file
211+
$this->generateStubs(
212+
$this->stubPath . 'composer.stub',
213+
$packagePath . '/composer.json',
214+
[
215+
"vendor" => $packageVendorPath,
216+
"package" => $packageNamePath,
217+
"description" => $packageDescription,
218+
"namespace" => $vendorNamespace ."\\\\". $packageNamespace,
219+
"provider" => $packageProviderName,
220+
"author" => $packageAuthor,
221+
"email" => $packageAuthorEmail,
222+
],
223+
[
224+
$packagePath
225+
]
226+
);
227+
228+
//Generate Readme.md file
229+
$this->generateStubs(
230+
$this->stubPath . 'readme.stub',
231+
$packagePath . '/README.md',
232+
[
233+
"name" => Str::of($packageNamePath)->replace('-', ' ')->ucfirst()->toString(),
234+
"vendor" => $packageVendorPath,
235+
"command" => $packageNamePath,
236+
"package" => $packageNamePath,
237+
"description" => $packageDescription,
238+
"author" => $packageAuthor,
239+
"email" => $packageAuthorEmail,
240+
"vendorName" => $vendorNamespace
241+
],
242+
[
243+
$packagePath
244+
]
245+
);
246+
247+
248+
249+
250+
$this->info('Package boilerplate generated successfully');
251+
}
252+
}

0 commit comments

Comments
 (0)