Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Laravel can be installed on selected directory #344

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,28 @@ protected function interact(InputInterface $input, OutputInterface $output)
label: 'What is the name of your project?',
placeholder: 'E.g. example-app',
required: 'The project name is required.',
validate: fn ($value) => preg_match('/[^\pL\pN\-_.]/', $value) !== 0
? 'The name may only contain letters, numbers, dashes, underscores, and periods.'
: null,
validate: function ($value) use ($input) {
if (preg_match('/[^\pL\pN\-_.]/', $value) !== 0) {
return 'The name may only contain letters, numbers, dashes, underscores, and periods.';
}

if ($input->getOption('force') !== true) {
try {
$this->verifyApplicationDoesntExist($this->getInstallationDirectory($value));
} catch (RuntimeException $e) {
return 'Application already exists.';
}
}
},
));
}

if ($input->getOption('force') !== true) {
$this->verifyApplicationDoesntExist(
$this->getInstallationDirectory($input->getArgument('name'))
);
}

if (! $input->getOption('breeze') && ! $input->getOption('jet')) {
match (select(
label: 'Would you like to install a starter kit?',
Expand Down Expand Up @@ -144,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$name = $input->getArgument('name');

$directory = $name !== '.' ? getcwd().'/'.$name : '.';
$directory = $this->getInstallationDirectory($name);

$this->composer = new Composer(new Filesystem(), $directory);

Expand Down Expand Up @@ -788,6 +804,17 @@ protected function isParked(string $directory)
return $output !== false ? in_array(dirname($directory), json_decode($output)) : false;
}

/**
* Get the installation directory.
*
* @param string $name
* @return string
*/
protected function getInstallationDirectory(string $name)
{
return $name !== '.' ? getcwd().'/'.$name : '.';
}

/**
* Get the version that should be downloaded.
*
Expand Down
Loading