feat: add scaleway-init writing the handler.php stubUnverified
Writes resources/handler.php at the application root and refuses to replace a different file unless run with --force.
934f5cd parent: b326a41 modified
.php-cs-fixer.dist.php +1 -1 | @@ -4,7 +4,7 @@ declare(strict_types=1); | ||
| 4 | 4 | |
| 5 | 5 | $finder = (new PhpCsFixer\Finder()) |
| 6 | 6 | ->in([__DIR__.'/src', __DIR__.'/tests']) |
| 7 | - ->append([__FILE__]); | |
| 7 | + ->append([__FILE__, __DIR__.'/bin/scaleway-init']); | |
| 8 | 8 | |
| 9 | 9 | return (new PhpCsFixer\Config()) |
| 10 | 10 | ->setRiskyAllowed(true) |
| @@ -4,7 +4,7 @@ declare(strict_types=1); | |||
| 4 | 4 | ||
| 5 | $finder = (new PhpCsFixer\Finder()) | 5 | $finder = (new PhpCsFixer\Finder()) |
| 6 | ->in([__DIR__.'/src', __DIR__.'/tests']) | 6 | ->in([__DIR__.'/src', __DIR__.'/tests']) |
| 7 | - ->append([__FILE__]); | 7 | + ->append([__FILE__, __DIR__.'/bin/scaleway-init']); |
| 8 | 8 | ||
| 9 | return (new PhpCsFixer\Config()) | 9 | return (new PhpCsFixer\Config()) |
| 10 | ->setRiskyAllowed(true) | 10 | ->setRiskyAllowed(true) |
added
bin/scaleway-init +21 -0 | new file mode 100755 | ||
| @@ -0,0 +1,21 @@ | ||
| 1 | +#!/usr/bin/env php | |
| 2 | +<?php | |
| 3 | + | |
| 4 | +declare(strict_types=1); | |
| 5 | + | |
| 6 | +use Composer\InstalledVersions; | |
| 7 | + | |
| 8 | +require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php'; | |
| 9 | + | |
| 10 | +$target = realpath(InstalledVersions::getRootPackage()['install_path']).'/handler.php'; | |
| 11 | +$stub = (string) file_get_contents(__DIR__.'/../resources/handler.php'); | |
| 12 | + | |
| 13 | +if (is_file($target) && file_get_contents($target) !== $stub && !in_array('--force', $argv ?? [], true)) { | |
| 14 | + fwrite(\STDERR, "{$target} exists and differs from the stub; run with --force to overwrite it.".\PHP_EOL); | |
| 15 | + exit(1); | |
| 16 | +} | |
| 17 | + | |
| 18 | +if (false === file_put_contents($target, $stub)) { | |
| 19 | + exit(1); | |
| 20 | +} | |
| 21 | +echo "Wrote {$target}; set the function handler to \"handler.handle\" and commit the file.", \PHP_EOL; | |
| new file mode 100755 | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | +#!/usr/bin/env php | ||
| 2 | +<?php | ||
| 3 | + | ||
| 4 | +declare(strict_types=1); | ||
| 5 | + | ||
| 6 | +use Composer\InstalledVersions; | ||
| 7 | + | ||
| 8 | +require $_composer_autoload_path ?? __DIR__.'/../vendor/autoload.php'; | ||
| 9 | + | ||
| 10 | +$target = realpath(InstalledVersions::getRootPackage()['install_path']).'/handler.php'; | ||
| 11 | +$stub = (string) file_get_contents(__DIR__.'/../resources/handler.php'); | ||
| 12 | + | ||
| 13 | +if (is_file($target) && file_get_contents($target) !== $stub && !in_array('--force', $argv ?? [], true)) { | ||
| 14 | + fwrite(\STDERR, "{$target} exists and differs from the stub; run with --force to overwrite it.".\PHP_EOL); | ||
| 15 | + exit(1); | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +if (false === file_put_contents($target, $stub)) { | ||
| 19 | + exit(1); | ||
| 20 | +} | ||
| 21 | +echo "Wrote {$target}; set the function handler to \"handler.handle\" and commit the file.", \PHP_EOL; | ||
modified
composer.json +3 -0 | @@ -28,6 +28,9 @@ | ||
| 28 | 28 | "JDecool\\ScalewayRuntime\\": "src/" |
| 29 | 29 | } |
| 30 | 30 | }, |
| 31 | + "bin": [ | |
| 32 | + "bin/scaleway-init" | |
| 33 | + ], | |
| 31 | 34 | "autoload-dev": { |
| 32 | 35 | "psr-4": { |
| 33 | 36 | "JDecool\\ScalewayRuntime\\Tests\\": "tests/" |
| @@ -28,6 +28,9 @@ | |||
| 28 | "JDecool\\ScalewayRuntime\\": "src/" | 28 | "JDecool\\ScalewayRuntime\\": "src/" |
| 29 | } | 29 | } |
| 30 | }, | 30 | }, |
| 31 | + "bin": [ | ||
| 32 | + "bin/scaleway-init" | ||
| 33 | + ], | ||
| 31 | "autoload-dev": { | 34 | "autoload-dev": { |
| 32 | "psr-4": { | 35 | "psr-4": { |
| 33 | "JDecool\\ScalewayRuntime\\Tests\\": "tests/" | 36 | "JDecool\\ScalewayRuntime\\Tests\\": "tests/" |
modified
phpstan.neon.dist +1 -0 | @@ -7,3 +7,4 @@ parameters: | ||
| 7 | 7 | paths: |
| 8 | 8 | - src |
| 9 | 9 | - tests |
| 10 | + - bin/scaleway-init | |
| @@ -7,3 +7,4 @@ parameters: | |||
| 7 | paths: | 7 | paths: |
| 8 | - src | 8 | - src |
| 9 | - tests | 9 | - tests |
| 10 | + - bin/scaleway-init | ||