Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- post install commands #6

Merged
merged 11 commits into from
Sep 23, 2024
File renamed without changes.
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
"scripts": {
"cs": "./vendor/bin/php-cs-fixer fix --dry-run --diff --config codestyle.php",
"csf": "./vendor/bin/php-cs-fixer fix --diff --config codestyle.php",
"test": "./vendor/bin/phpunit tests --colors=always",
"post-install-cmd": [
"chmod +x src/scripts/version.sh",
"chmod +x src/scripts/check.sh"
]
"test": "./vendor/bin/phpunit tests --colors=always"
}
}
15 changes: 15 additions & 0 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function setLong(bool $long): void

public function generate(): string
{
if (!$this->scriptsAreExecutable()) {
$this->makeScriptsExecutable();
}

return (new Process(["sh", "-c", $this->pathToCheckScript], self::SCRIPTS_DIRECTORY))->run()
? $this->getVersionBasedOnGit()
: $this->getVersionBasedOnTimestamp();
Expand All @@ -49,4 +53,15 @@ private function getVersionBasedOnTimestamp(): string
{
return (string)time();
}

private function scriptsAreExecutable(): bool
{
return is_executable(self::SCRIPTS_DIRECTORY . "version.sh") && is_executable(self::SCRIPTS_DIRECTORY . "check.sh");
}

private function makeScriptsExecutable(): void
{
chmod(self::SCRIPTS_DIRECTORY . "version.sh", 0755);
chmod(self::SCRIPTS_DIRECTORY . "check.sh", 0755);
}
}
Loading