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

Tailwind cli setup #411

Merged
merged 5 commits into from
Jun 25, 2024
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
30 changes: 20 additions & 10 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,42 @@

<rule ref="PSR12.Operators.OperatorSpacing.NoSpaceAfter">
<exclude-pattern>*/src/*/*Example.php</exclude-pattern>
<exclude-pattern>*/src/Init/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/plugin/</exclude-pattern>
</rule>

<rule ref="PSR12.Operators.OperatorSpacing.NoSpaceBefore">
<exclude-pattern>*/src/*/*Example.php</exclude-pattern>
<exclude-pattern>*/src/Init/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/plugin/</exclude-pattern>
</rule>

<rule ref="Eightshift.Security.HelpersEscape.OutputNotEscaped">
<exclude-pattern>*/src/*/*Example.php</exclude-pattern>
<exclude-pattern>*/src/Init/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/plugin/</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants.NonFullyQualified">
<exclude-pattern>*/src/*/*Example.php</exclude-pattern>
<exclude-pattern>*/src/Init/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/plugin/</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
<exclude-pattern>*/src/*/*Example.php</exclude-pattern>
<exclude-pattern>*/src/Init/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/standard/plugin/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/theme/</exclude-pattern>
<exclude-pattern>*/src/Init/tailwind/plugin/</exclude-pattern>
</rule>

<rule ref="Internal.NoCodeFound">
Expand Down
6 changes: 4 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ parameters:
- src/
excludePaths:
- src/**/*Example.php
- src/Init/theme/
- src/Init/plugin/
- src/Init/standard/theme/
- src/Init/standard/plugin/
- src/Init/tailwind/theme/
- src/Init/tailwind/plugin/
ignoreErrors:
# Ignore errors about reflection class variable being undefined. Errors are caught.
- '/^Variable \$reflectionClass might not be defined\.$/'
Expand Down
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
30 changes: 28 additions & 2 deletions src/Cli/AbstractCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ abstract class AbstractCli implements CliInterface
*/
public const ARG_FRONTEND_LIBS_VERSION = 'g_frontend_libs_version';

/**
* Output project frontend libs type arg.
*
* @var string
*/
public const ARG_FRONTEND_LIBS_TYPE = 'g_frontend_libs_type';

/**
* Output namespace arg.
*
Expand Down Expand Up @@ -277,6 +284,7 @@ public function prepareSetupArgs(array $args = []): array
self::ARG_SITE_URL => $args[self::ARG_SITE_URL] ?? \site_url(),
self::ARG_LIBS_VERSION => $args[self::ARG_LIBS_VERSION] ?? '',
self::ARG_FRONTEND_LIBS_VERSION => $args[self::ARG_FRONTEND_LIBS_VERSION] ?? '',
self::ARG_FRONTEND_LIBS_TYPE => \strtolower($args[self::ARG_FRONTEND_LIBS_TYPE] ?? 'standard'),
self::ARG_SKIP_EXISTING => true,
self::ARG_GROUP_OUTPUT => true,
];
Expand Down Expand Up @@ -657,13 +665,15 @@ public function cleanUpInitialBoilerplate(string $destination): void
*
* @param string $libsVersion Version of libs to install.
* @param string $frontendLibsVersion Version of frontend libs to install.
* @param string $frontendLibsType Type of frontend libs to install.
* @param string $destination Destination path.
*
* @return void
*/
public function initMandatoryAfter(
string $libsVersion,
string $frontendLibsVersion,
string $frontendLibsType,
string $destination
): void {
$this->cliLog('--------------------------------------------------', 'C');
Expand All @@ -681,10 +691,16 @@ public function initMandatoryAfter(
}
$this->cliLog('--------------------------------------------------', 'C');
$this->cliLog('Running npm install', 'C');

$flibsType = 'frontend-libs';
if ($frontendLibsType === 'tailwind') {
$flibsType = 'frontend-libs-tailwind';
}

if ($frontendLibsVersion) {
\shell_exec("cd {$destination} && npm install infinum/eightshift-frontend-libs#{$frontendLibsVersion}"); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
\shell_exec("cd {$destination} && npm install infinum/eightshift-{$flibsType}#{$frontendLibsVersion}"); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
} else {
\shell_exec("cd {$destination} && npm install @eightshift/frontend-libs"); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
\shell_exec("cd {$destination} && npm install @eightshift/{$flibsType}"); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
}
}

Expand Down Expand Up @@ -1072,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'));
}
}
37 changes: 26 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,26 +343,27 @@ public static function getProjectPaths(string $type = '', string $suffix = '', s
case 'custom':
case 'blocksDestinationCustom':
case 'blocksSourceCustom':
case 'blocksPrivateSourceCustom':
case 'blocksSourceTailwindCustom':
$name = 'custom';
break;
case 'component':
case 'components':
case 'blocksDestinationComponents':
case 'blocksSourceComponents':
case 'blocksPrivateSourceComponents':
case 'blocksSourceTailwindComponents':
$name = 'components';
break;
case 'variation':
case 'variations':
case 'blocksDestinationVariations':
case 'blocksSourceVariations':
case 'blocksPrivateSourceVariations':
case 'blocksSourceTailwindVariations':
$name = 'variations';
break;
case 'wrapper':
case 'blocksDestinationWrapper':
case 'blocksSourceWrapper':
case 'blocksSourceTailwindWrapper':
$name = 'wrapper';
break;
case 'blocksGlobalAssetsDestination':
Expand Down Expand Up @@ -385,11 +400,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
Loading