55
66function ask (string $ question , string $ default = '' ): string
77{
8- $ answer = readline ($ question. ($ default ? " ( {$ default }) " : null ). ': ' );
8+ $ answer = readline ($ question . ($ default ? " ( {$ default }) " : null ) . ': ' );
99
1010 if (! $ answer ) {
1111 return $ default ;
@@ -16,7 +16,7 @@ function ask(string $question, string $default = ''): string
1616
1717function confirm (string $ question , bool $ default = false ): bool
1818{
19- $ answer = ask ($ question. ' ( ' . ($ default ? 'Y/n ' : 'y/N ' ). ') ' );
19+ $ answer = ask ($ question . ' ( ' . ($ default ? 'Y/n ' : 'y/N ' ) . ') ' );
2020
2121 if (! $ answer ) {
2222 return $ default ;
@@ -27,7 +27,7 @@ function confirm(string $question, bool $default = false): bool
2727
2828function writeln (string $ line ): void
2929{
30- echo $ line. PHP_EOL ;
30+ echo $ line . PHP_EOL ;
3131}
3232
3333function run (string $ command ): string
@@ -86,20 +86,20 @@ function remove_prefix(string $prefix, string $content): string
8686
8787function remove_composer_deps (array $ names )
8888{
89- $ data = json_decode (file_get_contents (__DIR__ . '/composer.json ' ), true );
89+ $ data = json_decode (file_get_contents (__DIR__ . '/composer.json ' ), true );
9090
9191 foreach ($ data ['require-dev ' ] as $ name => $ version ) {
9292 if (in_array ($ name , $ names , true )) {
9393 unset($ data ['require-dev ' ][$ name ]);
9494 }
9595 }
9696
97- file_put_contents (__DIR__ . '/composer.json ' , json_encode ($ data , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ));
97+ file_put_contents (__DIR__ . '/composer.json ' , json_encode ($ data , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ));
9898}
9999
100100function remove_composer_script ($ scriptName )
101101{
102- $ data = json_decode (file_get_contents (__DIR__ . '/composer.json ' ), true );
102+ $ data = json_decode (file_get_contents (__DIR__ . '/composer.json ' ), true );
103103
104104 foreach ($ data ['scripts ' ] as $ name => $ script ) {
105105 if ($ scriptName === $ name ) {
@@ -108,7 +108,7 @@ function remove_composer_script($scriptName)
108108 }
109109 }
110110
111- file_put_contents (__DIR__ . '/composer.json ' , json_encode ($ data , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ));
111+ file_put_contents (__DIR__ . '/composer.json ' , json_encode ($ data , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ));
112112}
113113
114114function remove_readme_paragraphs (string $ file ): void
@@ -135,12 +135,12 @@ function determineSeparator(string $path): string
135135
136136function replaceForWindows (): array
137137{
138- return preg_split ('/ \\r \\n| \\r| \\n/ ' , run ('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i ' . basename (__FILE__ ). ' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com" ' ));
138+ return preg_split ('/ \\r \\n| \\r| \\n/ ' , run ('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i ' . basename (__FILE__ ) . ' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com" ' ));
139139}
140140
141141function replaceForAllOtherOSes (): array
142142{
143- return explode (PHP_EOL , run ('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v ' . basename (__FILE__ )));
143+ return explode (PHP_EOL , run ('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v ' . basename (__FILE__ )));
144144}
145145
146146$ gitName = run ('git config user.name ' );
@@ -171,11 +171,11 @@ function replaceForAllOtherOSes(): array
171171$ variableName = lcfirst ($ className );
172172$ description = ask ('Package description ' , "This is my package {$ packageSlug }" );
173173
174- //$usePhpStan = confirm('Enable PhpStan?', true);
175- //$useLaravelPint = confirm('Enable Laravel Pint?', true);
176- //$useDependabot = confirm('Enable Dependabot?', true);
177- //$useLaravelRay = confirm('Use Ray for debugging?', true);
178- //$useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true);
174+ // $usePhpStan = confirm('Enable PhpStan?', true);
175+ // $useLaravelPint = confirm('Enable Laravel Pint?', true);
176+ // $useDependabot = confirm('Enable Dependabot?', true);
177+ // $useLaravelRay = confirm('Use Ray for debugging?', true);
178+ // $useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true);
179179
180180writeln ('------ ' );
181181writeln ("Author : {$ authorName } ( {$ authorUsername }, {$ authorEmail }) " );
@@ -184,13 +184,13 @@ function replaceForAllOtherOSes(): array
184184writeln ("Namespace : {$ vendorNamespace }\\{$ className }" );
185185writeln ("Class name : {$ className }" );
186186writeln ('--- ' );
187- //writeln('Packages & Utilities');
188- //writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no'));
189- //writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no'));
190- //writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no'));
191- //writeln('Use Ray App : '.($useLaravelRay ? 'yes' : 'no'));
192- //writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no'));
193- //writeln('------');
187+ // writeln('Packages & Utilities');
188+ // writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no'));
189+ // writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no'));
190+ // writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no'));
191+ // writeln('Use Ray App : '.($useLaravelRay ? 'yes' : 'no'));
192+ // writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no'));
193+ // writeln('------');
194194
195195writeln ('This script will replace the above values in all relevant files in the project directory. ' );
196196
@@ -219,23 +219,23 @@ function replaceForAllOtherOSes(): array
219219 ]);
220220
221221 match (true ) {
222- str_contains ($ file , determineSeparator ('src/Skeleton.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className. '.php ' )),
223- str_contains ($ file , determineSeparator ('src/SkeletonServiceProvider.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className. 'ServiceProvider.php ' )),
224- str_contains ($ file , determineSeparator ('src/Facades/Skeleton.php ' )) => rename ($ file , determineSeparator ('./src/Facades/ ' . $ className. '.php ' )),
225- str_contains ($ file , determineSeparator ('src/Commands/SkeletonCommand.php ' )) => rename ($ file , determineSeparator ('./src/Commands/ ' . $ className. 'Command.php ' )),
226- str_contains ($ file , determineSeparator ('database/migrations/create_skeleton_table.php.stub ' )) => rename ($ file , determineSeparator ('./database/migrations/create_ ' . title_snake ($ packageSlugWithoutPrefix ). '_table.php.stub ' )),
227- str_contains ($ file , determineSeparator ('config/skeleton.php ' )) => rename ($ file , determineSeparator ('./config/ ' . $ packageSlugWithoutPrefix. '.php ' )),
222+ str_contains ($ file , determineSeparator ('src/Skeleton.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className . '.php ' )),
223+ str_contains ($ file , determineSeparator ('src/SkeletonServiceProvider.php ' )) => rename ($ file , determineSeparator ('./src/ ' . $ className . 'ServiceProvider.php ' )),
224+ str_contains ($ file , determineSeparator ('src/Facades/Skeleton.php ' )) => rename ($ file , determineSeparator ('./src/Facades/ ' . $ className . '.php ' )),
225+ str_contains ($ file , determineSeparator ('src/Commands/SkeletonCommand.php ' )) => rename ($ file , determineSeparator ('./src/Commands/ ' . $ className . 'Command.php ' )),
226+ str_contains ($ file , determineSeparator ('database/migrations/create_skeleton_table.php.stub ' )) => rename ($ file , determineSeparator ('./database/migrations/create_ ' . title_snake ($ packageSlugWithoutPrefix ) . '_table.php.stub ' )),
227+ str_contains ($ file , determineSeparator ('config/skeleton.php ' )) => rename ($ file , determineSeparator ('./config/ ' . $ packageSlugWithoutPrefix . '.php ' )),
228228 str_contains ($ file , 'README.md ' ) => remove_readme_paragraphs ($ file ),
229229 default => [],
230230 };
231231}
232232
233- //if (! $useLaravelPint) {
233+ // if (! $useLaravelPint) {
234234// safeUnlink(__DIR__.'/.github/workflows/fix-php-code-style-issues.yml');
235235// safeUnlink(__DIR__.'/pint.json');
236- //}
236+ // }
237237//
238- //if (! $usePhpStan) {
238+ // if (! $usePhpStan) {
239239// safeUnlink(__DIR__.'/phpstan.neon.dist');
240240// safeUnlink(__DIR__.'/phpstan-baseline.neon');
241241// safeUnlink(__DIR__.'/.github/workflows/phpstan.yml');
@@ -248,20 +248,20 @@ function replaceForAllOtherOSes(): array
248248// ]);
249249//
250250// remove_composer_script('phpstan');
251- //}
251+ // }
252252
253- //if (! $useDependabot) {
253+ // if (! $useDependabot) {
254254// safeUnlink(__DIR__.'/.github/dependabot.yml');
255255// safeUnlink(__DIR__.'/.github/workflows/dependabot-auto-merge.yml');
256- //}
256+ // }
257257//
258- //if (! $useLaravelRay) {
258+ // if (! $useLaravelRay) {
259259// remove_composer_deps(['spatie/laravel-ray']);
260- //}
260+ // }
261261//
262- //if (! $useUpdateChangelogWorkflow) {
262+ // if (! $useUpdateChangelogWorkflow) {
263263// safeUnlink(__DIR__.'/.github/workflows/update-changelog.yml');
264- //}
264+ // }
265265
266266confirm ('Execute `composer install` and run tests? ' ) && run ('composer install && composer test ' );
267267
0 commit comments