Skip to content

Commit

Permalink
fixing wrong block dependeny output
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Oct 27, 2023
1 parent 7bfc16c commit 1d3d368
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/Blocks/AbstractBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,34 @@ private function outputDependencyItems(string $source, string $type): void

if ($dependencies) {
$componentsCommandName = UseComponentCli::COMMAND_NAME;
$allDependencies = \array_map(static fn ($item) => Components::camelToKebabCase($item), $dependencies);
$allDependencies = \implode(', ', \array_unique(\array_values($allDependencies)));
$blocksCommandName = UseBlockCli::COMMAND_NAME;

$this->cliLogAlert(\implode("\n", [
"This {$type} may need some dependencies to work correctly.",
'',
'To add them to your project, run:',
"%Uwp boilerplate {$this->getCommandParentName()} {$componentsCommandName} --name='{$allDependencies}'%n",
'',
'If a dependency already exists in your project, you can skip it.',
]), 'info', 'Dependencies found');
$outputComand = [];

if ($componentsDependencies) {
$componentsDependenciesAll = \array_map(static fn ($item) => Components::camelToKebabCase($item), $componentsDependencies);
$componentsDependenciesAll = \implode(', ', \array_unique(\array_values($componentsDependenciesAll)));

$outputComand[] = "%Uwp boilerplate {$this->getCommandParentName()} {$componentsCommandName} --name='{$componentsDependenciesAll}'%n";
}

if ($innerBlocksDependency) {
$innerBlocksDependencyAll = \array_map(static fn ($item) => Components::camelToKebabCase($item), $innerBlocksDependency);

Check warning on line 247 in src/Blocks/AbstractBlocksCli.php

View check run for this annotation

Codecov / codecov/patch

src/Blocks/AbstractBlocksCli.php#L246-L247

Added lines #L246 - L247 were not covered by tests
$innerBlocksDependencyAll = \implode(', ', \array_unique(\array_values($innerBlocksDependencyAll)));

$outputComand[] = "%Uwp boilerplate {$this->getCommandParentName()} {$blocksCommandName} --name='{$innerBlocksDependencyAll}'%n";
}

if ($outputComand) {
$this->cliLogAlert(\implode("\n", [
"This {$type} may need some dependencies to work correctly.",
'',
'To add them to your project, run:',
...$outputComand,
'',
'If a dependency already exists in your project, you can skip it.',
]), 'info', 'Dependencies found');
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/Blocks/UseBlockCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
*/
class UseBlockCli extends AbstractBlocksCli
{
/**
* Command name.
*
* @var string
*/
public const COMMAND_NAME = 'use-block';

/**
* Get WPCLI command parent name
*
Expand All @@ -35,7 +42,7 @@ public function getCommandParentName(): string
*/
public function getCommandName(): string
{
return 'use-block';
return self::COMMAND_NAME;
}

/**
Expand Down

0 comments on commit 1d3d368

Please sign in to comment.