Skip to content

Commit 9e160a2

Browse files
committed
Move paths to config file.
1 parent ab9328f commit 9e160a2

9 files changed

+92
-22
lines changed

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ composer require zachleigh/laravel-vue-generators
1919
In Laravel's config/app.php file, add the service provider to the array with the 'providers' key.
2020
```
2121
VueGenerators\ServiceProvider::class
22-
```
22+
```
23+
Publish the config file:
24+
```
25+
php artisan vendor:publish --provider="VueGenerators\ServiceProvider"
26+
```
2327

2428
### Usage
2529
This package currently contains two commands: `component` and `mixin`.
2630
#### component
2731
Create a Vue js component file.
2832
```
29-
php artisan vueg:component {name} {--empty} {--path=assets.js.components}
33+
php artisan vueg:component {name} {--empty} {--path=}
3034
```
3135
###### name
3236
Name of the component.
@@ -41,16 +45,16 @@ php artisan vueg:component MyComponent --empty
4145
```
4246
Will create a file with no component methods.
4347
###### path
44-
By default, all components will be saved in resources/assets/js/components/. Specify a custom, period divide path with the path flag. Path root is in resources/.
48+
By default, all components will be saved in resources/assets/js/components/. Specify a custom path with the path flag. Path root is in resources/.
4549
```
46-
php artisan vueg:component MyComponent --path=assets.js.custom.folder
50+
php artisan vueg:component MyComponent --path=assets/js/custom/folder
4751
```
4852
Will create a file called MyComponent.vue at resources/assets/js/custom/folder/MyComponent.vue.
4953

5054
#### mixin
5155
Create a Vue js mixin file.
5256
```
53-
php artisan vueg:mixin {name} {--empty} {--path=assets.js.mixins}
57+
php artisan vueg:mixin {name} {--empty} {--path=}
5458
```
5559
###### name
5660
Name of the mixin.
@@ -65,9 +69,9 @@ php artisan vueg:mixin MyMixin --empty
6569
```
6670
Will create a file with no mixin methods.
6771
###### path
68-
By default, all mixins will be saved in resources/assets/js/mixins/. Specify a custom, period divide path with the path flag. Path root is in resources/.
72+
By default, all mixins will be saved in resources/assets/js/mixins/. Specify a custom path with the path flag. Path root is in resources/.
6973
```
70-
php artisan vueg:mixin MyMixin --path=assets.js.custom.folder
74+
php artisan vueg:mixin MyMixin --path=assets/js/custom/folder
7175
```
7276
Will create a file called MyMixin.vue at resources/assets/js/custom/folder/MyMixin.vue.
7377

src/Commands/MakeComponent.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MakeComponent extends VueGeneratorsCommand
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'vueg:component {name} {--empty} {--path=assets.js.components}';
14+
protected $signature = 'vueg:component {name} {--empty} {--path=}';
1515

1616
/**
1717
* The console command description.
@@ -29,7 +29,7 @@ public function handle()
2929

3030
$name = $this->argument('name').'.vue';
3131

32-
$path = $this->createPath($filesystem);
32+
$path = $this->createPath($filesystem, 'component');
3333

3434
$fullPath = resource_path("{$path}/{$name}");
3535

src/Commands/MakeMixin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MakeMixin extends VueGeneratorsCommand
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'vueg:mixin {name} {--empty} {--path=assets.js.mixins}';
14+
protected $signature = 'vueg:mixin {name} {--empty} {--path=}';
1515

1616
/**
1717
* The console command description.
@@ -29,7 +29,7 @@ public function handle()
2929

3030
$name = $this->argument('name').'.js';
3131

32-
$path = $this->createPath($filesystem);
32+
$path = $this->createPath($filesystem, 'mixin');
3333

3434
$fullPath = resource_path("{$path}/{$name}");
3535

src/Commands/VueGeneratorsCommand.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ class VueGeneratorsCommand extends Command
1414
* Create path for file.
1515
*
1616
* @param Filesystem $filesystem
17+
* @param string $type File type.
1718
*
1819
* @return string
1920
*/
20-
protected function createPath(Filesystem $filesystem)
21+
protected function createPath(Filesystem $filesystem, $type)
2122
{
22-
$path = $this->option('path');
23+
$customPath = $this->option('path');
2324

24-
$pathArray = explode('.', $path);
25+
$defaultPath = config("vue-generators.paths.{$type}s");
2526

26-
$this->buildPathFromArray($pathArray, $filesystem);
27+
$path = $customPath !== null ? $customPath : $defaultPath;
2728

28-
return implode('/', $pathArray);
29+
$this->buildPathFromArray($path, $filesystem);
30+
31+
return $path;
2932
}
3033
}

src/Paths.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ trait Paths
99
/**
1010
* Build directory tree from array of paths.
1111
*
12-
* @param array $pathArray
12+
* @param string $path
1313
* @param Filesystem|null $filesystem
1414
*/
15-
protected function buildPathFromArray(array $pathArray, Filesystem $filesystem = null)
15+
protected function buildPathFromArray($path, Filesystem $filesystem = null)
1616
{
17+
$pathArray = explode('/', $path);
18+
1719
if (is_null($filesystem)) {
1820
$filesystem = new Filesystem();
1921
}

src/ServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public function register()
2525
*/
2626
public function boot()
2727
{
28-
//
28+
$this->publishes([
29+
__DIR__.'/config.php' => config_path('vue-generators.php'),
30+
], 'config');
2931
}
3032

3133
/**

src/config.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Paths
7+
|--------------------------------------------------------------------------
8+
|
9+
| Register default paths for file types.
10+
*/
11+
'paths' => [
12+
'components' => 'assets/js/components',
13+
'mixins' => 'assets/js/mixins',
14+
]
15+
];

tests/CommandTest.php

+38-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,25 @@ public function it_saves_component_file_to_specified_path()
6767

6868
Artisan::call('vueg:component', [
6969
'name' => 'NewComponent',
70-
'--path' => 'custom.path',
70+
'--path' => 'custom/path',
71+
]);
72+
73+
$this->assertFileExists($file);
74+
}
75+
76+
/**
77+
* @test
78+
*/
79+
public function it_saves_componets_to_path_set_in_config()
80+
{
81+
app()['config']->set('vue-generators.paths.components', 'custom/path');
82+
83+
$file = resource_path('custom/path/NewComponent.vue');
84+
85+
$this->assertFileNotExists($file);
86+
87+
Artisan::call('vueg:component', [
88+
'name' => 'NewComponent',
7189
]);
7290

7391
$this->assertFileExists($file);
@@ -134,7 +152,25 @@ public function it_saves_mixin_file_to_specified_path()
134152

135153
Artisan::call('vueg:mixin', [
136154
'name' => 'NewMixin',
137-
'--path' => 'custom.path',
155+
'--path' => 'custom/path',
156+
]);
157+
158+
$this->assertFileExists($file);
159+
}
160+
161+
/**
162+
* @test
163+
*/
164+
public function it_saves_mixins_to_path_set_in_config()
165+
{
166+
app()['config']->set('vue-generators.paths.mixins', 'custom/path');
167+
168+
$file = resource_path('custom/path/NewMixin.js');
169+
170+
$this->assertFileNotExists($file);
171+
172+
Artisan::call('vueg:mixin', [
173+
'name' => 'NewMixin',
138174
]);
139175

140176
$this->assertFileExists($file);

tests/TestCase.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public function createApplication()
3333
*/
3434
protected function setUp()
3535
{
36+
$filesystem = new Filesystem();
37+
38+
$configDir = __DIR__.'./../src/config.php';
39+
40+
$configTarget = __DIR__.'./../vendor/laravel/laravel/config/vue-generators.php';
41+
42+
$filesystem->copy($configDir, $configTarget);
43+
3644
parent::setUp();
3745
}
3846

@@ -45,7 +53,7 @@ protected function tearDown()
4553

4654
$filesystem->deleteDirectory(resource_path());
4755

48-
$this->buildPathFromArray(explode('.', 'assets.js.components'));
56+
$this->buildPathFromArray('assets/js/components');
4957

5058
parent::tearDown();
5159
}

0 commit comments

Comments
 (0)