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 4c85c35 commit f89b3b3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 61 deletions.
3 changes: 1 addition & 2 deletions src/Init/InitAllCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ public function getDoc(): array
/* @phpstan-ignore-next-line */
public function __invoke(array $args, array $assocArgs)
{
$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];

$assocArgs = $this->prepareArgs($assocArgs);
$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];

if (!$groupOutput) {
$this->getIntroText();
Expand Down
51 changes: 4 additions & 47 deletions src/Init/InitBlocksCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,6 @@ public function getDoc(): array
{
return [
'shortdesc' => 'Create all files for blocks to work.',
'synopsis' => [
[
'type' => 'flag',
'name' => 'use_all',
'description' => 'Output all items to your project.',
'optional' => true,
'default' => false,
],
],
'longdesc' => $this->prepareLongDesc("
This command will copy all initial blocks, components, manifests and service classes to you project in order to start using block editor.
Expand All @@ -145,46 +136,18 @@ public function getDoc(): array
/* @phpstan-ignore-next-line */
public function __invoke(array $args, array $assocArgs)
{
$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];
$all = $assocArgs['use_all'] ?? false;

$assocArgs = $this->prepareArgs($assocArgs);
$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];

if (!$groupOutput) {
$this->getIntroText();
$this->cliLog("%w╭\n│ %nCreating block editor files", 'mixed');
}

$this->cliLog("%w╭\n│ %nCreating block editor files", 'mixed');

$commands = static::COMMANDS;

if ($all) {
$commands = [];
$type = \getenv('ES_TEST') ? 'test' : 'default';

foreach (\array_keys(static::COMMANDS) as $command) {
switch ($command) {
case UseBlockCli::class:
$commands[$command][$type] = $this->getFolderItems(Helpers::getProjectPaths('blocksSourceCustom'));
break;
case UseComponentCli::class:
$commands[$command][$type] = $this->getFolderItems(Helpers::getProjectPaths('blocksSourceComponents'));
break;
case UseVariationCli::class:
$commands[$command][$type] = $this->getFolderItems(Helpers::getProjectPaths('blocksSourceVariations'));
break;
default:
$commands[$command] = [];
break;
}
}
}

$this->getInitBlocks($assocArgs, $commands);

$this->cliLog('', 'w');
$this->getInitBlocks($assocArgs, static::COMMANDS);

if (!$groupOutput) {
$this->cliLog('', 'w');
$this->cliLogAlert('Files copied! Run `npm start` to build all the assets.\n\nHappy developing!', 'success', \__('Ready to go!', 'eightshift-libs'));
}
}
Expand All @@ -206,23 +169,17 @@ private function getInitBlocks(array $assocArgs, array $commands): void
if ($items) {
$innerItems = $items['default'];

if (\getenv('ES_TEST')) {
$innerItems = $items['test'];
}

$class->__invoke([], \array_merge(
$assocArgs,
[
'name' => \implode(",", $innerItems),
self::ARG_GROUP_OUTPUT => true,
'checkDependency' => false,
]
));
} else {
$class->__invoke([], \array_merge(
$assocArgs,
[
self::ARG_GROUP_OUTPUT => true,
'checkDependency' => false,
]
));
Expand Down
10 changes: 1 addition & 9 deletions src/Init/InitThemeCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function __invoke(array $args, array $assocArgs)
foreach (static::COMMANDS as $item) {
$label = $item['label'] ?? '';
$items = $item['items'] ?? [];
$type = $item['type'] ?? '';

if ($label) {
$this->cliLog($label, 'C');
Expand All @@ -134,16 +133,9 @@ public function __invoke(array $args, array $assocArgs)
$reflectionClass = new ReflectionClass($className);
$class = $reflectionClass->newInstanceArgs([$this->commandParentName]);

$class->__invoke([], \array_merge(
$assocArgs,
[
self::ARG_GROUP_OUTPUT => $type === 'blocks',
]
));
$class->__invoke([], $assocArgs);
}
}

$this->cliLog("\n");
}

if (!$groupOutput) {
Expand Down
5 changes: 2 additions & 3 deletions src/Init/InitThemeSetupCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public function __invoke(array $args, array $assocArgs)
{
$assocArgs = $this->prepareSetupArgs($assocArgs);

$assocArgs['actionOutput'] = 'file created';
$assocArgs[self::ARG_GROUP_OUTPUT] = true;
$groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT];

$this->getIntroText();

Expand Down Expand Up @@ -160,7 +159,7 @@ public function __invoke(array $args, array $assocArgs)
WP_CLI::runcommand('theme activate ' . $assocArgs[self::ARG_TEXTDOMAIN]);
$this->cliLog('--------------------------------------------------', 'C');
$this->cliLog("Installing theme service classes", 'C');
WP_CLI::runcommand('boilerplate init theme --group_output=true');
WP_CLI::runcommand("boilerplate init theme --{$groupOutput}=true");
$this->cliLog('--------------------------------------------------', 'C');
$this->cliLog("Building the new theme assets", 'C');
WP_CLI::runcommand("eval 'shell_exec(\"cd {$newDestionation} && npm run build\");'");
Expand Down

0 comments on commit f89b3b3

Please sign in to comment.