diff --git a/install-scripts/ScriptHelpers.php b/composer-scripts/ScriptHelpers.php similarity index 89% rename from install-scripts/ScriptHelpers.php rename to composer-scripts/ScriptHelpers.php index 90701f0..a1ec1d3 100644 --- a/install-scripts/ScriptHelpers.php +++ b/composer-scripts/ScriptHelpers.php @@ -59,9 +59,11 @@ public static function error(string $message): int|false return fwrite(STDERR, self::ANSI_RED . $message . self::ANSI_CLOSE . PHP_EOL); } - public static function replaceText(string $subject, string $pattern, string $replacement): string + public static function replaceFileText(string $filePath, string $pattern, string $replacement): void { - return preg_replace($pattern, $replacement, $subject); + $fileContent = file_get_contents($filePath); + $fileContent = preg_replace($pattern, $replacement, $fileContent); + file_put_contents($filePath, $fileContent); } public static function kebabCase(string $string) diff --git a/composer-scripts/post-create-project.php b/composer-scripts/post-create-project.php new file mode 100644 index 0000000..72f535b --- /dev/null +++ b/composer-scripts/post-create-project.php @@ -0,0 +1,59 @@ + true, +]); + +Console::output("Great! We'll use the name: $projectName"); + +$suggestedProjectSlug = ScriptHelpers::kebabCase($projectName); + +$projectSlugPrompt = Console::prompt("Customize the project slug? This controls the DDEV URL, etc.", [ + 'default' => $suggestedProjectSlug, +]); + +$projectSlug = !empty(trim($projectSlugPrompt)) ? ScriptHelpers::kebabCase($projectSlugPrompt) : $suggestedProjectSlug; + +ScriptHelpers::success("Great! We'll use $projectSlug"); + +/** + * Update DDEV config + */ + +ScriptHelpers::replaceFileText( + filePath: "$cwd/.ddev/config.yaml", + pattern: "/name:\s+craft-starter/", + replacement: "name: $projectSlug", +); + +/** + * Update project config + */ + +ScriptHelpers::replaceFileText( + filePath: "$cwd/config/project/project.yaml", + pattern: "/Viget Craft Starter/", + replacement: "$projectName", +); + +ScriptHelpers::replaceFileText( + filePath: "$cwd/config/project/siteGroups/805d8826-faed-4186-9b88-f509eb9b07e6.yaml", + pattern: "/Viget Craft Starter/", + replacement: "$projectName", +); + +ScriptHelpers::replaceFileText( + filePath: "$cwd/config/project/sites/default--35b563a0-4662-40b9-b885-a8450a2868d9.yaml", + pattern: "/Viget Craft Starter/", + replacement: "$projectName", +); diff --git a/composer.json b/composer.json index 465dcff..511dac3 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "scripts": { "post-create-project-cmd": [ "@php -r \"file_exists('.env') || copy('.env.example.dev', '.env');\"", - "@php install-scripts/rename-ddev.php", + "@php composer-scripts/post-create-project.php", "echo 'Cleaning composer.json'", "@composer config --unset scripts.post-create-project-cmd", "@composer config --unset name", diff --git a/install-scripts/rename-ddev.php b/install-scripts/rename-ddev.php deleted file mode 100644 index 57bea76..0000000 --- a/install-scripts/rename-ddev.php +++ /dev/null @@ -1,23 +0,0 @@ -