From 6454a9e3e40206864dbd2e853e6dfab28c266f14 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Wed, 10 Jul 2019 13:16:44 +0700 Subject: [PATCH] Wip --- bin/lgen | 12 ++++++++ composer.json | 4 ++- src/InstallCommand.php | 65 ++++++++++++++++++++++++++++++++++++++++++ src/Skeleton.php | 28 ------------------ 4 files changed, 80 insertions(+), 29 deletions(-) create mode 100755 bin/lgen create mode 100644 src/InstallCommand.php delete mode 100644 src/Skeleton.php diff --git a/bin/lgen b/bin/lgen new file mode 100755 index 0000000..68b6376 --- /dev/null +++ b/bin/lgen @@ -0,0 +1,12 @@ +#!/usr/bin/env php +add(new InstallCommand()); + +$application->run(); diff --git a/composer.json b/composer.json index 1b45a6e..69e78a9 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/InstallCommand.php b/src/InstallCommand.php new file mode 100644 index 0000000..dbbf6da --- /dev/null +++ b/src/InstallCommand.php @@ -0,0 +1,65 @@ +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!'); + } + } +} diff --git a/src/Skeleton.php b/src/Skeleton.php deleted file mode 100644 index 1964488..0000000 --- a/src/Skeleton.php +++ /dev/null @@ -1,28 +0,0 @@ -