Skip to content

Commit

Permalink
changing config version and name definition
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Oct 27, 2023
1 parent d84ce12 commit be389fe
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"php-di/invoker": "^2.3",
"php-di/invoker": "^2.3.4",
"php-di/php-di": "^7"
},
"require-dev": {
Expand Down
21 changes: 21 additions & 0 deletions src/Cli/AbstractCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ abstract class AbstractCli implements CliInterface
*/
public const TEMPLATE = '';

/**
* Output project name arg.
*
* @var string
*/
public const PROJECT_NAME_ARG = 'project_name';

/**
* Output theme name arg.
*
* @var string
*/
public const THEME_NAME_ARG = 'theme_name';

/**
* Output plugin name arg.
*
* @var string
*/
public const PLUGIN_NAME_ARG = 'plugin_name';

/**
* Construct Method.
*
Expand Down
26 changes: 0 additions & 26 deletions src/Config/ConfigCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function getCommandName(): string
public function getDefaultArgs(): array
{
return [
'name' => 'Boilerplate',
'version' => '1',
'routes_version' => '1',
];
}
Expand All @@ -63,20 +61,6 @@ public function getDoc(): array
return [
'shortdesc' => 'Create project config service class.',
'synopsis' => [
[
'type' => 'assoc',
'name' => 'name',
'description' => 'Define project name.',
'optional' => true,
'default' => $this->getDefaultArg('name'),
],
[
'type' => 'assoc',
'name' => 'version',
'description' => 'Define project version.',
'optional' => true,
'default' => $this->getDefaultArg('version'),
],
[
'type' => 'assoc',
'name' => 'routes_version',
Expand Down Expand Up @@ -109,8 +93,6 @@ public function __invoke(array $args, array $assocArgs)
$this->getIntroText($assocArgs);

// Get Props.
$name = $this->getArg($assocArgs, 'name');
$version = $this->getArg($assocArgs, 'version');
$routesVersion = $this->getArg($assocArgs, 'routes_version');

$className = $this->getClassShortName();
Expand All @@ -121,14 +103,6 @@ public function __invoke(array $args, array $assocArgs)
->renameNamespace($assocArgs)
->renameUse($assocArgs);

if (!empty($name)) {
$class->searchReplaceString($this->getArgTemplate('name'), $name);
}

if (!empty($version)) {
$class->searchReplaceString($this->getArgTemplate('version'), $version);
}

if (!empty($routesVersion)) {
$class->searchReplaceString($this->getArgTemplate('routes_version'), $routesVersion);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Config/ConfigExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConfigExample extends AbstractConfigData
*/
public static function getProjectName(): string
{
return '%name%';
return \wp_get_theme('', \dirname(__DIR__, 3))->get('TextDomain');
}

/**
Expand All @@ -37,7 +37,7 @@ public static function getProjectName(): string
*/
public static function getProjectVersion(): string
{
return '%version%';
return \wp_get_theme('', \dirname(__DIR__, 3))->get('Version');
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/Init/InitThemeCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public function getCommandName(): string
return 'theme';
}

/**
* Define default arguments.
*
* @return array<string, int|string|boolean>
*/
public function getDefaultArgs(): array
{
return [
AbstractCli::THEME_NAME_ARG => 'Boilerplate',
];
}

/**
* Get WP-CLI command doc.
*
Expand All @@ -85,6 +97,15 @@ public function getDoc(): array
{
return [
'shortdesc' => 'Kickstart your WordPress theme with this simple command.',
'synopsis' => [
[
'type' => 'assoc',
'name' => AbstractCli::THEME_NAME_ARG,
'description' => 'Define theme name.',
'optional' => true,
'default' => $this->getDefaultArg(AbstractCli::THEME_NAME_ARG),
],
],
'longdesc' => $this->prepareLongDesc("
## USAGE
Expand All @@ -107,6 +128,11 @@ public function __invoke(array $args, array $assocArgs)
$this->getIntroText();
}

$themeName = $this->getArg($assocArgs, AbstractCli::THEME_NAME_ARG);
if ($themeName) {
unset($assocArgs[AbstractCli::THEME_NAME_ARG]);
}

foreach (static::COMMANDS as $item) {
$label = $item['label'] ?? '';
$items = $item['items'] ?? [];
Expand All @@ -126,6 +152,7 @@ public function __invoke(array $args, array $assocArgs)
[
'groupOutput' => $type === 'blocks',
'introOutput' => false,
AbstractCli::PROJECT_NAME_ARG => $themeName,
]
));
}
Expand Down
7 changes: 7 additions & 0 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Mockery\MockInterface;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use WP_Theme;
use Yoast\WPTestUtils\BrainMonkey\TestCase;

class BaseTest extends TestCase
Expand Down Expand Up @@ -192,6 +193,12 @@ protected function set_up()

Functions\when('wp_nonce_field')->justReturn('nonce');

Functions\when('wp_get_theme')->justReturn(new class {
public function get( $header ) {
return 'test';
}
});

// Mock https://developer.wordpress.org/reference/functions/wp_is_json_media_type/ function
Functions\when('wp_is_json_media_type')->alias(function ($mediaType) {
static $cache = array();
Expand Down

0 comments on commit be389fe

Please sign in to comment.