Skip to content

Commit

Permalink
Merge pull request #636 from lucatume/v4-wpcli-change-path
Browse files Browse the repository at this point in the history
feat(Module/WPCLI) add changePath method
  • Loading branch information
lucatume authored Sep 19, 2023
2 parents 68166b4 + 20658f4 commit 14230c8
Show file tree
Hide file tree
Showing 25 changed files with 5,175 additions and 1,257 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Added

- Allow changing path in the WPCLI module using the `changeWpcliPath` method.

## [4.0.2] 2023-09-18;

### Fixed

- Exclude some WooCommerce global values and static attributes from backup to avoid fatals.
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ update_sqlite_plugin:
docs_serve:
mkdocs serve -a 0.0.0.0:8000

docs_api_update:
php bin/extract-api.php "lucatume\WPBrowser\Module\WPBrowser" "docs/modules/WPBrowser.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPCLI" "docs/modules/WPCLI.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPDb" "docs/modules/WPDb.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPFilesystem" "docs/modules/WPFilesystem.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPLoader" "docs/modules/WPLoader.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPQueries" "docs/modules/WPQueries.md"
php bin/extract-api.php "lucatume\WPBrowser\Module\WPWebDriver" "docs/modules/WPWebDriver.md"
.PHONY: docs_api_update

wordpress_install:
php bin/setup-wp.php

Expand Down
44 changes: 38 additions & 6 deletions bin/extract-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_once dirname(__DIR__) . '/vendor/autoload.php';

$class = $argv[1];
$destFile = $argv[2];

if (!class_exists($class)) {
throw new \InvalidArgumentException("Class $class does not exist.");
Expand Down Expand Up @@ -49,27 +50,58 @@

$descriptionLines = [];

foreach ($textLines as $line) {
$line = str_starts_with($line,' ') ? substr($line, 1) : $line;
foreach ($textLines as $k => $line) {
$line = str_starts_with($line, ' ') ? substr($line, 1) : $line;

if (str_starts_with($line, '@example') || str_starts_with($line, '@see') || str_starts_with($line, '@link')) {
break;
continue;
}

if (str_starts_with($line, '@')) {
break;
}

if (str_contains($line, '```')) {
$line = trim($line);
}

$descriptionLines[] = $line;

if (str_contains($line, '```php')) {
if (isset($textLines[$k + 1]) && !str_contains($textLines[$k + 1], '<?php')) {
$descriptionLines[] = '<?php';
}
}
}

return sprintf(
'* `%s(%s)` : `%s`%s' . PHP_EOL,
"#### %s\nSignature: `%s(%s)` : `%s`%s",
$m->getName(),
$m->getName(),
$parametersString,
$returnType,
count($descriptionLines) ? " \n\t" . implode("\n\t", $descriptionLines) : ''
count($descriptionLines) ? " \n\n" . implode("\n", $descriptionLines) : ''
);
}, $apiClassMethods);

array_map(fn(string $m) => print($m . PHP_EOL), $methods);
$methodsMarkdown = array_map(fn(string $m) => PHP_EOL . $m, $methods);

$destFileLines = file($destFile);

// Remove any content between the `<!-- methods -->` and `<!-- /methods -->` markers.
$methodsStart = array_search('<!-- methods -->' . PHP_EOL, $destFileLines, true);
$methodsEnd = array_search('<!-- /methods -->' . PHP_EOL, $destFileLines, true);
$methodsLines = array_merge(
array_slice($destFileLines, 0, $methodsStart + 1),
array_slice($destFileLines, $methodsEnd)
);

// Insert the methods markdown between the `<!-- methods -->` and `<!-- /methods -->` markers.
$methodsStart = array_search('<!-- methods -->' . PHP_EOL, $destFileLines, true);
$methodsEnd = array_search('<!-- /methods -->' . PHP_EOL, $destFileLines, true);
$methodsLines = array_merge(
array_slice($destFileLines, 0, $methodsStart + 1),
$methodsMarkdown,
array_slice($destFileLines, $methodsEnd)
);
file_put_contents($destFile, implode('', $methodsLines));
Loading

0 comments on commit 14230c8

Please sign in to comment.