mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Improves init command
This commit is contained in:
1
resources/views/components/new-line.php
Normal file
1
resources/views/components/new-line.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
<div></div>
|
||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Console;
|
namespace Pest\Console;
|
||||||
|
|
||||||
|
use Pest\Support\View;
|
||||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@ -15,18 +16,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
|||||||
final class Thanks
|
final class Thanks
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The Command messages.
|
* The support options.
|
||||||
*
|
*
|
||||||
* @var array<int, string>
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
private const FUNDING_MESSAGES = [
|
private const FUNDING_MESSAGES = [
|
||||||
'',
|
'Star the project on GitHub' => 'https://github.com/pestphp/pest',
|
||||||
' - Star or contribute to Pest:',
|
'Tweet about the project' => 'https://twitter.com/pestphp',
|
||||||
' <options=bold>https://github.com/pestphp/pest</>',
|
'Sponsor the project' => 'https://github.com/sponsors/nunomaduro',
|
||||||
' - Tweet something about Pest on Twitter:',
|
|
||||||
' <options=bold>https://twitter.com/pestphp</>',
|
|
||||||
' - Sponsor the creator:',
|
|
||||||
' <options=bold>https://github.com/sponsors/nunomaduro</>',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +43,7 @@ final class Thanks
|
|||||||
new ArrayInput([]),
|
new ArrayInput([]),
|
||||||
$this->output,
|
$this->output,
|
||||||
new ConfirmationQuestion(
|
new ConfirmationQuestion(
|
||||||
'Can you quickly <options=bold>star our GitHub repository</>? 🙏🏻',
|
' <options=bold>Would you like to show your support by starring the project on GitHub?</>',
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -63,8 +60,15 @@ final class Thanks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (self::FUNDING_MESSAGES as $message) {
|
View::render('components.new-line');
|
||||||
$this->output->writeln($message);
|
|
||||||
|
foreach (self::FUNDING_MESSAGES as $message => $link) {
|
||||||
|
View::render('components.two-column-detail', [
|
||||||
|
'left' => $message,
|
||||||
|
'right' => $link,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View::render('components.new-line');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ namespace Pest\Plugins;
|
|||||||
|
|
||||||
use Pest\Console\Thanks;
|
use Pest\Console\Thanks;
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
|
use Pest\Support\View;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@ -61,61 +62,37 @@ final class Init implements HandlesArguments
|
|||||||
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
||||||
|
|
||||||
if (! is_dir($testsBaseDir)) {
|
if (! is_dir($testsBaseDir)) {
|
||||||
if (! mkdir($testsBaseDir) && ! is_dir($testsBaseDir)) {
|
mkdir($testsBaseDir);
|
||||||
$this->output->writeln(sprintf(
|
|
||||||
"\n <fg=white;bg=red;options=bold> ERROR </> Directory `%s` was not created.</>",
|
|
||||||
$testsBaseDir
|
|
||||||
));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->output->writeln(
|
$this->output->writeln([
|
||||||
' <fg=black;bg=green;options=bold> DONE </> Created `tests` directory.</>',
|
'',
|
||||||
);
|
' <fg=white;bg=blue;options=bold> INFO </> Preparing tests directory.</>',
|
||||||
}
|
'',
|
||||||
|
]);
|
||||||
|
|
||||||
foreach (self::STUBS as $from => $to) {
|
foreach (self::STUBS as $from => $to) {
|
||||||
$fromPath = __DIR__."/../../stubs/init/{$from}";
|
$fromPath = __DIR__."/../../stubs/init/{$from}";
|
||||||
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
$toPath = "{$this->testSuite->rootPath}/{$to}";
|
||||||
|
|
||||||
if (file_exists($toPath)) {
|
if (file_exists($toPath)) {
|
||||||
$this->output->writeln(sprintf(
|
View::render('components.two-column-detail', [
|
||||||
' <fg=black;bg=yellow;options=bold> INFO </> File `%s` already exists, skipped.</>',
|
'left' => $to,
|
||||||
$to
|
'right' => 'File already exists.',
|
||||||
));
|
]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($from === 'phpunit.xml' && file_exists($toPath.'.dist')) {
|
copy($fromPath, $toPath);
|
||||||
$this->output->writeln(sprintf(
|
|
||||||
' <fg=black;bg=yellow;options=bold> INFO </> File `%s` already exists, skipped.</>',
|
|
||||||
$to.'.dist'
|
|
||||||
));
|
|
||||||
|
|
||||||
continue;
|
View::render('components.two-column-detail', [
|
||||||
|
'left' => $to,
|
||||||
|
'right' => 'File created.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! copy($fromPath, $toPath)) {
|
View::render('components.new-line');
|
||||||
$this->output->writeln(sprintf(
|
|
||||||
'<fg=black;bg=red>[WARNING] Failed to copy stub `%s` to `%s`</>',
|
|
||||||
$from,
|
|
||||||
$toPath
|
|
||||||
));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->output->writeln(sprintf(
|
|
||||||
' <fg=black;bg=green;options=bold> DONE </> Created `%s` file.</>',
|
|
||||||
$to
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->output->writeln(
|
|
||||||
"\n <fg=black;bg=green;options=bold> DONE </> Pest initialised.</>\n",
|
|
||||||
);
|
|
||||||
|
|
||||||
(new Thanks($this->output))();
|
(new Thanks($this->output))();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user