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

Feature/cli #308

Merged
merged 52 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7146824
Feature/refactor (#307)
iruzevic Jul 5, 2022
2a0de11
updating comments
iruzevic Jul 5, 2022
ed53dc6
updating command desc
iruzevic Jul 5, 2022
94b660f
adding variation to init setup
iruzevic Jul 5, 2022
07c96b3
adding init blocks all command
iruzevic Jul 5, 2022
7cae8e2
adding init all command
iruzevic Jul 5, 2022
113c9ff
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 6, 2022
155d39b
Apply suggestions from code review
iruzevic Jul 6, 2022
a2f5261
Update src/Blocks/UseComponentCli.php
iruzevic Jul 6, 2022
7516fd9
Update src/Blocks/UseGlobalAssetsCli.php
iruzevic Jul 6, 2022
e448233
Update tests/WpCli/WpCliTest.php
iruzevic Jul 6, 2022
1ce0c6a
Update src/Cli/ParentGroups/CliBoilerplate.php
iruzevic Jul 6, 2022
d26d0e2
Update src/GitIgnore/GitIgnoreCli.php
iruzevic Jul 6, 2022
f61ad22
Update src/Helpers/StoreTrait.php
iruzevic Jul 6, 2022
dae9649
Update tests/Helpers.php
iruzevic Jul 6, 2022
481f2ae
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
7fa0cb3
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
9a5d562
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
573e180
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
e5f1cf7
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
22b8ebf
Update src/Init/InitThemeCli.php
iruzevic Jul 6, 2022
2a37132
removing build and ci-exclude functionality
iruzevic Jul 6, 2022
6ae212a
renaming blocks command prefix
iruzevic Jul 6, 2022
cccee93
updating tests
iruzevic Jul 6, 2022
3a3d569
updating tests
iruzevic Jul 6, 2022
0b14ff5
updating docs for new subcommands
iruzevic Jul 6, 2022
5405092
fixing failing i18n command
iruzevic Jul 6, 2022
4133ae0
fixing wrong indentation
iruzevic Jul 6, 2022
0956525
renaming command names from _ to -
iruzevic Jul 6, 2022
f49a954
Update src/ConfigProject/ConfigProjectCli.php
iruzevic Jul 6, 2022
a1d46ed
fixing tests
iruzevic Jul 6, 2022
93639ba
fixing tests
iruzevic Jul 6, 2022
7b95c17
updating cli command names
iruzevic Jul 7, 2022
081d31b
fixing tests
iruzevic Jul 7, 2022
3c11fa6
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 7, 2022
80ca3c2
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 7, 2022
e614b0e
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 7, 2022
f9aa9ed
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 7, 2022
16e97eb
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 7, 2022
3cfc457
Update src/Cli/AbstractCli.php
iruzevic Jul 7, 2022
731c030
Update src/Cli/README.md
iruzevic Jul 7, 2022
2e3ec0c
Update src/Init/InitBlocksCli.php
iruzevic Jul 7, 2022
30150ff
Update src/Init/InitBlocksCli.php
iruzevic Jul 7, 2022
a7608cf
Update src/Blocks/UseBlockCli.php
iruzevic Jul 7, 2022
4a4618c
Update src/Blocks/UseComponentCli.php
iruzevic Jul 7, 2022
3efe570
Update src/Blocks/AbstractBlocksCli.php
iruzevic Jul 8, 2022
38f8b3c
Update src/Blocks/UseAssetsCli.php
iruzevic Jul 8, 2022
71409c6
Update src/Init/InitBlocksCli.php
iruzevic Jul 8, 2022
896e1bc
Update src/Blocks/BlocksCli.php
iruzevic Jul 8, 2022
fd7a2ae
Update src/Blocks/UseComponentCli.php
iruzevic Jul 8, 2022
0e8efff
Update src/CustomPostType/PostTypeCli.php
iruzevic Jul 8, 2022
134bff5
Update src/CustomTaxonomy/TaxonomyCli.php
iruzevic Jul 8, 2022
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
23 changes: 0 additions & 23 deletions bin/cli.php

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"brain/monkey": "^2.6",
"captainhook/captainhook": "^5.10",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"infinum/eightshift-coding-standards": "^1.5",
"infinum/eightshift-coding-standards": "^1.6",
"pestphp/pest": "^1.2",
"php-stubs/wordpress-stubs": "^5.9",
"phpunit/phpunit": "^9.5",
Expand Down
10 changes: 10 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@
<property name="ignoreComments" value="true" />
</properties>
</rule>

<!-- Add additional extending CLI classes. -->
<rule ref="Eightshift.Commenting.FunctionComment">
<properties>
<property name="allowedExtendedClasses" type="array">
<element value="AbstractCli"/>
<element value="AbstractBlocksCli"/>
</property>
</properties>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</testsuite>
</testsuites>
<php>
<env name="ES_TEST" value="true" force="true" />
</php>
<env name="ES_TEST" value="true" force="true" />
</php>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
Expand Down
41 changes: 28 additions & 13 deletions src/AdminMenus/AbstractAdminMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,37 @@ abstract class AbstractAdminMenu implements ServiceInterface, RenderableBlockInt
*/
public function register(): void
{
\add_action(
'admin_menu',
function () {
\add_menu_page(
$this->getTitle(),
$this->getMenuTitle(),
$this->getCapability(),
$this->getMenuSlug(),
[$this, 'processAdminMenu'],
$this->getIcon(),
$this->getPosition()
);
}
\add_action('admin_menu', [$this, 'callback'], $this->getPriorityOrder());
}

/**
* Return action callback method.
*
* @return void
*/
public function callback(): void
{
\add_menu_page(
$this->getTitle(),
$this->getMenuTitle(),
$this->getCapability(),
$this->getMenuSlug(),
[$this, 'processAdminMenu'],
$this->getIcon(),
$this->getPosition()
);
}

/**
* Return hook priority order.
*
* @return integer
*/
public function getPriorityOrder(): int
{
return 10;
}

/**
* Process the admin menu attributes and prepare rendering.
*
Expand Down
35 changes: 6 additions & 29 deletions src/AdminMenus/AdminMenuCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@

use EightshiftLibs\Cli\AbstractCli;
use EightshiftLibs\Cli\ParentGroups\CliCreate;
use EightshiftLibs\Helpers\Components;

/**
* Class AdminMenuCli
*/
class AdminMenuCli extends AbstractCli
{
/**
* Output dir relative path.
*
* @var string
*/
public const OUTPUT_DIR = 'src' . \DIRECTORY_SEPARATOR . 'AdminMenus';

/**
* Get WPCLI command parent name
*
Expand All @@ -42,26 +36,7 @@ public function getCommandParentName(): string
*/
public function getCommandName(): string
{
return 'admin_menu';
}

/**
* Define default develop props.
*
* @param string[] $args WPCLI eval-file arguments.
*
* @return array<string, int|string|boolean>
*/
public function getDevelopArgs(array $args): array
{
return [
'title' => 'Test Title',
'menu_title' => 'Test Menu Title',
'capability' => 'test_edit_posts',
'menu_slug' => 'test_title',
'menu_icon' => 'dashicons-admin-media',
'menu_position' => 50,
];
return 'admin-menu';
}

/**
Expand Down Expand Up @@ -138,7 +113,7 @@ public function getDoc(): array
## EXAMPLES

# Create service class:
$ wp boilerplate {$this->getCommandParentName()} {$this->getCommandName()} --title='Content' --menu_title='content' --capability='edit_posts' --menu_slug='es-content'
dingo-d marked this conversation as resolved.
Show resolved Hide resolved
$ wp {$this->commandParentName} {$this->getCommandParentName()} {$this->getCommandName()} --title='Content' --menu_title='content' --capability='edit_posts' --menu_slug='es-content'

## RESOURCES

Expand All @@ -151,6 +126,8 @@ public function getDoc(): array
/* @phpstan-ignore-next-line */
public function __invoke(array $args, array $assocArgs)
{
$this->getIntroText($assocArgs);

// Get Arguments.
$title = $this->getArg($assocArgs, 'title');
$menuTitle = $this->getArg($assocArgs, 'menu_title');
Expand Down Expand Up @@ -183,6 +160,6 @@ public function __invoke(array $args, array $assocArgs)
}

// Output final class to new file/folder and finish.
$class->outputWrite(static::OUTPUT_DIR, $className, $assocArgs);
$class->outputWrite(Components::getProjectPaths('srcDestination', 'AdminMenus'), "{$className}.php", $assocArgs);
}
}
38 changes: 8 additions & 30 deletions src/AdminMenus/AdminReusableBlocksMenuCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@

use EightshiftLibs\Cli\AbstractCli;
use EightshiftLibs\Cli\ParentGroups\CliCreate;
use EightshiftLibs\Helpers\Components;

/**
* Class AdminReusableBlocksMenuCli
*/
class AdminReusableBlocksMenuCli extends AbstractCli
{
/**
* Output dir relative path.
*
* @var string
*/
public const OUTPUT_DIR = 'src' . \DIRECTORY_SEPARATOR . 'AdminMenus';

/**
* Get WPCLI command parent name
*
Expand All @@ -42,25 +36,7 @@ public function getCommandParentName(): string
*/
public function getCommandName(): string
{
return 'admin_reusable_blocks_menu';
}

/**
* Define default develop props.
*
* @param string[] $args WPCLI eval-file arguments.
*
* @return array<string, int|string|boolean>
*/
public function getDevelopArgs(array $args): array
{
return [
'title' => 'Test Reusable Blocks',
'menu_title' => 'Test Reusable Blocks',
'capability' => 'test_edit_posts',
'menu_icon' => 'dashicons-editor-generic',
'menu_position' => 100,
];
return 'admin-reusable-blocks-menu';
}

/**
Expand Down Expand Up @@ -94,14 +70,14 @@ public function getDoc(): array
'name' => 'title',
'description' => 'The text to be displayed in the title tags of the page when the menu is selected.',
'optional' => true,
'default' => 'Reusable Blocks',
'default' => $this->getDefaultArg('title'),
],
[
'type' => 'assoc',
'name' => 'menu_title',
'description' => 'The text to be used for the menu.',
'optional' => true,
'default' => 'Reusable Blocks',
'default' => $this->getDefaultArg('menu_title'),
],
[
'type' => 'assoc',
Expand Down Expand Up @@ -133,7 +109,7 @@ public function getDoc(): array
## EXAMPLES

# Create service class:
$ wp boilerplate {$this->getCommandParentName()} {$this->getCommandName()}
$ wp {$this->commandParentName} {$this->getCommandParentName()} {$this->getCommandName()}

## RESOURCES

Expand All @@ -146,6 +122,8 @@ public function getDoc(): array
/* @phpstan-ignore-next-line */
public function __invoke(array $args, array $assocArgs)
{
$this->getIntroText($assocArgs);

// Get Arguments.
$title = $this->getArg($assocArgs, 'title');
$menuTitle = $this->getArg($assocArgs, 'menu_title');
Expand Down Expand Up @@ -176,6 +154,6 @@ public function __invoke(array $args, array $assocArgs)
}

// Output final class to new file/folder and finish.
$class->outputWrite(static::OUTPUT_DIR, $className, $assocArgs);
$class->outputWrite(Components::getProjectPaths('srcDestination', 'AdminMenus'), "{$className}.php", $assocArgs);
}
}
40 changes: 8 additions & 32 deletions src/AdminMenus/AdminSubMenuCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@

use EightshiftLibs\Cli\AbstractCli;
use EightshiftLibs\Cli\ParentGroups\CliCreate;
use EightshiftLibs\Helpers\Components;

/**
* Class AdminSubMenuCli
*/
class AdminSubMenuCli extends AbstractCli
{
/**
* Output dir relative path.
*
* @var string
*/
public const OUTPUT_DIR = 'src' . \DIRECTORY_SEPARATOR . 'AdminMenus';

/**
* Get WPCLI command parent name
*
Expand All @@ -42,25 +36,7 @@ public function getCommandParentName(): string
*/
public function getCommandName(): string
{
return 'admin_sub_menu';
}

/**
* Define default develop props.
*
* @param string[] $args WPCLI eval-file arguments.
*
* @return array<string, int|string|boolean>
*/
public function getDevelopArgs(array $args): array
{
return [
'parent_slug' => 'test-example-menu-slug',
'title' => 'Test Admin Title',
'menu_title' => 'Test Admin Sub Menu Title',
'capability' => 'test_edit_posts',
'menu_slug' => 'test_admin_title',
];
return 'admin-sub-menu';
}

/**
Expand Down Expand Up @@ -128,7 +104,7 @@ public function getDoc(): array
## EXAMPLES

# Create service class:
$ wp boilerplate {$this->getCommandParentName()} {$this->getCommandName()} --parent_slug='shop' --title='Content' --menu_title='content' --capability='edit_posts' --menu_slug='es-content'
$ wp {$this->commandParentName} {$this->getCommandParentName()} {$this->getCommandName()} --parent_slug='shop' --title='Content' --menu_title='content' --capability='edit_posts' --menu_slug='es-content'

## RESOURCES

Expand All @@ -141,6 +117,8 @@ public function getDoc(): array
/* @phpstan-ignore-next-line */
public function __invoke(array $args, array $assocArgs)
{
$this->getIntroText($assocArgs);

// Get Arguments.
$parentSlug = $this->getArg($assocArgs, 'parent_slug');
$title = $this->getArg($assocArgs, 'title');
Expand All @@ -153,7 +131,7 @@ public function __invoke(array $args, array $assocArgs)
$className = $className . $this->getClassShortName();

// Read the template contents, and replace the placeholders with provided variables.
$class = $this->getExampleTemplate(__DIR__, $this->getClassShortName())
$this->getExampleTemplate(__DIR__, $this->getClassShortName())
->renameClassNameWithPrefix($this->getClassShortName(), $className)
->renameNamespace($assocArgs)
->renameUse($assocArgs)
Expand All @@ -162,9 +140,7 @@ public function __invoke(array $args, array $assocArgs)
->searchReplaceString($this->getArgTemplate('title'), $title)
->searchReplaceString($this->getArgTemplate('menu_title'), $menuTitle)
->searchReplaceString($this->getArgTemplate('capability'), $capability)
->searchReplaceString($this->getArgTemplate('menu_slug'), $menuSlug);

// Output final class to new file/folder and finish.
$class->outputWrite(static::OUTPUT_DIR, $className, $assocArgs);
->searchReplaceString($this->getArgTemplate('menu_slug'), $menuSlug)
->outputWrite(Components::getProjectPaths('srcDestination', 'AdminMenus'), "{$className}.php", $assocArgs);
}
}
Loading