Skip to content

Commit

Permalink
adding tailwind cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Jun 25, 2024
1 parent 61e5eb1 commit 857b3ba
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 37 deletions.
11 changes: 1 addition & 10 deletions src/Blocks/AbstractBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ 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, string $sourcePrivate = ''): void
protected function moveItems(array $args, string $source, string $destination, string $type, bool $isSingleFolder = false): void
{
// Get Props.
$skipExisting = $this->getSkipExisting($args);
Expand Down Expand Up @@ -63,14 +62,6 @@ protected function moveItems(array $args, string $source, string $destination, s

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

if (\is_dir($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 (!$sourceItems) {
self::cliError(
Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseAssetsCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function getDoc(): array
Assets will be created from this folder:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/assets
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/assets
"),
];
}
Expand All @@ -79,7 +81,7 @@ public function __invoke(array $args, array $assocArgs)
'name' => 'assets',
],
),
Helpers::getProjectPaths('blocksAssetsSource'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksAssetsTailwindSource') : Helpers::getProjectPaths('blocksAssetsSource'),
Helpers::getProjectPaths('blocksAssetsDestination'),
'assets folder',
true
Expand Down
8 changes: 4 additions & 4 deletions src/Blocks/UseBlockCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function getDoc(): array
All our blocks can be found here:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/custom
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/custom
"),
];
}
Expand All @@ -104,11 +106,9 @@ public function __invoke(array $args, array $assocArgs)

$this->moveItems(
$assocArgs,
Helpers::getProjectPaths('blocksSourceCustom'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksSourceTailwindCustom') : Helpers::getProjectPaths('blocksSourceCustom'),
Helpers::getProjectPaths('blocksDestinationCustom'),
'block',
false,
Helpers::getProjectPaths('blocksPrivateSourceCustom')
'block'
);
}
}
8 changes: 4 additions & 4 deletions src/Blocks/UseComponentCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function getDoc(): array
All our components can be found here:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/components
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/components
"),
];
}
Expand All @@ -104,11 +106,9 @@ public function __invoke(array $args, array $assocArgs)

$this->moveItems(
$assocArgs,
Helpers::getProjectPaths('blocksSourceComponents'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksSourceTailwindComponents') : Helpers::getProjectPaths('blocksSourceComponents'),
Helpers::getProjectPaths('blocksDestinationComponents'),
'component',
false,
Helpers::getProjectPaths('blocksPrivateSourceCustom')
'component'
);

if (!$assocArgs[self::ARG_GROUP_OUTPUT]) {
Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseGlobalAssetsCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function getDoc(): array
Global assets will be created from this folder:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/assets
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/assets
"),
];
}
Expand All @@ -79,7 +81,7 @@ public function __invoke(array $args, array $assocArgs)
'name' => 'assets',
],
),
Helpers::getProjectPaths('blocksGlobalAssetsSource'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksGlobalAssetsTailwindSource') : Helpers::getProjectPaths('blocksGlobalAssetsSource'),
Helpers::getProjectPaths('blocksGlobalAssetsDestination'),
'assets folder',
true
Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseManifestCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function getDoc(): array
Manifest.json file will be created from this file:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/manifest.json
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/manifest.json
"),
];
}
Expand All @@ -78,7 +80,7 @@ public function __invoke(array $args, array $assocArgs)
'name' => 'manifest.json',
],
),
Helpers::getProjectPaths('blocksSource'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksTailwindSource') : Helpers::getProjectPaths('blocksSource'),
Helpers::getProjectPaths('blocksDestination'),
'file'
);
Expand Down
8 changes: 4 additions & 4 deletions src/Blocks/UseVariationCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function getDoc(): array
All our variations can be found here:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/variations
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/variations
"),
];
}
Expand All @@ -94,11 +96,9 @@ public function __invoke(array $args, array $assocArgs)

$this->moveItems(
$assocArgs,
Helpers::getProjectPaths('blocksSourceVariations'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksSourceTailwindVariations') : Helpers::getProjectPaths('blocksSourceVariations'),
Helpers::getProjectPaths('blocksDestinationVariations'),
'variation',
false,
Helpers::getProjectPaths('blocksPrivateSourceCustom')
'variation'
);

if (!$assocArgs[self::ARG_GROUP_OUTPUT]) {
Expand Down
4 changes: 3 additions & 1 deletion src/Blocks/UseWrapperCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function getDoc(): array
Our wrapper can be found here:
https://github.com/infinum/eightshift-frontend-libs/tree/develop/blocks/init/src/Blocks/wrapper
or
https://github.com/infinum/eightshift-frontend-libs-tailwind/tree/develop/blocks/init/src/Blocks/wrapper
"),
];
}
Expand All @@ -75,7 +77,7 @@ public function __invoke(array $args, array $assocArgs)
'name' => 'wrapper',
],
),
Helpers::getProjectPaths('blocksSourceWrapper'),
$this->isTailwind() ? Helpers::getProjectPaths('blocksSourceTailwindWrapper') : Helpers::getProjectPaths('blocksSourceWrapper'),
Helpers::getProjectPaths('blocksDestinationWrapper'),
'wrapper',
true
Expand Down
10 changes: 10 additions & 0 deletions src/Cli/AbstractCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -1088,4 +1088,14 @@ public function runCliCommand(string $commandClass, string $commandParentName, a
$args,
));
}

/**
* Check if the project is using Tailwind.
*
* @return bool
*/
public function isTailwind(): bool
{
return \file_exists(Helpers::getProjectPaths('blocksTailwindSource'));
}
}
33 changes: 22 additions & 11 deletions src/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,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"];
$fTailwindLibsPath = ["node_modules", "@eightshift", "frontend-libs-tailwind", "blocks", "init"];
$libsPath = ["vendor", "infinum", "eightshift-libs"];
$libsPrefixedPath = ["vendor-prefixed", "infinum", "eightshift-libs"];
$testsDataPath = ["tests", "data"];
Expand Down Expand Up @@ -317,8 +317,22 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
$path = self::joinPaths([...$testsDataPath, ...$blocksPath]);
}
break;
case 'blocksPrivateSource':
$path = self::joinPaths([...$fPLibsPath, ...$blocksPath]);
case 'blocksGlobalAssetsTailwindSource':
$path = self::joinPaths([...$fTailwindLibsPath, $assetsPath]);

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

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

if (\getenv('ES_TEST')) {
$path = self::joinPaths([...$testsDataPath, ...$blocksPath]);
Expand All @@ -329,21 +343,18 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
case 'custom':
case 'blocksDestinationCustom':
case 'blocksSourceCustom':
case 'blocksPrivateSourceCustom':
$name = 'custom';
break;
case 'component':
case 'components':
case 'blocksDestinationComponents':
case 'blocksSourceComponents':
case 'blocksPrivateSourceComponents':
$name = 'components';
break;
case 'variation':
case 'variations':
case 'blocksDestinationVariations':
case 'blocksSourceVariations':
case 'blocksPrivateSourceVariations':
$name = 'variations';
break;
case 'wrapper':
Expand Down Expand Up @@ -385,11 +396,11 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
$path = self::joinPaths([...$testsDataPath, ...$blocksPath, $name]);
}
break;

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

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

0 comments on commit 857b3ba

Please sign in to comment.