Skip to content
Closed
Show file tree
Hide file tree
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
40 changes: 39 additions & 1 deletion src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected function configure()
->addOption('yarn', null, InputOption::VALUE_NONE, 'Install and build NPM dependencies via Yarn')
->addOption('boost', null, InputOption::VALUE_NONE, 'Install Laravel Boost to improve AI assisted coding')
->addOption('using', null, InputOption::VALUE_OPTIONAL, 'Install a custom starter kit from a community maintained package')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists');
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists')
->addOption('ide-helper', null, InputOption::VALUE_NONE, 'Install Laravel ide-helper');
}

/**
Expand Down Expand Up @@ -181,6 +182,13 @@ protected function interact(InputInterface $input, OutputInterface $output)
label: 'Do you want to install Laravel Boost to improve AI assisted coding?',
));
}

if (! $input->getOption('ide-helper')) {
$input->setOption('ide-helper', confirm(
label: 'Do you want to install Laravel IDE Helper?',
default: false,
));
}
}

/**
Expand Down Expand Up @@ -543,6 +551,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->commitChanges('Configure Boost post-update script', $directory, $input, $output);
}

if ($input->getOption('ide-helper')) {
$this->installIdeHelper($directory, $input, $output);
}

$output->writeln(" <bg=blue;fg=white> INFO </> Application ready in <options=bold>[{$name}]</>. You can start your local development using:".PHP_EOL);
$output->writeln('<fg=gray>➜</> <options=bold>cd '.$name.'</>');

Expand All @@ -565,6 +577,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return $process->getExitCode();
}

protected function installIdeHelper(string $directory, InputInterface $input, OutputInterface $output): void
{
$composerBinary = $this->findComposer();

$gitignoreContents = file_get_contents($directory.'/.gitignore');

file_put_contents(
$directory.'/.gitignore',
$gitignoreContents.
PHP_EOL.
'# Laravel IDE Helper'
.PHP_EOL.'_ide_helper.php'
.PHP_EOL.'_ide_helper_models.php'
.PHP_EOL.'.phpstorm.meta.php'
);

$commands = [
$composerBinary.' require --dev barryvdh/laravel-ide-helper',
$this->phpBinary().' artisan ide-helper:generate',
$this->phpBinary().' artisan ide-helper:models --nowrite',
$this->phpBinary().' artisan ide-helper:meta',
];

$this->runCommands($commands, $input, $output, workingPath: $directory);
}

/**
* Determine the Node package manager to use.
*
Expand Down
33 changes: 33 additions & 0 deletions tests/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,37 @@ public function test_on_at_least_laravel_11()
$this->assertTrue($onLaravel11);
$this->assertTrue($onLaravel12);
}

public function test_it_can_add_laravel_ide_helper()
{
$scaffoldDirectoryName = 'tests-output/ide-helper-app';
$scaffoldDirectory = __DIR__.'/../'.$scaffoldDirectoryName;

if (file_exists($scaffoldDirectory)) {
if (PHP_OS_FAMILY == 'Windows') {
exec("rd /s /q \"$scaffoldDirectory\"");
} else {
exec("rm -rf \"$scaffoldDirectory\"");
}
}

$app = new Application('Laravel Installer');
$app->add(new NewCommand);

$tester = new CommandTester($app->find('new'));

$statusCode = $tester->execute(
['name' => $scaffoldDirectoryName, '--ide-helper' => true],
['interactive' => false]
);

$this->assertSame(0, $statusCode);
$this->assertDirectoryExists($scaffoldDirectory.'/vendor/barryvdh/laravel-ide-helper');

$gitignoreContents = file_get_contents($scaffoldDirectory.'/.gitignore');
$this->assertStringContainsString('# Laravel IDE Helper', $gitignoreContents);
$this->assertStringContainsString('_ide_helper.php', $gitignoreContents);
$this->assertStringContainsString('_ide_helper_models.php', $gitignoreContents);
$this->assertStringContainsString('phpstorm.meta.php', $gitignoreContents);
}
}