Skip to content

Commit

Permalink
Merge branch 'release/v0.4.24'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Sep 4, 2024
2 parents 533d15f + 9244553 commit 34b6dd5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.4.24 (2024-09-04)
* Added app task check support

## v0.4.23 (2024-09-04)
* Added --global option to mount tasks
* Improved analysis locality
Expand Down
121 changes: 90 additions & 31 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use DecodeLabs\Veneer;
use DecodeLabs\Veneer\Plugin;
use OndraM\CiDetector\CiDetector;
use Throwable;

/**
* @phpstan-type TConfig array{
Expand Down Expand Up @@ -121,6 +122,12 @@ public function run(
}


// Confirmed app task
if ($this->hasAppTask($name)) {
return $this->runAppTask($name, ...$args);
}


// Composer script
if ($this->hasComposerScript($name)) {
return $this->runComposerScript($name, ...$args);
Expand Down Expand Up @@ -150,37 +157,7 @@ public function run(
}


// Entry file
if ($entry = $this->getEntryFile()) {
$this->config->save();

// Launch script
return Systemic::command([
Integra::getPhpBinary(),
$entry->getPath(),
$name,
...$args
])
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->run();
}

// Clip
elseif ($this->hasVendorBin('clip')) {
return Systemic::command([
(string)Integra::$rootDir->getFile('vendor/bin/clip'),
$name,
...$args
])
->setWorkingDirectory(Integra::$runDir)
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->run();
}


throw Exceptional::NotFound(
'Effigy couldn\'t find any appropriate ways to run "' . $name . '"'
);
return $this->runAppTask($name, ...$args);
}

/**
Expand Down Expand Up @@ -341,6 +318,88 @@ public function getEntryFile(): ?File
throw Exceptional::NotFound('Entry file ' . $entry . ' does not exist');
}

/**
* Ask app if it supports a task
*/
public function hasAppTask(
string $name
): bool {
try {
// Entry file
if ($entry = $this->getEntryFile()) {
$this->config->save();

// Launch script
$result = Systemic::command([
Integra::getPhpBinary(),
$entry->getPath(),
'effigy/has-task',
$name
])
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->capture();
}

// Clip
elseif ($this->hasVendorBin('clip')) {
$result = Systemic::command([
(string)Integra::$rootDir->getFile('vendor/bin/clip'),
'effigy/has-task',
$name
])
->setWorkingDirectory(Integra::$runDir)
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->capture();
} else {
return false;
}

return trim((string)$result->getOutput()) === 'true';
} catch (Throwable $e) {
return false;
}
}

/**
* Run app task via entry or clip
*/
public function runAppTask(
string $name,
string ...$args
): bool {
// Entry file
if ($entry = $this->getEntryFile()) {
$this->config->save();

// Launch script
return Systemic::command([
Integra::getPhpBinary(),
$entry->getPath(),
$name,
...$args
])
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->run();
}

// Clip
elseif ($this->hasVendorBin('clip')) {
return Systemic::command([
(string)Integra::$rootDir->getFile('vendor/bin/clip'),
$name,
...$args
])
->setWorkingDirectory(Integra::$runDir)
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->run();
}


throw Exceptional::NotFound(
'Effigy couldn\'t find any appropriate ways to run "' . $name . '"'
);
}




Expand Down
6 changes: 6 additions & 0 deletions stubs/DecodeLabs/Effigy.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public static function hasVendorBin(string $name): bool {
public static function getEntryFile(): ?Ref0 {
return static::$instance->getEntryFile();
}
public static function hasAppTask(string $name): bool {
return static::$instance->hasAppTask(...func_get_args());
}
public static function runAppTask(string $name, string ...$args): bool {
return static::$instance->runAppTask(...func_get_args());
}
public static function getCodeDirs(): array {
return static::$instance->getCodeDirs();
}
Expand Down

0 comments on commit 34b6dd5

Please sign in to comment.