Skip to content

Commit a0f51d1

Browse files
authored
Merge pull request #2 from kernel243/dev
Dev
2 parents cece5f2 + f8b4b72 commit a0f51d1

23 files changed

Lines changed: 676 additions & 77 deletions

src/Commands/BaseCommand.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ protected function isValidFilename(string $filename): bool
202202
return (bool) preg_match('#^[A-Za-z0-9_\\\\/\.-]+$#', $filename);
203203
}
204204

205+
/**
206+
* Create folders if necessary for file paths.
207+
*
208+
* @param array $pathParts
209+
* @param string $basePath
210+
* @return void
211+
*/
212+
protected function createFoldersIfNecessary(array $pathParts, string $basePath): void
213+
{
214+
$folder = $basePath;
215+
for ($i = 0; $i < count($pathParts) - 1; $i++) {
216+
$folder .= DIRECTORY_SEPARATOR . $pathParts[$i];
217+
if (!is_dir($folder)) {
218+
mkdir($folder, 0755, true);
219+
}
220+
}
221+
}
222+
205223
/**
206224
* Check if a repository file exists.
207225
*

src/Commands/ClassMakeCommand.php

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

3-
declare(strict_types=1);
4-
53
namespace Kernel243\Artisan\Commands;
64

75
use Illuminate\Support\Str;

src/Commands/Controller.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Kernel243\Artisan\Commands;
44

5-
use Illuminate\Console\Command;
65
use Illuminate\Support\Arr;
76
use Illuminate\Support\Str;
87

src/Commands/CrudMakeCommand.php

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

3-
declare(strict_types=1);
4-
53
namespace Kernel243\Artisan\Commands;
64

75
use Illuminate\Support\Str;

src/Commands/File.php

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace Kernel243\Artisan\Commands;
44

5-
use Illuminate\Console\Command;
65
use Illuminate\Support\Str;
76

8-
class File extends Command
7+
class File extends BaseCommand
98
{
109
/**
1110
* The name and signature of the console command.
@@ -21,37 +20,27 @@ class File extends Command
2120
*/
2221
protected $description = 'Create a new file';
2322

24-
/**
25-
* Create a new command instance.
26-
*
27-
* @return void
28-
*/
29-
public function __construct()
30-
{
31-
parent::__construct();
32-
}
33-
3423
/**
3524
* Execute the console command.
3625
*
37-
* @return void
26+
* @return int
3827
*/
39-
public function handle()
28+
public function handle(): int
4029
{
4130
if ($this->isCorrectFilename($this->argument('filename'))) {
4231
$extension = $this->getExtension();
4332
$path = base_path(str_replace('.', '/', $this->argument('filename')).'.'.$extension);
4433

45-
if ($this->replaceExistingFile($path, 'There is already a file with this name do you want to replace it ? [y/n]')) {
34+
if ($this->shouldReplaceFile($path, 'There is already a file with this name do you want to replace it ? [y/n]')) {
4635
$filename = explode('.', $this->argument('filename'));
47-
48-
$this->createFoldersIfNecessary($filename);
49-
36+
$this->createFoldersIfNecessary($filename, base_path());
5037
file_put_contents($path, '');
5138
$this->info('File created successfully');
5239
}
53-
} else
54-
$this->error('The filename is not correct.');
40+
return self::SUCCESS;
41+
}
42+
$this->error('The filename is not correct.');
43+
return self::FAILURE;
5544
}
5645

5746
/**
@@ -70,23 +59,6 @@ protected function getExtension()
7059
return 'php';
7160
}
7261

73-
/**
74-
* Create a set of folders if necessary.
75-
*
76-
* @param $filename
77-
* @return void
78-
*/
79-
protected function createFoldersIfNecessary($filename)
80-
{
81-
$folder = base_path('');
82-
for ($i = 0; $i < count($filename) - 1; $i++) {
83-
if (!is_dir($folder . '/' . $filename[$i])) {
84-
mkdir($folder . '/' . $filename[$i]);
85-
}
86-
$folder .= '/' . $filename[$i];
87-
}
88-
}
89-
9062
/**
9163
* Check if the filename is correct.
9264
*
@@ -97,25 +69,4 @@ protected function isCorrectFilename($name)
9769
{
9870
return (bool) preg_match('#^[a-zA-Z][a-zA-Z0-9._\-]+$#', $name);
9971
}
100-
101-
/**
102-
* Check if the filename exists and if it could be replaced.
103-
*
104-
* @param $filename
105-
* @param $question
106-
* @return bool
107-
*/
108-
protected function replaceExistingFile($filename, $question)
109-
{
110-
$replaceExistingFile = true;
111-
if (file_exists($filename)) {
112-
do {
113-
$input = $this->ask($question);
114-
} while (strtolower($input) != 'y' && strtolower($input) != 'n');
115-
116-
if (strtolower($input) == 'n')
117-
$replaceExistingFile = false;
118-
}
119-
return $replaceExistingFile;
120-
}
12172
}

src/Commands/Lang.php

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

3-
declare(strict_types=1);
4-
53
namespace Kernel243\Artisan\Commands;
64

75
class Lang extends BaseCommand

src/Commands/Repository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Kernel243\Artisan\Commands;
44

5-
use Illuminate\Console\Command;
65
use Illuminate\Support\Arr;
76
use Illuminate\Support\Str;
87

src/Commands/Resource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ protected function replaceNamespace($namespace, $stub)
6565
/**
6666
* Rewrite actually the content in the file.
6767
*
68-
* @param $filename
69-
* @param null $content
70-
* @param $module
68+
* @param string $filename
69+
* @param string $content
70+
* @param string $module
7171
*/
7272
protected function putInFile($filename, $content, $module = null)
7373
{

src/Commands/ResourceMakeCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace Kernel243\Artisan\Commands;
64

75
use Illuminate\Support\Str;
@@ -248,6 +246,15 @@ protected function generateLayout(): void
248246
$this->writeFile($path, $stub);
249247
}
250248

249+
protected function generateTailwindConfig(): void
250+
{
251+
$path = base_path('tailwind.config.js');
252+
if (file_exists($path)) return;
253+
$stub = $this->getStubContent('tailwind.config');
254+
if (!$this->shouldReplaceFile($path, 'Tailwind config exists. Replace it? [y/n]')) return;
255+
$this->writeFile($path, $stub);
256+
}
257+
251258
protected function generateResourceFormFields(array $fields): string
252259
{
253260
if (empty($fields)) { return " // Form::text('name', 'Name'),"; }

src/Commands/Service.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ protected function replaceClassName($name, $stub)
5454
/**
5555
* Rewrite actually the content in the file.
5656
*
57-
* @param null $module
58-
* @param $filename
59-
* @param $content
57+
* @param string $filename
58+
* @param string $content
59+
* @param string $module
6060
*/
6161
protected function putInFile($filename, $content, $module = null)
6262
{

0 commit comments

Comments
 (0)