Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding frontend libs private options #372

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
25 changes: 18 additions & 7 deletions src/Blocks/AbstractBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ abstract class AbstractBlocksCli extends AbstractCli
* @param string $destination Destination path.
* @param string $type Type of items used for output log.
* @param bool $isSingleFolder Is single folder item.
* @param string $sourcePrivate Source private libs path.
*
* @return void
*/
protected function moveItems(array $args, string $source, string $destination, string $type, bool $isSingleFolder = false): void
protected function moveItems(array $args, string $source, string $destination, string $type, bool $isSingleFolder = false, string $sourcePrivate = ''): void
{
$sep = \DIRECTORY_SEPARATOR;

Expand Down Expand Up @@ -62,12 +63,20 @@ protected function moveItems(array $args, string $source, string $destination, s
);
}

$sourceItems = \array_diff(\scandir($source), ['..', '.']);
$sourceItems = \array_values($sourceItems);
$sourceItems = \array_diff(\scandir($source) ?: [], ['..', '.']); // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found
$sourceItems = \array_fill_keys(\array_values($sourceItems), $source);
$sourceItemsPrivate = [];

if ($isSingleFolder || $isFile) {
if ($sourcePrivate) {
$sourceItemsPrivate = \array_diff(\scandir($sourcePrivate) ?: [], ['..', '.']); // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found
$sourceItemsPrivate = \array_fill_keys(\array_values($sourceItemsPrivate), $sourcePrivate);
}

$sourceItems = \array_merge($sourceItems, $sourceItemsPrivate);

if (($isSingleFolder || $isFile) && isset($sourceItems[$name])) {
$sourceItems = [
$name,
$name => $sourceItems[$name],
];
}

Expand All @@ -83,18 +92,20 @@ protected function moveItems(array $args, string $source, string $destination, s
}

foreach ($itemsList as $item) {
if (!\in_array($item, $sourceItems, true)) {
if (!isset($sourceItems[$item])) {
self::cliError(
\sprintf(
// translators: %s will be replaced with type of item, item name and shorten cli path.
"Requested %s with the name `%s` doesn't exist in our library. Please review you search.\nYou can find all available items on this list: \n\n%s\n\nOr find them on this link: https://eightshift.com/storybook/",
$type,
$item,
\implode(\PHP_EOL, $sourceItems)
\implode(\PHP_EOL, \array_keys($sourceItems))
)
);
}

$source = $sourceItems[$item];

$fullSource = Components::joinPaths([$source, $item]);
$fullDestination = Components::joinPaths([$destination, $item]);

Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseBlockCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function __invoke(array $args, array $assocArgs)
$assocArgs,
Components::getProjectPaths('blocksSourceCustom'),
Components::getProjectPaths('blocksDestinationCustom'),
'block'
'block',
false,
Components::getProjectPaths('blocksPrivateSourceCustom')
);
}
}
4 changes: 3 additions & 1 deletion src/Blocks/UseComponentCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function __invoke(array $args, array $assocArgs)
$assocArgs,
Components::getProjectPaths('blocksSourceComponents'),
Components::getProjectPaths('blocksDestinationComponents'),
'component'
'component',
false,
Components::getProjectPaths('blocksPrivateSourceCustom')
);

if (!$groupOutput) {
Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseVariationCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function __invoke(array $args, array $assocArgs)
$assocArgs,
Components::getProjectPaths('blocksSourceVariations'),
Components::getProjectPaths('blocksDestinationVariations'),
'variation'
'variation',
false,
Components::getProjectPaths('blocksPrivateSourceCustom')
);

if (!$groupOutput) {
Expand Down
22 changes: 21 additions & 1 deletion src/Helpers/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
}

$flibsPath = ["node_modules", "@eightshift", "frontend-libs", "blocks", "init"];
$fPLibsPath = ["node_modules", "@eightshift", "frontend-libs-private", "blocks", "init"];
$libsPath = ["vendor", "infinum", "eightshift-libs"];
$testsDataPath = ["tests", "data"];
$srcPath = "src";
Expand Down Expand Up @@ -417,20 +418,30 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
case 'blocksSource':
$path = self::joinPaths([...$flibsPath, ...$blocksPath]);

if (\getenv('ES_TEST')) {
$path = self::joinPaths([...$testsDataPath, ...$blocksPath]);
}
break;
case 'blocksPrivateSource':
$path = self::joinPaths([...$fPLibsPath, ...$blocksPath]);

if (\getenv('ES_TEST')) {
$path = self::joinPaths([...$testsDataPath, ...$blocksPath]);
}
break;
case 'blocksDestinationCustom':
case 'blocksSourceCustom':
case 'blocksPrivateSourceCustom':
$name = 'custom';
break;
case 'blocksDestinationComponents':
case 'blocksSourceComponents':
case 'blocksPrivateSourceComponents':
$name = 'components';
break;
case 'blocksDestinationVariations':
case 'blocksSourceVariations':
case 'blocksPrivateSourceVariations':
$name = 'variations';
break;
case 'blocksDestinationWrapper':
Expand Down Expand Up @@ -480,6 +491,16 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
}
break;

case 'blocksPrivateSourceCustom':
case 'blocksPrivateSourceComponents':
case 'blocksPrivateSourceVariations':
$path = self::joinPaths([...$fPLibsPath, ...$blocksPath, $name]);

if (\getenv('ES_TEST')) {
$path = self::joinPaths([...$testsDataPath, ...$blocksPath, $name]);
}
break;

case 'blocksDestinationCustom':
case 'blocksDestinationComponents':
case 'blocksDestinationVariations':
Expand All @@ -500,7 +521,6 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s

return \str_replace("{$sep}{$sep}", $sep, $path);
}

/**
* Paths join
*
Expand Down
Loading