Skip to content

Commit 1863287

Browse files
committed
[#1580] Allow to choose tools in the installer. Part 2.
1 parent 5a3b35d commit 1863287

14 files changed

Lines changed: 129 additions & 183 deletions

File tree

.github/workflows/vortex-test-installer.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ jobs:
3737
run: composer install
3838
working-directory: .vortex/installer
3939

40+
- name: Validate Composer configuration is normalized
41+
run: composer normalize --dry-run
42+
working-directory: .vortex/installer
43+
4044
- name: Check coding standards
4145
run: composer lint
4246
working-directory: .vortex/installer

.vortex/installer/composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
},
5151
"autoload-dev": {
5252
"psr-4": {
53-
"DrevOps\\VortexInstaller\\Tests\\": "tests",
54-
"AlexSkrypnyk\\File\\Tests\\": "vendor/alexskrypnyk/file/tests"
53+
"AlexSkrypnyk\\File\\Tests\\": "vendor/alexskrypnyk/file/tests",
54+
"DrevOps\\VortexInstaller\\Tests\\": "tests"
5555
},
5656
"classmap": [
5757
"tests"
@@ -94,8 +94,8 @@
9494
],
9595
"reset": "rm -Rf vendor vendor-bin",
9696
"test": "phpunit --no-coverage",
97+
"test-baseline": "UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall@baseline || UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall@baseline",
9798
"test-coverage": "php -d pcov.directory=. vendor/bin/phpunit",
98-
"test-fixtures": "UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall",
99-
"test-baseline": "UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall@baseline || UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall@baseline"
99+
"test-fixtures": "UPDATE_FIXTURES=1 phpunit --no-coverage --filter=testInstall"
100100
}
101101
}

.vortex/installer/src/Command/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class InstallCommand extends Command {
5656
*/
5757
protected function configure(): void {
5858
$this->setName('Vortex Installer');
59-
$this->setDescription('Install Vortex CLI from remote or local repository.');
59+
$this->setDescription('Install Vortex from remote or local repository.');
6060
$this->setHelp(<<<EOF
6161
Interactively install Vortex from the latest stable release into the current directory:
6262
php installer destination

.vortex/installer/src/Prompts/Handlers/MachineName.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

7-
use DrevOps\VortexInstaller\Utils\ComposerJson;
7+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
88
use DrevOps\VortexInstaller\Utils\Converter;
99
use DrevOps\VortexInstaller\Utils\Env;
1010
use DrevOps\VortexInstaller\Utils\File;
@@ -54,13 +54,13 @@ public function default(array $responses): null|string|bool|array {
5454
* {@inheritdoc}
5555
*/
5656
public function discover(): null|string|bool|array {
57-
$v1 = Env::getFromDotenv('VORTEX_PROJECT', $this->dstDir);
57+
$v = Env::getFromDotenv('VORTEX_PROJECT', $this->dstDir);
5858

59-
if (!empty($v1)) {
60-
return $v1;
59+
if (!empty($v)) {
60+
return $v;
6161
}
6262

63-
$v = ComposerJson::fromFile($this->dstDir . '/composer.json')?->getProperty('name');
63+
$v = JsonManipulator::fromFile($this->dstDir . '/composer.json')?->getProperty('name');
6464
if ($v && preg_match('/([^\/]+)\/(.+)/', (string) $v, $matches) && !empty($matches[2])) {
6565
return trim($matches[2]);
6666
}

.vortex/installer/src/Prompts/Handlers/Name.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

7-
use DrevOps\VortexInstaller\Utils\ComposerJson;
7+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
88
use DrevOps\VortexInstaller\Utils\Converter;
99
use DrevOps\VortexInstaller\Utils\File;
1010

@@ -50,7 +50,8 @@ public function default(array $responses): null|string|bool|array {
5050
* {@inheritdoc}
5151
*/
5252
public function discover(): null|string|bool|array {
53-
$v = ComposerJson::fromFile($this->dstDir . '/composer.json')?->getProperty('description');
53+
$v = JsonManipulator::fromFile($this->dstDir . '/composer.json')?->getProperty('description');
54+
5455
if ($v && preg_match('/Drupal \d+ .* of ([0-9a-zA-Z\- ]+)(\s?\.|for)/', (string) $v, $matches) && !empty($matches[1])) {
5556
return trim($matches[1]);
5657
}

.vortex/installer/src/Prompts/Handlers/Org.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

7-
use DrevOps\VortexInstaller\Utils\ComposerJson;
7+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
88
use DrevOps\VortexInstaller\Utils\Converter;
99
use DrevOps\VortexInstaller\Utils\File;
1010

@@ -53,7 +53,8 @@ public function default(array $responses): null|string|bool|array {
5353
* {@inheritdoc}
5454
*/
5555
public function discover(): null|string|bool|array {
56-
$v = ComposerJson::fromFile($this->dstDir . '/composer.json')?->getProperty('description');
56+
$v = JsonManipulator::fromFile($this->dstDir . '/composer.json')?->getProperty('description');
57+
5758
if ($v && preg_match('/Drupal \d+ .* of ([0-9a-zA-Z\- ]+) for ([0-9a-zA-Z\- ]+)/', (string) $v, $matches) && !empty($matches[2])) {
5859
return $matches[2];
5960
}

.vortex/installer/src/Prompts/Handlers/OrgMachineName.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

7-
use DrevOps\VortexInstaller\Utils\ComposerJson;
7+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
88
use DrevOps\VortexInstaller\Utils\Converter;
99
use DrevOps\VortexInstaller\Utils\File;
1010

@@ -53,7 +53,8 @@ public function default(array $responses): null|string|bool|array {
5353
* {@inheritdoc}
5454
*/
5555
public function discover(): null|string|bool|array {
56-
$v = ComposerJson::fromFile($this->dstDir . '/composer.json')?->getProperty('name');
56+
$v = JsonManipulator::fromFile($this->dstDir . '/composer.json')?->getProperty('name');
57+
5758
if ($v && preg_match('/([^\/]+)\/(.+)/', (string) $v, $matches) && !empty($matches[1])) {
5859
return $matches[1];
5960
}

.vortex/installer/src/Prompts/Handlers/Services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

77
use DrevOps\VortexInstaller\Utils\File;
8-
use Symfony\Component\Yaml\Yaml;
8+
use DrevOps\VortexInstaller\Utils\Yaml;
99

1010
class Services extends AbstractHandler {
1111

.vortex/installer/src/Prompts/Handlers/Tools.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

77
use AlexSkrypnyk\File\ExtendedSplFileInfo;
8-
use DrevOps\VortexInstaller\Utils\ComposerJson;
8+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
99
use DrevOps\VortexInstaller\Utils\File;
1010
use DrevOps\VortexInstaller\Utils\Strings;
1111
use DrevOps\VortexInstaller\Utils\Yaml;
@@ -67,8 +67,8 @@ public function discover(): null|string|bool|array {
6767

6868
$tools = [];
6969

70-
$cj = ComposerJson::fromFile($this->dstDir . '/composer.json');
71-
if ($cj instanceof ComposerJson) {
70+
$cj = JsonManipulator::fromFile($this->dstDir . '/composer.json');
71+
if ($cj instanceof JsonManipulator) {
7272
foreach (static::getToolDefinitions('tools') as $tool => $config) {
7373
if (isset($config['present']) && $config['present'] instanceof \Closure && $config['present']->bindTo($this)()) {
7474
$tools[] = $tool;
@@ -120,8 +120,8 @@ protected function processTool(string $name): void {
120120
// Remove dependencies from composer.json.
121121
if (isset($tool['composer.json']) && is_callable($tool['composer.json'])) {
122122
$composer_path = $this->tmpDir . '/composer.json';
123-
$cj = ComposerJson::fromFile($composer_path);
124-
if ($cj instanceof ComposerJson) {
123+
$cj = JsonManipulator::fromFile($composer_path);
124+
if ($cj instanceof JsonManipulator) {
125125
$tool['composer.json']($cj);
126126
file_put_contents($composer_path, $cj->getContents());
127127
}
@@ -186,7 +186,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
186186
File::contains($this->dstDir . '/composer.json', 'drupal/coder') ||
187187
File::contains($this->dstDir . '/composer.json', 'squizlabs/php_codesniffer');
188188
},
189-
'composer.json' => function (ComposerJson $cj): void {
189+
'composer.json' => function (JsonManipulator $cj): void {
190190
$cj->removeSubNode('require-dev', 'dealerdirect/phpcodesniffer-composer-installer');
191191
$cj->removeSubNode('require-dev', 'drupal/coder');
192192
$cj->removeSubNode('require-dev', 'squizlabs/php_codesniffer');
@@ -205,7 +205,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
205205
return File::contains($this->dstDir . '/composer.json', 'phpstan/phpstan') ||
206206
File::contains($this->dstDir . '/composer.json', 'mglaman/phpstan-drupal');
207207
},
208-
'composer.json' => function (ComposerJson $cj): void {
208+
'composer.json' => function (JsonManipulator $cj): void {
209209
$cj->removeSubNode('require-dev', 'phpstan/phpstan');
210210
$cj->removeSubNode('require-dev', 'mglaman/phpstan-drupal');
211211
},
@@ -222,7 +222,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
222222
'present' => function (): mixed {
223223
return File::contains($this->dstDir . '/composer.json', 'rector/rector');
224224
},
225-
'composer.json' => function (ComposerJson $cj): void {
225+
'composer.json' => function (JsonManipulator $cj): void {
226226
$cj->removeSubNode('require-dev', 'rector/rector');
227227
},
228228
'files' => ['rector.php'],
@@ -235,7 +235,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
235235
'present' => function (): mixed {
236236
return File::contains($this->dstDir . '/composer.json', 'phpmd/phpmd');
237237
},
238-
'composer.json' => function (ComposerJson $cj): void {
238+
'composer.json' => function (JsonManipulator $cj): void {
239239
$cj->removeSubNode('require-dev', 'phpmd/phpmd');
240240
},
241241
'files' => ['phpmd.xml'],
@@ -251,7 +251,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
251251
'present' => function (): mixed {
252252
return File::contains($this->dstDir . '/composer.json', 'phpunit/phpunit');
253253
},
254-
'composer.json' => function (ComposerJson $cj): void {
254+
'composer.json' => function (JsonManipulator $cj): void {
255255
$cj->removeSubNode('require-dev', 'phpunit/phpunit');
256256
$cj->removeProperty('autoload-dev.classmap');
257257
$cj->removeMainKeyIfEmpty('autoload-dev');
@@ -281,7 +281,7 @@ public static function getToolDefinitions(string $filter = 'all'): array {
281281
return File::contains($this->dstDir . '/composer.json', 'behat/behat') ||
282282
File::contains($this->dstDir . '/composer.json', 'drupal/drupal-extension');
283283
},
284-
'composer.json' => function (ComposerJson $cj): void {
284+
'composer.json' => function (JsonManipulator $cj): void {
285285
$cj->removeSubNode('require-dev', 'behat/behat');
286286
$cj->removeSubNode('require-dev', 'drupal/drupal-extension');
287287
$cj->removeSubNode('require-dev', 'dantleech/gherkin-lint');

.vortex/installer/src/Prompts/Handlers/Webroot.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DrevOps\VortexInstaller\Prompts\Handlers;
66

7-
use DrevOps\VortexInstaller\Utils\ComposerJson;
7+
use DrevOps\VortexInstaller\Utils\JsonManipulator;
88
use DrevOps\VortexInstaller\Utils\Env;
99
use DrevOps\VortexInstaller\Utils\File;
1010
use DrevOps\VortexInstaller\Utils\Validator;
@@ -63,15 +63,16 @@ public function default(array $responses): null|string|bool|array {
6363
* {@inheritdoc}
6464
*/
6565
public function discover(): null|string|bool|array {
66-
$v1 = Env::getFromDotenv('WEBROOT', $this->dstDir);
67-
if (!empty($v1)) {
68-
return $v1;
66+
$v = Env::getFromDotenv('WEBROOT', $this->dstDir);
67+
68+
if (!empty($v)) {
69+
return $v;
6970
}
7071

71-
$v2 = ComposerJson::fromFile($this->dstDir . '/composer.json')?->getProperty('extra.drupal-scaffold.locations.web-root');
72+
$v = JsonManipulator::fromFile($this->dstDir . '/composer.json')?->getProperty('extra.drupal-scaffold.locations.web-root');
7273

73-
if (!empty($v2)) {
74-
return $v2;
74+
if (!empty($v)) {
75+
return $v;
7576
}
7677

7778
return NULL;

0 commit comments

Comments
 (0)