Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed May 6, 2022
2 parents c16f58d + ba0495a commit 906ea8b
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 109 deletions.
16 changes: 9 additions & 7 deletions src/Blocks/AbstractBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo
$root = $this->getProjectRootPath();
$rootNode = $this->getFrontendLibsBlockPath();

$sourcePathFolder = "{$rootNode}/{$outputDir}/";
$ds = \DIRECTORY_SEPARATOR;
$sourcePathFolder = "{$rootNode}{$ds}{$outputDir}{$ds}";

$blocks = \scandir($sourcePathFolder);
$blocksFullList = \array_diff((array)$blocks, ['..', '.']);
Expand All @@ -53,13 +54,13 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo

// Iterate blocks/components.
foreach ($blocks as $block) {
$path = "{$outputDir}/{$block}";
$path = "{$outputDir}{$ds}{$block}";
$sourcePath = "{$sourcePathFolder}{$block}";

if (!\getenv('ES_TEST')) {
$destinationPath = $root . \DIRECTORY_SEPARATOR . $path;
if (!\getenv('TEST')) {
$destinationPath = "{$root}{$ds}{$path}";
} else {
$destinationPath = $this->getProjectRootPath(true) . '/cliOutput';
$destinationPath = "{$this->getProjectRootPath(true)}{$ds}cliOutput";
}

$typePlural = !$isComponents ? 'blocks' : 'components';
Expand Down Expand Up @@ -115,11 +116,12 @@ protected function blocksMove(array $assocArgs, string $outputDir, bool $isCompo
*/
private function moveBlock(string $destinationPath, string $sourcePath, string $name, array $assocArgs, string $path, string $typeSingular): void
{
$ds = \DIRECTORY_SEPARATOR;
// Create folder in project if missing.
\mkdir("{$destinationPath}/");
\mkdir("{$destinationPath}{$ds}");

// Move block/component to project folder.
$this->copyRecursively($sourcePath, "{$destinationPath}/");
$this->copyRecursively($sourcePath, "{$destinationPath}{$ds}");

$typeSingular = \ucfirst($typeSingular);

Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ private function blocksInit(array $args): void
WP_CLI::runcommand("{$this->commandParentName} use_wrapper {$this->prepareArgsManual($args)}");

foreach (static::COMPONENTS as $component) {
WP_CLI::runcommand("{$this->commandParentName} use_component --name='{$component}' {$this->prepareArgsManual($args)}");
WP_CLI::runcommand("{$this->commandParentName} use_component --name={$component} {$this->prepareArgsManual($args)}");
}

foreach (static::BLOCKS as $block) {
WP_CLI::runcommand("{$this->commandParentName} use_block --name='{$block}' {$this->prepareArgsManual($args)}");
WP_CLI::runcommand("{$this->commandParentName} use_block --name={$block} {$this->prepareArgsManual($args)}");
}

WP_CLI::success('Blocks successfully set.');
Expand Down
46 changes: 28 additions & 18 deletions src/Cli/AbstractCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ function ($item) {
*/
public function getExampleTemplate(string $currentDir, string $fileName, bool $skipMissing = false): self
{
$path = "{$currentDir}/{$this->getExampleFileName( $fileName )}.php";
$ds = \DIRECTORY_SEPARATOR;
$path = "{$currentDir}{$ds}{$this->getExampleFileName( $fileName )}.php";

// If you pass file name with extension the version will be used.
if (\strpos($fileName, '.') !== false) {
$path = "{$currentDir}/{$fileName}";
$path = "{$currentDir}{$ds}{$fileName}";
}

$templateFile = '';
Expand Down Expand Up @@ -345,21 +346,25 @@ public function outputWrite(string $outputDir, string $outputFile, array $args =
*/
public function getOutputDir(string $path = ''): string
{
if (\function_exists('\add_action') && !\getenv('ES_TEST')) {
$ds = \DIRECTORY_SEPARATOR;

if (\function_exists('\add_action') && !\getenv('TEST')) {
$root = $this->getProjectRootPath();
} else {
$root = $this->getProjectRootPath(true) . '/cliOutput';
$root = "{$this->getProjectRootPath(true)}{$ds}cliOutput";
}

$ds = \DIRECTORY_SEPARATOR;

$root = \rtrim($root, $ds);
$root = \trim($root, $ds);

$path = \rtrim($path, $ds);
$path = \trim($path, $ds);

return "{$ds}{$root}{$ds}{$path}";
if ($ds === '/') {
return "{$ds}{$root}{$ds}{$path}";
}

return "{$root}{$ds}{$path}";
}

/**
Expand Down Expand Up @@ -657,11 +662,12 @@ public function searchReplaceString(string $oldString, string $newString): self
*/
public function getComposer(array $args = []): array
{
$ds = \DIRECTORY_SEPARATOR;
if (!isset($args['config_path'])) {
if (\function_exists('\add_action')) {
$composerPath = $this->getProjectRootPath() . '/composer.json';
$composerPath = "{$this->getProjectRootPath()}{$ds}composer.json";
} else {
$composerPath = $this->getProjectRootPath(true) . '/composer.json';
$composerPath = "{$this->getProjectRootPath(true)}{$ds}composer.json";
}
} else {
$composerPath = $args['config_path'];
Expand Down Expand Up @@ -834,7 +840,8 @@ public function getProjectConfigRootPath(bool $isDev = false): string
*/
public function getFrontendLibsPath(string $path = ''): string
{
return "{$this->getProjectRootPath()}/node_modules/@eightshift/frontend-libs/{$path}";
$ds = \DIRECTORY_SEPARATOR;
return "{$this->getProjectRootPath()}{$ds}node_modules{$ds}@eightshift{$ds}frontend-libs{$ds}{$path}";
}

/**
Expand All @@ -846,11 +853,12 @@ public function getFrontendLibsPath(string $path = ''): string
*/
public function getLibsPath(string $path = ''): string
{
if (\getenv('ES_TEST')) {
return "{$this->getProjectRootPath()}/{$path}";
$ds = \DIRECTORY_SEPARATOR;
if (\getenv('TEST')) {
return "{$this->getProjectRootPath()}{$ds}{$path}";
}

return "{$this->getProjectRootPath()}/vendor/infinum/eightshift-libs/{$path}";
return "{$this->getProjectRootPath()}{$ds}vendor{$ds}infinum{$ds}eightshift-libs{$ds}{$path}";
}

/**
Expand All @@ -860,7 +868,8 @@ public function getLibsPath(string $path = ''): string
*/
public function getFrontendLibsBlockPath(): string
{
return $this->getFrontendLibsPath('blocks/init');
$ds = \DIRECTORY_SEPARATOR;
return $this->getFrontendLibsPath("blocks{$ds}init");
}

/**
Expand All @@ -872,16 +881,17 @@ public function getFrontendLibsBlockPath(): string
*/
public function getFullBlocksFiles(string $name): array
{
$ds = \DIRECTORY_SEPARATOR;
return [
"{$name}.php",
"{$name}-block.js",
"{$name}-hooks.js",
"{$name}-transforms.js",
"{$name}.js",
"docs/story.js",
"components/{$name}-editor.js",
"components/{$name}-toolbar.js",
"components/{$name}-options.js",
"docs{$ds}story.js",
"components{$ds}{$name}-editor.js",
"components{$ds}{$name}-toolbar.js",
"components{$ds}{$name}-options.js",
];
}

Expand Down
5 changes: 3 additions & 2 deletions src/Cli/CliInitAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public function getCommandName(): string
public function getDoc(): array
{
return [
'shortdesc' => 'Generates initial setup for all service classes in the WordPress theme project.
This command is used only in develop mode. For this to work you must set global constant ES_DEVELOP_MODE to true.',
'shortdesc' =>
'Generates initial setup for all service classes in the WordPress theme project.
This command is used only in develop mode. For this to work you must set global constant ES_DEVELOP_MODE to true.',
];
}

Expand Down
6 changes: 5 additions & 1 deletion src/Helpers/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ public static function getManifestDirect(string $path): array
$sep = \DIRECTORY_SEPARATOR;
$path = \trim($path, $sep);

$manifest = "{$sep}{$path}{$sep}manifest.json";
$manifest = "{$path}{$sep}manifest.json";

if ($sep === '/') {
$manifest = "{$sep}{$manifest}";
}

if (!\file_exists($manifest)) {
throw ComponentException::throwUnableToLocateComponent($manifest);
Expand Down
156 changes: 77 additions & 79 deletions src/Helpers/CssVariablesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,104 +151,102 @@ public static function outputCssVariablesInline(): string
return '';
}

// Prepare final output.
$output = '';

$styles = Components::getStyles();

// Bailout if styles are missing.
if (!$styles) {
return '';
}

// Define variables from globalManifest.
$breakpointsData = self::getSettingsGlobalVariablesBreakpoints();

// Sort breakpoints in ascending order.
\asort($breakpointsData);

// Populate min values.
$breakpointsMin = \array_map(
static function ($item) {
return "min---{$item}";
},
\array_values($breakpointsData)
);
// Append 0 value.
\array_unshift($breakpointsMin, 'min---0');

// Populate max values.
$breakpointsMax = \array_map(
static function ($item) {
return "max---{$item}";
},
\array_reverse(\array_values($breakpointsData))
);
// Append 0 value.
\array_unshift($breakpointsMax, 'max---0');

// Return empty array of items.
$breakpoints = \array_map(
static function () {
return '';
},
\array_flip(\array_values(\array_merge($breakpointsMin, $breakpointsMax)))
);
if ($styles) {
// Define variables from globalManifest.
$breakpointsData = self::getSettingsGlobalVariablesBreakpoints();

// Loop styles.
foreach ($styles as $style) {
$name = $style['name'] ?? '';
$unique = $style['unique'] ?? '';
$variables = $style['variables'] ?? [];
// Sort breakpoints in ascending order.
\asort($breakpointsData);

// Bailout if variables are missing.
if (!$variables) {
continue;
}
// Populate min values.
$breakpointsMin = \array_map(
static function ($item) {
return "min---{$item}";
},
\array_values($breakpointsData)
);
// Append 0 value.
\array_unshift($breakpointsMin, 'min---0');

$uniqueSelector = "[data-id='{$unique}']";
// Populate max values.
$breakpointsMax = \array_map(
static function ($item) {
return "max---{$item}";
},
\array_reverse(\array_values($breakpointsData))
);
// Append 0 value.
\array_unshift($breakpointsMax, 'max---0');

if (!$unique) {
$uniqueSelector = '';
}
// Return empty array of items.
$breakpoints = \array_map(
static function () {
return '';
},
\array_flip(\array_values(\array_merge($breakpointsMin, $breakpointsMax)))
);

foreach ($variables as $data) {
$type = $data['type'] ?? '';
$value = $data['value'] ?? '';
$variable = $data['variable'] ?? '';
// Loop styles.
foreach ($styles as $style) {
$name = $style['name'] ?? '';
$unique = $style['unique'] ?? '';
$variables = $style['variables'] ?? [];

// Bailout if variable is missing.
if (!$variable) {
// Bailout if variables are missing.
if (!$variables) {
continue;
}

// Bailout if breakpont is missing.
if (!isset($breakpoints["{$type}---{$value}"])) {
continue;
}
$uniqueSelector = "[data-id='{$unique}']";

// Populate breakpoint.
$breakpoints["{$type}---{$value}"] .= "\n.{$name}{$uniqueSelector}{\n{$variable}\n} ";
}
}
if (!$unique) {
$uniqueSelector = '';
}

// Prepare final output.
$output = '';
foreach ($variables as $data) {
$type = $data['type'] ?? '';
$value = $data['value'] ?? '';
$variable = $data['variable'] ?? '';

// Loop breakpoints in correct order.
foreach ($breakpoints as $breakpointKey => $breakpointValue) {
$breakpointKey = \explode('---', $breakpointKey);
// Bailout if variable is missing.
if (!$variable) {
continue;
}

$type = $breakpointKey[0] ?? '';
$value = $breakpointKey[1] ?? '';
// Bailout if breakpont is missing.
if (!isset($breakpoints["{$type}---{$value}"])) {
continue;
}

// Bailout if empty value.
if (!$breakpointValue) {
continue;
// Populate breakpoint.
$breakpoints["{$type}---{$value}"] .= "\n.{$name}{$uniqueSelector}{\n{$variable}\n} ";
}
}

// If value is 0 then this breakpoint has no media query.
if ($value === '0') {
$output .= "{$breakpointValue}\n";
} else {
$output .= "\n@media ({$type}-width:{$value}px){{$breakpointValue}}\n ";
// Loop breakpoints in correct order.
foreach ($breakpoints as $breakpointKey => $breakpointValue) {
$breakpointKey = \explode('---', $breakpointKey);

$type = $breakpointKey[0] ?? '';
$value = $breakpointKey[1] ?? '';

// Bailout if empty value.
if (!$breakpointValue) {
continue;
}

// If value is 0 then this breakpoint has no media query.
if ($value === '0') {
$output .= "{$breakpointValue}\n";
} else {
$output .= "\n@media ({$type}-width:{$value}px){{$breakpointValue}}\n ";
}
}
}

Expand Down

0 comments on commit 906ea8b

Please sign in to comment.