Skip to content

Commit

Permalink
Now it asks for configurations BEFORE installation starts
Browse files Browse the repository at this point in the history
  • Loading branch information
mderis committed Apr 26, 2021
1 parent d52ca34 commit 07222dd
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class NewCommand extends Command

protected static $defaultName = 'new';

protected static $availableContainers = [
'Social Authentication' => 'apiato/social-auth-container',
'Localization' => 'apiato/localization-container',
'Payments' => 'apiato/payment-container',
'Settings' => 'apiato/settings-container',
];

protected function configure()
{
$this
Expand All @@ -38,6 +45,13 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{

// Init
$helper = $this->getHelper('question');
$name = $input->getArgument('name');
$directory = $name !== '.' ? getcwd() . '/' . $name : '.';
$version = $this->getVersion($input);
$composer = $this->findComposer();

$output->writeln([
'<fg=red>' . PHP_EOL . PHP_EOL . PHP_EOL,
" ___ .______ __ ___ .___________. ______ ",
Expand All @@ -51,11 +65,32 @@ protected function execute(InputInterface $input, OutputInterface $output)

sleep(1);

$name = $input->getArgument('name');
// Ask for configurations

$directory = $name !== '.' ? getcwd() . '/' . $name : '.';
$confirmation = new ConfirmationQuestion('Do you want to add additional containers? (yes/no) [no] ', false);
$installContainersCommand = null;

$version = $this->getVersion($input);
if ($helper->ask($input, $output, $confirmation)) {
$question = new ChoiceQuestion(
'Select all containers you want to install (example: 2,3,4).',
array_keys(self::$availableContainers)
);

$question->setMultiselect(true);

$selectedContainersArray = $helper->ask($input, $output, $question);
$selectedContainersString = "";
$installContainersCommand = ['cd ' . $directory];

foreach (array_keys(self::$availableContainers) as $availableContainer) {
if (in_array($availableContainer, $selectedContainersArray)) {
$selectedContainersString .= ' ' . self::$availableContainers[$availableContainer];
}
}
array_push($installContainersCommand, $composer . " require" . $selectedContainersString);
}

// Start installing project

if (!$input->getOption('force')) {
$this->verifyApplicationDoesntExist($directory);
Expand All @@ -65,8 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new RuntimeException('Cannot use --force option when using current directory for installation!');
}

$composer = $this->findComposer();

$commands = [
$composer . " create-project apiato/apiato \"$directory\" $version --remove-vcs --prefer-dist",
];
Expand All @@ -91,39 +124,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$helper = $this->getHelper('question');

$confirmation = new ConfirmationQuestion('Now do you want to add additional containers? [default: no] ', false);

$availableContainers = [
'Social Authentication' => 'apiato/social-auth-container',
'Localization' => 'apiato/localization-container',
'Payments' => 'apiato/payment-container',
'Settings' => 'apiato/settings-container',
];

if ($helper->ask($input, $output, $confirmation)) {
$question = new ChoiceQuestion(
'Select all containers you want to install (example: 2,3,4).',
array_keys($availableContainers)
);

$question->setMultiselect(true);

$selectedContainersArray = $helper->ask($input, $output, $question);
$selectedContainersString = "";
$commands = ['cd ' . $directory];

foreach (array_keys($availableContainers) as $availableContainer) {
if (in_array($availableContainer, $selectedContainersArray)) {
$selectedContainersString .= ' ' . $availableContainers[$availableContainer];
}
}

array_push($commands, $composer . " require" . $selectedContainersString);
$this->runCommands($commands, $input, $output);
}
// Install additional containers
if ($installContainersCommand) $this->runCommands($installContainersCommand, $input, $output);

// The End
$output->writeln(PHP_EOL . '<comment>Apiato ready! Build something amazing.</comment>');

return $process->getExitCode();
Expand Down

0 comments on commit 07222dd

Please sign in to comment.