Skip to content

Commit c28c7e9

Browse files
authored
Merge pull request #29 from webfactor/issue-26
Open files in IDE
2 parents 11ad653 + 0146012 commit c28c7e9

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,22 @@ With `{--git}` option all generated files will be added to git automatically. In
215215

216216
## Open files in IDE
217217

218-
With `{--ide=}` option you can define your preferred IDE to open all automatically generated files. The keys in the `ides`-Array of the config file are possible values for the command option. You can add other IDE-Opener classes, they have to implement `Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface`. This package comes with implementations for PhpStorm (`pstorm`), Sublime (`sublime`) and VS Code (`vscode`).
218+
If specified we will automatically open all generated files in the IDE of your choice.
219+
There are three options to use this feature (applied in this order):
220+
* `{--ide=}` command option
221+
* __.env__ variable `APP_EDITOR`
222+
* config value `config('app.editor')`
223+
224+
The keys in the `ides`-Array of the config file are possible values for the command option.
225+
Per default we provide:
226+
* `phpstorm`: will open all files with `pstorm` CLI helper of PhpStorm
227+
* `pstorm`: will open all files with `pstorm` CLI helper of PhpStorm
228+
* `sublime`: will open all files with `subl` CLI helper of Sublime
229+
* `subl`: will open all files with `subl` CLI helper of Sublime
230+
* `vscode`: will open all files with `code` CLI helper of VSCode
231+
* `code`: will open all files with `code` CLI helper of VSCode
232+
233+
You can add other IDE-Opener classes. They have to implement `Webfactor\Laravel\Generators\Contracts\OpenInIdeInterface`.
219234

220235
In your service class you have to add the generated file to a stack (see "Add files to git" section)
221236

config/generators.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,31 @@
2222
* is used. Have to implement Webfactor\Laravel\Generators\Contracts\OpenIdeInterface.
2323
*/
2424
'ides' => [
25-
'pstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class,
26-
'sublime' => Webfactor\Laravel\Generators\Recipes\SublimeOpener::class,
27-
'vscode' => Webfactor\Laravel\Generators\Recipes\VSCodeOpener::class,
25+
'phpstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class,
26+
'pstorm' => Webfactor\Laravel\Generators\Recipes\PhpStormOpener::class,
27+
'sublime' => Webfactor\Laravel\Generators\Recipes\SublimeOpener::class,
28+
'subl' => Webfactor\Laravel\Generators\Recipes\SublimeOpener::class,
29+
'vscode' => Webfactor\Laravel\Generators\Recipes\VSCodeOpener::class,
30+
'code' => Webfactor\Laravel\Generators\Recipes\VSCodeOpener::class,
2831
],
2932

3033
'naming' => [
31-
'migration' => Webfactor\Laravel\Generators\Schemas\Naming\Migration::class,
32-
'languageFile' => Webfactor\Laravel\Generators\Schemas\Naming\LanguageFile::class,
33-
'crudModel' => Webfactor\Laravel\Generators\Schemas\Naming\CrudModel::class,
34-
'crudRequest' => Webfactor\Laravel\Generators\Schemas\Naming\CrudRequest::class,
34+
'migration' => Webfactor\Laravel\Generators\Schemas\Naming\Migration::class,
35+
'languageFile' => Webfactor\Laravel\Generators\Schemas\Naming\LanguageFile::class,
36+
'crudModel' => Webfactor\Laravel\Generators\Schemas\Naming\CrudModel::class,
37+
'crudRequest' => Webfactor\Laravel\Generators\Schemas\Naming\CrudRequest::class,
3538
'crudController' => Webfactor\Laravel\Generators\Schemas\Naming\CrudController::class,
36-
'routeFile' => Webfactor\Laravel\Generators\Schemas\Naming\RouteFile::class,
37-
'factory' => Webfactor\Laravel\Generators\Schemas\Naming\Factory::class,
38-
'seeder' => Webfactor\Laravel\Generators\Schemas\Naming\Seeder::class,
39-
'sidebar' => Webfactor\Laravel\Generators\Schemas\Naming\Sidebar::class,
39+
'routeFile' => Webfactor\Laravel\Generators\Schemas\Naming\RouteFile::class,
40+
'factory' => Webfactor\Laravel\Generators\Schemas\Naming\Factory::class,
41+
'seeder' => Webfactor\Laravel\Generators\Schemas\Naming\Seeder::class,
42+
'sidebar' => Webfactor\Laravel\Generators\Schemas\Naming\Sidebar::class,
4043
],
4144

4245
'fieldTypes' => [
43-
'date' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\DateType::class,
44-
'number' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\NumberType::class,
46+
'date' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\DateType::class,
47+
'number' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\NumberType::class,
4548
'summernote' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\SummernoteType::class,
46-
'string' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\StringType::class,
47-
'text' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\TextType::class,
48-
]
49+
'string' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\StringType::class,
50+
'text' => \Webfactor\Laravel\Generators\Schemas\FieldTypes\TextType::class,
51+
],
4952
];

src/Services/OpenIdeService.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@ class OpenIdeService extends ServiceAbstract implements ServiceInterface
99
{
1010
public function call()
1111
{
12-
if (!$ide = $this->command->option('ide')) {
13-
return;
12+
if ($ide = $this->command->option('ide')) {
13+
return $this->openInIde($ide);
14+
}
15+
16+
if ($ide = env('APP_EDITOR')) {
17+
return $this->openInIde($ide);
18+
}
19+
20+
if ($ide = config('app.editor')) {
21+
return $this->openInIde($ide);
1422
}
23+
}
1524

25+
protected function openInIde($ide)
26+
{
1627
if ($ideClass = config('webfactor.generators.ides.' . $ide)) {
1728
(new $ideClass($this->command->filesToBeOpened))->open();
29+
30+
return;
1831
}
32+
33+
$this->command->error('There is no opener class for ide <comment>' . $ide . '</comment>');
1934
}
2035
}

0 commit comments

Comments
 (0)