Skip to content

Commit

Permalink
initi
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed May 14, 2024
1 parent fbf188d commit 8a3e496
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 43 deletions.
21 changes: 20 additions & 1 deletion src/Cli/AbstractCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public function prepareArgs(array $args = []): array

if (isset($args[self::ARG_SKIP_EXISTING])) {
$args[self::ARG_SKIP_EXISTING] = filter_var($args[self::ARG_SKIP_EXISTING], FILTER_VALIDATE_BOOLEAN);

}

return \array_merge(
[
self::ARG_NAMESPACE => $namespace,
Expand Down Expand Up @@ -1029,4 +1029,23 @@ public function convertToNamespace(string $name): string

return $namespace;
}

/**
* Run CLI command.
*
* @param string $commandClass Command class to run.
* @param string $commandParentName Parent name of the command.
* @param array<string, mixed> $args Arguments to pass.
*
* @return void
*/
public function runCliCommand(string $commandClass, string $commandParentName, array $args): void
{
$reflectionClass = new ReflectionClass($commandClass);
$class = $reflectionClass->newInstanceArgs([$commandParentName]);

$class->__invoke([], array_merge(
$args,
));
}
}
10 changes: 5 additions & 5 deletions src/Init/InitAllCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use EightshiftLibs\Cli\AbstractCli;
use EightshiftLibs\Cli\Cli;
use EightshiftLibs\Cli\ParentGroups\CliInit;
use ReflectionClass;

/**
* Class InitAllCli
Expand Down Expand Up @@ -78,10 +77,11 @@ public function __invoke(array $args, array $assocArgs)
);

foreach ($commands as $item) {
$reflectionClass = new ReflectionClass($item);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

$class->__invoke([], $assocArgs);
$this->runCliCommand(
$item,
$this->commandParentName,
$assocArgs
);
}

if (!$groupOutput) {
Expand Down
39 changes: 21 additions & 18 deletions src/Init/InitBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use EightshiftLibs\Blocks\UseWrapperCli;
use EightshiftLibs\Cli\AbstractCli;
use EightshiftLibs\Cli\ParentGroups\CliInit;
use EightshiftLibs\Helpers\Helpers;
use ReflectionClass;

/**
* Class InitBlocksCli
Expand Down Expand Up @@ -142,24 +140,29 @@ public function __invoke(array $args, array $assocArgs)
private function getInitBlocks(array $assocArgs, array $commands): void
{
foreach ($commands as $className => $items) {
$reflectionClass = new ReflectionClass($className);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

if ($items) {
$class->__invoke([], \array_merge(
$assocArgs,
[
'name' => \implode(",", $items),
'checkDependency' => false,
]
));
$this->runCliCommand(
$className,
$this->commandParentName,
\array_merge(
$assocArgs,
[
'name' => \implode(",", $items),
'checkDependency' => false,
]
)
);
} else {
$class->__invoke([], \array_merge(
$assocArgs,
[
'checkDependency' => false,
]
));
$this->runCliCommand(
$className,
$this->commandParentName,
\array_merge(
$assocArgs,
[
'checkDependency' => false,
]
)
);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Init/InitPluginCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use EightshiftLibs\Cli\ParentGroups\CliInit;
use EightshiftLibs\Config\ConfigPluginCli;
use EightshiftLibs\Main\MainCli;
use ReflectionClass;

/**
* Class InitPluginCli
Expand Down Expand Up @@ -85,10 +84,11 @@ public function __invoke(array $args, array $assocArgs)
$this->getIntroText($assocArgs);

foreach (static::COMMANDS as $item) {
$reflectionClass = new ReflectionClass($item);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

$class->__invoke([], $assocArgs);
$this->runCliCommand(
$item,
$this->commandParentName,
$assocArgs
);
}

if (!$groupOutput) {
Expand Down
10 changes: 5 additions & 5 deletions src/Init/InitProjectCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use EightshiftLibs\GitIgnore\GitIgnoreCli;
use EightshiftLibs\Readme\ReadmeCli;
use EightshiftLibs\Setup\SetupCli;
use ReflectionClass;
use WP_CLI;

/**
Expand Down Expand Up @@ -90,10 +89,11 @@ public function __invoke(array $args, array $assocArgs)
$this->getIntroText($assocArgs);

foreach (static::COMMANDS as $item) {
$reflectionClass = new ReflectionClass($item);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

$class->__invoke([], $assocArgs);
$this->runCliCommand(
$item,
$this->commandParentName,
$assocArgs
);
}

if (!$groupOutput) {
Expand Down
26 changes: 18 additions & 8 deletions src/Init/InitThemeCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use EightshiftLibs\Enqueue\Blocks\EnqueueBlocksCli;
use EightshiftLibs\Enqueue\Theme\EnqueueThemeCli;
use EightshiftLibs\Main\MainCli;
use ReflectionClass;
use WP_CLI;

/**
* Class InitThemeCli
Expand Down Expand Up @@ -102,19 +100,31 @@ public function __invoke(array $args, array $assocArgs)
{
$assocArgs = $this->prepareArgs($assocArgs);

$assocArgs[self::ARG_GROUP_OUTPUT] = false;

$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];

$this->getIntroText($assocArgs);

foreach (static::COMMANDS as $item) {
$reflectionClass = new ReflectionClass($item);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

$class->__invoke([], $assocArgs);
$this->runCliCommand(
$item,
$this->commandParentName,
array_merge(
$assocArgs,
[
self::ARG_GROUP_OUTPUT => true,
]
)
);
}

if ($groupOutput) {
$this->cliLogAlert('All the files have been copied, you can start working on your awesome theme!', 'success', \__('Ready to go!', 'eightshift-libs'));
if (!$groupOutput) {
$this->cliLogAlert(
'All the files have been copied, you can start working on your awesome theme!',
'success',
\__('Ready to go!', 'eightshift-libs')
);
}
}
}
2 changes: 1 addition & 1 deletion src/Init/InitThemeSetupCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function __invoke(array $args, array $assocArgs)
$this->cliLog("Activating new theme", 'C');
WP_CLI::runcommand('theme activate ' . $assocArgs[self::ARG_TEXTDOMAIN]);
$this->cliLog('--------------------------------------------------', 'C');
$this->cliLog("Installing theme service classes", 'C');
$this->cliLog("Installing theme service classes and blocks", 'C');
WP_CLI::runcommand(\sprintf("boilerplate init theme --%s=true", self::ARG_GROUP_OUTPUT));
$this->cliLog('--------------------------------------------------', 'C');
$this->cliLog("Building the new theme assets", 'C');
Expand Down

0 comments on commit 8a3e496

Please sign in to comment.