Skip to content

Commit

Permalink
summary working
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 18, 2025
1 parent 22e940b commit 2bcbf48
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->promptManager->prompt();

$this->printer->summary($this->config, $this->promptManager->getResponses());

if (!$this->promptManager->shouldProceed()) {
info('Aborting project installation. No files were changed.');

return Command::SUCCESS;
}
die('RESTORE FROM HERE');

$this->downloadVortex();

Expand Down
54 changes: 31 additions & 23 deletions .vortex/installer/src/Prompts/PromptManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function prompt() {
default: $this->default($n, Converter::abbreviation($r['machine_name'], 4, ['_'])),
transform: fn(string $v) => trim($v),
// @todo Fix validation here.
validate: fn($v) => Converter::abbreviation($v) !== $v ? 'Please enter a valid module prefix: only lowercase letters, numbers, and underscores are allowed.' : NULL,
validate: fn($v) => Converter::machine(strtolower($v)) !== strtolower($v) ? 'Please enter a valid module prefix: only lowercase letters, numbers, and underscores are allowed.' : NULL,
), PromptFields::MODULE_PREFIX)

->add(fn($r, $pr, $n) => text(
Expand All @@ -201,24 +201,29 @@ public function prompt() {
default: $this->default($n, NULL),
), PromptFields::HOSTING_PROVIDER)

->addIf(
fn($r) => $r['hosting_provider'] !== 'other',
fn($r, $pr, $n) => info(sprintf('Web root will be set to "%s".', match ($r['hosting_provider']) {
'acquia' => 'docroot',
'lagoon' => 'web',
default => $this->default($n, 'web'),
})))

->addIf(
fn($r) => $r['hosting_provider'] === 'other',
fn($r, $pr, $n) => text(
label: 'πŸ“ Custom web root directory',
hint: 'Custom directory where the web server serves the site.',
placeholder: 'E.g. public',
required: TRUE,
transform: fn(string $v) => !empty(trim($v)) ? Converter::path($v) : trim($v),
validate: fn($v) => empty($v) ? 'Please enter a valid directory name' : NULL,
), PromptFields::WEBROOT_CUSTOM)
->add(
function ($r, $pr, $n) {
if ($r['hosting_provider'] !== 'other'){
$webroot = match ($r['hosting_provider']) {
'acquia' => 'docroot',
'lagoon' => 'web',
default => $this->default($n, 'web')
};

info(sprintf('Web root will be set to "%s".',$webroot));
}
else {
$webroot = text(
label: 'πŸ“ Custom web root directory',
hint: 'Custom directory where the web server serves the site.',
placeholder: 'E.g. public',
required: TRUE,
transform: fn(string $v) => !empty(trim($v)) ? Converter::path($v) : trim($v),
validate: fn($v) => empty($v) ? 'Please enter a valid directory name' : NULL,
);
}
return $webroot;
}, PromptFields::WEBROOT_CUSTOM)

->intro('Deployment')

Expand All @@ -245,7 +250,7 @@ public function prompt() {
$defaults[] = 'webhook';
}

multiselect(
return multiselect(
label: '🚚 Deployment types',
hint: 'You can deploy code using one or more methods.',
options: $options,
Expand Down Expand Up @@ -287,7 +292,7 @@ function ($r, $pr, $n) {
unset($options['acquia']);
}

select(
return select(
label: 'Database dump source',
hint: 'The database can be downloaded as an exported dump file or pre-packaged in a container image.',
options: $options,
Expand Down Expand Up @@ -323,7 +328,7 @@ function ($r, $pr, $n) {
unset($options['gha']);
}

select(
return select(
label: 'πŸ” Continuous Integration provider',
hint: 'Both providers support equivalent workflow.',
options: $options,
Expand Down Expand Up @@ -470,7 +475,10 @@ public function shouldProceed(): bool {
$proceed = TRUE;

if (!$this->config->isQuiet()) {
$proceed = confirm(sprintf('Proceed with installing Vortex into your project\'s directory "%s"?', $this->config->getDst()));
$proceed = confirm(
label: 'Proceed with installing Vortex?',
hint: sprintf('Vortex will be installed into your project\'s directory "%s"', $this->config->getDst())
);
}

// Kill-switch to not proceed with install. If false, the install will not
Expand Down
69 changes: 41 additions & 28 deletions .vortex/installer/src/Utils/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

use DrevOps\Installer\Prompts\PromptFields;
use Laravel\Prompts\Terminal;
use Symfony\Component\Console\Helper\TableSeparator;
use function Laravel\Prompts\info;
use function Laravel\Prompts\note;
use function Laravel\Prompts\table;

class Printer {

const EMPTY_LINE = '---EMPTY---';
const SECTION_TITLE = '---SECTION_TITLE---';

protected $output;

Expand Down Expand Up @@ -106,24 +108,14 @@ protected function headerInteractive(Config $config): void {
}

public function summary(Config $config, array $responses): void {
$values['General information'] = '';
$values['Current directory'] = $config->getRoot();
$values['Destination directory'] = $config->getDst();
// @todo Review below - it should show the version of Vortex that will be
// installed and a commit to be installed from.
$values['Vortex version'] = $config->get(Config::VORTEX_VERSION);
[$repo, $ref] = Downloader::parseUri($config->get(Config::REPO_URI));
$values['Vortex commit'] = $ref;

$values[] = self::EMPTY_LINE;

$values['General information'] = static::SECTION_TITLE;
$values['πŸ”– Site name'] = $responses[PromptFields::NAME];
$values['πŸ”– Site machine name'] = $responses[PromptFields::MACHINE_NAME];
$values['🏒 Organization name'] = $responses[PromptFields::ORG];
$values['🏒 Organization machine name'] = $responses[PromptFields::ORG_MACHINE_NAME];
$values['🌐 Public domain'] = $responses[PromptFields::DOMAIN];

$values['Code repository'] = '';
$values['Code repository'] = static::SECTION_TITLE;
$values['Code provider'] = $responses[PromptFields::CODE_PROVIDER];
if (PromptFields::GITHUB_TOKEN) {
$values['πŸ”‘ GitHub access token'] = 'valid';
Expand All @@ -132,7 +124,7 @@ public function summary(Config $config, array $responses): void {
$values['GitHub repository'] = $responses[PromptFields::GITHUB_REPO];
}

$values['Drupal'] = '';
$values['Drupal'] = static::SECTION_TITLE;
$values['πŸ“ Webroot'] = $responses[PromptFields::WEBROOT_CUSTOM];
$values['Use a custom profile'] = static::formatYesNo($responses[PromptFields::USE_CUSTOM_PROFILE]);
if ($responses[PromptFields::USE_CUSTOM_PROFILE]) {
Expand All @@ -141,13 +133,13 @@ public function summary(Config $config, array $responses): void {
$values['🧩 Module prefix'] = $responses[PromptFields::MODULE_PREFIX];
$values['🎨 Theme machine name'] = $responses[PromptFields::THEME];

$values['Hosting'] = '';
$values['Hosting'] = static::SECTION_TITLE;
$values['🏠 Hosting provider'] = $responses[PromptFields::HOSTING_PROVIDER];

$values['Deployment'] = '';
$values['Deployment'] = static::SECTION_TITLE;
$values['🚚 Deployment types'] = $responses[PromptFields::DEPLOY_TYPE];

$values['Workflow'] = '';
$values['Workflow'] = static::SECTION_TITLE;
$values['Provision type'] = $responses[PromptFields::PROVISION_TYPE];

if ($responses[PromptFields::PROVISION_TYPE] == 'database') {
Expand All @@ -158,19 +150,24 @@ public function summary(Config $config, array $responses): void {
}
}

$values['Continuous Integration'] = '';
$values['CI provider'] = $responses[PromptFields::CI_PROVIDER];
$values['Continuous Integration'] = static::SECTION_TITLE;
$values['πŸ” CI provider'] = $responses[PromptFields::CI_PROVIDER];

$values['Automations'] = '';
$values['Automations'] = static::SECTION_TITLE;
$values['πŸ”„ Dependency updates provider'] = $responses[PromptFields::DEPENDENCY_UPDATES_PROVIDER];
$values['πŸ‘€ Auto-assign the author to their PR'] = static::formatYesNo($responses[PromptFields::ASSIGN_AUTHOR_PR]);
$values['🎫 Auto-add a <info>CONFLICT</info> label to a PR when conflicts occur'] = static::formatYesNo($responses[PromptFields::LABEL_MERGE_CONFLICTS_PR]);
$values['πŸ‘€ Auto-assign PR author'] = static::formatYesNo($responses[PromptFields::ASSIGN_AUTHOR_PR]);
$values['🎫 Auto-add a <info>CONFLICT</info> label to PRs'] = static::formatYesNo($responses[PromptFields::LABEL_MERGE_CONFLICTS_PR]);

$values['Documentation'] = '';
$values['Documentation'] = static::SECTION_TITLE;
$values['πŸ“š Preserve project documentation'] = static::formatYesNo($responses[PromptFields::DOCS_PROJECT]);
$values['πŸ“‹ Preserve onboarding checklist'] = static::formatYesNo($responses[PromptFields::DOCS_ONBOARDING]);

static::printList($values);
$values['Locations'] = static::SECTION_TITLE;
$values['Current directory'] = $config->getRoot();
$values['Destination directory'] = $config->getDst();
$values['Vortex repository'] = $config->get(Config::REPO_URI);

$this->printList($values, 'Summary');
}

protected function printBox(string $content, ?string $title = NULL, int $width = 80): void {
Expand All @@ -188,10 +185,26 @@ protected function printBox(string $content, ?string $title = NULL, int $width =
table([], $rows);
}

protected static function printList(array $values): void {
$rows = array_map(function ($key, $value) {
return $value == Printer::EMPTY_LINE ? [] : [$key, $value];
}, array_keys($values), array_values($values));
protected function printList(array $values, ?string $title): void {
foreach ($values as $key => $value) {
if (is_array($value)) {
$values[$key] = implode(', ', $value);
}
}

$rows = [];
foreach ($values as $key => $value) {
if ($value === self::SECTION_TITLE) {
$rows[] = [static::green(static::bold($key))];
continue;
}

$rows[] = [' ' . $key, $value];
}

if ($title) {
info($title);
}

table([], $rows);
}
Expand Down

0 comments on commit 2bcbf48

Please sign in to comment.