diff --git a/composer.json b/composer.json index 0b27b70..6d2aa42 100644 --- a/composer.json +++ b/composer.json @@ -1,29 +1,29 @@ { - "name": "vendor-name/example-package", + "name": ":vendor_slug/:package_slug", "type": "package", - "description": "An example package for Roots Acorn.", + "description": ":package_description", "license": "MIT", "authors": [ { - "name": "Brandon Nifong", - "email": "brandon@tendency.me" + "name": ":author_name", + "email": ":author_email" } ], "autoload": { "psr-4": { - "VendorName\\ExamplePackage\\": "src/" + ":vendor_name\\:class_name\\": "src/" } }, "require": { - "php": "^8.0" + "php": "^8.1" }, "extra": { "acorn": { "providers": [ - "VendorName\\ExamplePackage\\Providers\\ExampleServiceProvider" + ":vendor_name\\:class_name\\Providers\\:class_nameServiceProvider" ], "aliases": { - "Example": "VendorName\\ExamplePackage\\Facades\\Example" + ":class_name": ":vendor_name\\:class_name\\Facades\\:class_name" } } } diff --git a/configure.php b/configure.php new file mode 100644 index 0000000..9133ad5 --- /dev/null +++ b/configure.php @@ -0,0 +1,158 @@ +#!/usr/bin/env php +"); +writeln("Namespace : {$vendorNamespace}\\{$className}"); +writeln("Class name : {$className}"); +writeln('------'); + +writeln('This script will replace the above values in all relevant files in the project directory.'); + +if (! confirm('Modify files?', true)) { + exit(1); +} + +$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); + +foreach ($files as $file) { + replace_in_file($file, [ + ':author_name' => $authorName, + ':author_username' => $authorUsername, + ':author_email' => $authorEmail, + ':vendor_name' => $vendorNamespace, + ':vendor_slug' => $vendorSlug, + 'VendorName' => $vendorNamespace, + ':package_name' => $packageName, + ':package_slug' => $packageSlug, + 'Example' => $className, + 'ExamplePackage' => $className, + 'example' => $packageSlug, + ':package_description' => $description, + ':class_name' => $className + ]); + + match (true) { + str_contains($file, determineSeparator('src/Example.php')) => rename($file, determineSeparator('./src/'.$className.'.php')), + str_contains($file, determineSeparator('src/Providers/ExampleServiceProvider.php')) => rename($file, determineSeparator('./src/providers/'.$className.'ServiceProvider.php')), + str_contains($file, determineSeparator('src/Console/ExampleCommand.php')) => rename($file, determineSeparator('./src/console/'.$className.'.php')), + str_contains($file, determineSeparator('src/Facades/Example.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')), + str_contains($file, determineSeparator('resources/views/example.blade.php')) => rename($file, determineSeparator('./resources/views/'.$packageSlug.'.blade.php')), + default => [], + }; +} + +rename(determineSeparator('config/example.php'), determineSeparator('./config/'.$packageSlug.'.php')); + +confirm('Execute `composer install`?') && run('composer install'); + +confirm('Let this script delete itself?', true) && unlink(__FILE__);