Skip to content
Draft
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
12 changes: 12 additions & 0 deletions bin/lgen
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\Console\Application;
use StdGroup\LaravelGenerator\InstallCommand;

$application = new Application('Laravel Generator', '1.0');

$application->add(new InstallCommand());

$application->run();
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
}
],
"require": {
"php" : ">=7.1"
"php": ">=7.1",
"symfony/console": "^4.3",
"symfony/process": "^4.3"
},
"require-dev": {
"phpunit/phpunit" : ">=7.0",
Expand Down
65 changes: 65 additions & 0 deletions src/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace StdGroup\LaravelGenerator;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Process\Process;

class InstallCommand extends Command
{
protected function configure()
{
$this
->setName('install')
->setDescription('Install new Laravel app')
->addArgument(
'name',
InputArgument::REQUIRED,
'Your project name'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');

$output->writeln("Install new app: {$name}");

$questionHelper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select Laravel version (defaults: latest)',
['5.5', '5.6', '5.7', '5.8', 'latest'],
4
);
$question->setErrorMessage('Invalid version. Please select again!');

$laravelVersion = $questionHelper->ask($input, $output, $question);
$output->writeln('Installing Laravel ' . $laravelVersion);

$laravelPackage = 'laravel/laravel';
if ($laravelVersion !== 'latest') {
$laravelPackage .= ":$laravelVersion";
}

$process = new Process("composer create-project --prefer-dist $laravelPackage $name");
$process->setTty(true);
$process->setTimeout(null);

$output->writeln('Run > $ ' . $process->getCommandLine());

$statusCode = $process->run(function ($type, $buffer) use ($output) {
$output->writeln($buffer);
});

if ($statusCode === 0) {
$output->writeln('All done!');
}
}
}
28 changes: 0 additions & 28 deletions src/Skeleton.php

This file was deleted.