Skip to content

Commit fe2a74e

Browse files
committed
Prevent doubling Sylius prefix in plugin name
1 parent ebaf9dc commit fe2a74e

File tree

5 files changed

+81
-25
lines changed

5 files changed

+81
-25
lines changed

bin/rename-plugin.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,26 @@ private function generateNameVariations(string $company, string $pluginName, boo
231231
];
232232
}
233233

234-
$syliusPlugin = 'Sylius' . $plugin;
234+
$hasSyliusPrefix = str_starts_with($pluginName, 'Sylius');
235+
$syliusPlugin = $hasSyliusPrefix ? $plugin : 'Sylius' . $plugin;
236+
$syliusPluginName = $hasSyliusPrefix ? $pluginName : 'Sylius' . $pluginName;
237+
235238
$fullClass = $company . $syliusPlugin;
236-
$extensionClass = $company . 'Sylius' . $pluginName . 'Extension';
239+
$extensionClass = $company . $syliusPluginName . 'Extension';
237240

238241
$companyKebab = $this->toKebabCase($company);
239242
$fullPluginKebab = $this->toKebabCase($syliusPlugin);
240243
$companySnake = $this->toSnakeCase($company);
244+
$pluginSnakeForDb = $hasSyliusPrefix ? $pluginSnake : 'sylius_' . $pluginSnake;
241245

242246
return [
243247
'company' => $company,
244248
'plugin' => $syliusPlugin,
245249
'fullClass' => $fullClass,
246250
'extensionClass' => $extensionClass,
247251
'package' => $companyKebab . '/' . $fullPluginKebab,
248-
'db' => $companySnake . '_sylius_' . $pluginSnake . '_plugin',
249-
'configKey' => $companySnake . '_sylius_' . $pluginSnake,
252+
'db' => $companySnake . '_' . $pluginSnakeForDb . '_plugin',
253+
'configKey' => $companySnake . '_' . $pluginSnakeForDb,
250254
];
251255
}
252256

@@ -382,6 +386,9 @@ private function updateComposerJson(SymfonyStyle $io, string $packageName, strin
382386
unset($composer['autoload-dev']['psr-4']['Tests\\Acme\\SyliusExamplePlugin\\']);
383387
$composer['autoload-dev']['psr-4']["Tests\\{$names['company']}\\{$names['plugin']}\\"] = ['tests/', 'tests/TestApplication/src/'];
384388

389+
unset($composer['scripts']['post-create-project-cmd']);
390+
unset($composer['scripts']['post-root-package-install']);
391+
385392
if ($dryRun) {
386393
$io->writeln('[DRY RUN] Would update composer.json with:');
387394
$io->writeln(' - name: ' . $packageName);

bin/show-success.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
echo PHP_EOL;
7+
echo " \033[42;30m DONE \033[0m Your plugin is ready!" . PHP_EOL;
8+
echo PHP_EOL;
9+
echo " \033[1mNext steps:\033[0m" . PHP_EOL;
10+
echo " 1. Start the server: \033[36msymfony serve -d\033[0m" . PHP_EOL;
11+
echo " 2. Open in browser: \033[36mhttps://127.0.0.1:8000\033[0m" . PHP_EOL;
12+
echo PHP_EOL;
13+
14+
unlink(__FILE__);

bin/validate-directory.php

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,57 @@
44
declare(strict_types=1);
55

66
$dirName = basename(dirname(__DIR__));
7+
$isSyliusOfficial = getenv('SYLIUS') === '1';
78

8-
if (!preg_match('/^[A-Z][a-zA-Z0-9]*Plugin$/', $dirName)) {
9-
fwrite(STDERR, "\n");
10-
fwrite(STDERR, " \033[41;37m ERROR \033[0m Directory name must end with 'Plugin' suffix\n");
11-
fwrite(STDERR, "\n");
12-
fwrite(STDERR, " Current: {$dirName}\n");
13-
fwrite(STDERR, " Expected: {$dirName}Plugin (or similar PascalCase name ending with Plugin)\n");
14-
fwrite(STDERR, "\n");
15-
fwrite(STDERR, " Example:\n");
16-
fwrite(STDERR, " composer create-project sylius/plugin-skeleton WishlistPlugin\n");
17-
fwrite(STDERR, "\n");
18-
19-
exit(1);
9+
if ($isSyliusOfficial) {
10+
if (!preg_match('/^[A-Z][a-zA-Z0-9]*Plugin$/', $dirName) || str_starts_with($dirName, 'Sylius')) {
11+
$hasPluginSuffix = str_ends_with($dirName, 'Plugin');
12+
13+
$suggestion = $dirName;
14+
if (str_starts_with($suggestion, 'Sylius')) {
15+
$suggestion = substr($suggestion, 6);
16+
}
17+
if (!$hasPluginSuffix) {
18+
$suggestion .= 'Plugin';
19+
}
20+
21+
fwrite(STDERR, "\n");
22+
fwrite(STDERR, " \033[41;37m ERROR \033[0m Official Sylius plugin name must match pattern: {Feature}Plugin\n");
23+
fwrite(STDERR, "\n");
24+
fwrite(STDERR, " Current: {$dirName}\n");
25+
fwrite(STDERR, " Expected: {$suggestion}\n");
26+
fwrite(STDERR, "\n");
27+
fwrite(STDERR, " Example:\n");
28+
fwrite(STDERR, " SYLIUS=1 composer create-project sylius/plugin-skeleton MailerLitePlugin\n");
29+
fwrite(STDERR, "\n");
30+
31+
exit(1);
32+
}
33+
} else {
34+
if (!preg_match('/^Sylius[A-Z][a-zA-Z0-9]*Plugin$/', $dirName)) {
35+
$hasSyliusPrefix = str_starts_with($dirName, 'Sylius');
36+
$hasPluginSuffix = str_ends_with($dirName, 'Plugin');
37+
38+
$suggestion = $dirName;
39+
if (!$hasSyliusPrefix) {
40+
$suggestion = 'Sylius' . $suggestion;
41+
}
42+
if (!$hasPluginSuffix) {
43+
$suggestion .= 'Plugin';
44+
}
45+
46+
fwrite(STDERR, "\n");
47+
fwrite(STDERR, " \033[41;37m ERROR \033[0m Community plugin name must match pattern: Sylius{Feature}Plugin\n");
48+
fwrite(STDERR, "\n");
49+
fwrite(STDERR, " Current: {$dirName}\n");
50+
fwrite(STDERR, " Expected: {$suggestion}\n");
51+
fwrite(STDERR, "\n");
52+
fwrite(STDERR, " Example:\n");
53+
fwrite(STDERR, " composer create-project sylius/plugin-skeleton SyliusWishlistPlugin\n");
54+
fwrite(STDERR, "\n");
55+
56+
exit(1);
57+
}
2058
}
2159

2260
unlink(__FILE__);

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@
7979
],
8080
"post-create-project-cmd": [
8181
"@php bin/rename-plugin.php",
82-
"@test-app-init"
82+
"@test-app-init",
83+
"git init -q",
84+
"git add -A",
85+
"git commit -q -m 'Initial commit'",
86+
"@php bin/show-success.php"
8387
],
8488
"database-reset": [
8589
"vendor/bin/console doctrine:database:drop --force --if-exists",
@@ -93,8 +97,7 @@
9397
],
9498
"test-app-init": [
9599
"@database-reset",
96-
"@frontend-clear",
97-
"echo '\nNow run:\n\n symfony serve -d\n'"
100+
"@frontend-clear"
98101
]
99102
}
100103
}

tests/TestApplication/.env

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
DATABASE_URL=mysql://root@127.0.0.1/acme_sylius_example_plugin_%kernel.environment%
2-
3-
BEHAT_BASE_URL="http://nginx/"
4-
5-
SYLIUS_TEST_APP_BUNDLES_PATH="tests/TestApplication/config/bundles.php"
6-
SYLIUS_TEST_APP_CONFIGS_TO_IMPORT="@AcmeSyliusExamplePlugin/tests/TestApplication/config/config.yaml"
7-
SYLIUS_TEST_APP_ROUTES_TO_IMPORT="@AcmeSyliusExamplePlugin/tests/TestApplication/config/routes.yaml"

0 commit comments

Comments
 (0)