Skip to content

Commit 9202655

Browse files
Merge pull request #13 from hexadog/develop
Develop
2 parents b302ac8 + 6245973 commit 9202655

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

config/config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,22 @@
4545
'key' => 'themes-manager',
4646
'lifetime' => 86400,
4747
],
48+
49+
/*
50+
|--------------------------------------------------------------------------
51+
| Composer File Template
52+
|--------------------------------------------------------------------------
53+
|
54+
| Config for composer.json file, generated for new theme
55+
| If null then information will be asked at generation process
56+
| If not null, values will be used at generation process
57+
|
58+
*/
59+
'composer' => [
60+
'vendor' => null,
61+
'author' => [
62+
'name' => null,
63+
'email' => null,
64+
],
65+
],
4866
];

resources/stubs/_folder-structure/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"minimum-stability": "stable",
77
"authors": [
88
{
9-
"name": "DummyAuthor"
9+
"name": "DummyAuthorName",
10+
"email": "DummyAuthorEmail"
1011
}
1112
],
1213
"extra": {

src/Console/Generators/MakeTheme.php

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Hexadog\ThemesManager\Console\Generators;
44

55
use Exception;
6-
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
7-
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
8-
use Hexadog\ThemesManager\Facades\ThemesManager;
6+
use Illuminate\Support\Arr;
7+
use Illuminate\Support\Str;
98
use Illuminate\Console\Command;
109
use Illuminate\Config\Repository;
1110
use Illuminate\Filesystem\Filesystem;
12-
use Illuminate\Support\Arr;
13-
use Illuminate\Support\Str;
11+
use Hexadog\ThemesManager\Facades\ThemesManager;
12+
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
13+
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
1414

1515
class MakeTheme extends Command
1616
{
@@ -94,6 +94,9 @@ public function handle()
9494
}
9595
}
9696

97+
/**
98+
* Validate theme name provided.
99+
*/
97100
protected function validateName()
98101
{
99102
$this->askName();
@@ -128,6 +131,11 @@ protected function validateName()
128131
return true;
129132
}
130133

134+
/**
135+
* Generate Theme structure in target directory.
136+
*
137+
* @return void
138+
*/
131139
private function generateTheme()
132140
{
133141
$this->sectionMessage('Files generation', 'start files generation process...');
@@ -161,12 +169,20 @@ private function generateTheme()
161169
}
162170
}
163171

172+
/**
173+
* Replace placeholders in generated file.
174+
*
175+
* @param \Symfony\Component\Finder\SplFileInfo $file
176+
*
177+
* @return string
178+
*/
164179
protected function replacePlaceholders($file)
165180
{
166181
$this->sectionMessage('File generation', "{$file->getPathName()}");
167182

168183
$find = [
169-
'DummyAuthor',
184+
'DummyAuthorName',
185+
'DummyAuthorEmail',
170186
'DummyDescription',
171187
'DummyName',
172188
'DummyParent',
@@ -175,8 +191,9 @@ protected function replacePlaceholders($file)
175191
];
176192

177193
$replace = [
178-
Str::title(Arr::get($this->theme, 'author', '')),
179-
Str::title(Arr::get($this->theme, 'description', '')),
194+
Str::title(Arr::get($this->theme, 'author-name', '')),
195+
Arr::get($this->theme, 'author-email', ''),
196+
Arr::get($this->theme, 'description', ''),
180197
Arr::get($this->theme, 'name', ''),
181198
Arr::get($this->theme, 'parent', ''),
182199
Arr::get($this->theme, 'vendor', ''),
@@ -186,16 +203,34 @@ protected function replacePlaceholders($file)
186203
return str_replace($find, $replace, $file->getContents());
187204
}
188205

206+
/**
207+
* Ask for theme author information.
208+
* Notice: if value is set in themes-manager.composer.author.name and themes-manager.composer.author.email config value
209+
* then this value will be used.
210+
*
211+
* @return void
212+
*/
189213
protected function askAuthor()
190214
{
191-
$this->config['author'] = $this->ask('Author name');
215+
$this->theme['author-name'] = $this->config->get('themes-manager.composer.author.name') ?? $this->ask('Author name');
216+
$this->theme['author-email'] = $this->config->get('themes-manager.composer.author.email') ?? $this->ask('Author email');
192217
}
193218

219+
/**
220+
* Ask for theme description.
221+
*
222+
* @return void
223+
*/
194224
protected function askDescription()
195225
{
196-
$this->config['description'] = $this->ask('Description');
226+
$this->theme['description'] = $this->ask('Description');
197227
}
198228

229+
/**
230+
* Ask for theme name.
231+
*
232+
* @return void
233+
*/
199234
protected function askName()
200235
{
201236
while (empty(Arr::get($this->theme, 'name', null))) {
@@ -209,19 +244,32 @@ protected function askName()
209244
}
210245
}
211246

247+
/**
248+
* Ask for parent theme name.
249+
*/
212250
protected function askParent()
213251
{
214252
if ($this->confirm('Is it a child theme?')) {
215253
$this->theme['parent'] = $this->ask('Parent theme name');
216-
$this->theme['parent'] = strtolower($this->theme['parent']);
254+
$this->theme['parent'] = mb_strtolower($this->theme['parent']);
217255
}
218256
}
219257

258+
/**
259+
* Ask for theme vendor.
260+
* Notice: if value is set in themes-manager.composer.vendor config value
261+
* then this value will be used.
262+
*
263+
* @return void
264+
*/
220265
protected function askVendor()
221266
{
222-
$this->theme['vendor'] = mb_strtolower($this->ask('Vendor name'));
267+
$this->theme['vendor'] = mb_strtolower($this->config->get('themes-manager.composer.vendor') ?? $this->ask('Vendor name'));
223268
}
224269

270+
/**
271+
* Ask for theme version.
272+
*/
225273
protected function askVersion()
226274
{
227275
$this->theme['version'] = $this->ask('Version number');

0 commit comments

Comments
 (0)