Skip to content

Commit

Permalink
- post install commands (#6)
Browse files Browse the repository at this point in the history
* - fix: composer.json update

* - fix: composer.json update

* - fix: composer.json update fix

* - fix: composer.json update fix

* - fix: composer.json update fix 2

* - fix: composer.json update fix 3

* - fix: composer.json update fix 3

* - fix: added readme instructions

* - fix: fixes

* - fix: fixed readme file

* - fix: applied code review suggestions
  • Loading branch information
kamilpiech97 authored Sep 23, 2024
1 parent 84a7596 commit 586b79f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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);
}
}

0 comments on commit 586b79f

Please sign in to comment.