Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Nov 25, 2022
2 parents f3c068d + 9505e45 commit 378838a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 106 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.3.1 (2022-11-25)
* Use run dir for cwd when calling bins
* Moved body of Template to Genesis
* Improved version task
* Added signal handlers to bin launcher

## v0.3.0 (2022-11-24)
* Switched composer integration to Integra
* Moved config handling to standalone class
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"decodelabs/dictum": "^0.4.3",
"decodelabs/exceptional": "^0.4",
"decodelabs/integra": "^0.1",
"decodelabs/genesis": "^0.7.1",
"decodelabs/systemic": "^0.10.1",
"decodelabs/terminus": "^0.9.3",
"decodelabs/veneer": "^0.10.12",
Expand Down
8 changes: 5 additions & 3 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ public function run(

// Bin
if ($this->hasVendorBin($name)) {
return Systemic::$process->launch(
'vendor/bin/' . $name,
return Systemic::$process->newLauncher(
Integra::$rootDir->getFile('vendor/bin/' . $name),
$args,
Integra::$rootDir,
Integra::$runDir,
Cli::getSession()
)
->addSignal('SIGINT', 'SIGTERM', 'SIGQUIT')
->launch()
->wasSuccessful();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function execute(): bool
Cli::newLine();
Cli::{'brightCyan'}('Effigy ');
Cli::{'white'}(': ');
Cli::{'.brightYellow'}(InstalledVersions::getVersion('decodelabs/effigy'));
Cli::{'.brightYellow'}(InstalledVersions::getPrettyVersion('decodelabs/effigy'));
Cli::newLine();

return true;
Expand Down
105 changes: 3 additions & 102 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,13 @@

namespace DecodeLabs\Effigy;

use DecodeLabs\Atlas;
use DecodeLabs\Atlas\File;
use DecodeLabs\Dictum;
use DecodeLabs\Exceptional;
use DecodeLabs\Genesis\FileTemplate;
use DecodeLabs\Integra;
use DecodeLabs\Terminus as Cli;

class Template
class Template extends FileTemplate
{
/**
* @phpstan-var array<string, ?string>
*/
protected array $slots = [];

protected File $templateFile;

public function __construct(
string|File $templateFile
) {
$this->templateFile = Atlas::file($templateFile);

if (!$this->templateFile->exists()) {
throw Exceptional::Runtime('Template file could not be found');
}
}


/**
* Set slots
*
* @param array<string, string> $slots
* @return $this
*/
public function setSlots(array $slots): static
{
foreach ($slots as $name => $slot) {
$this->setSlot($name, $slot);
}

return $this;
}

/**
* Get slots
*
* @return array<string, ?string>
*/
public function getSlots(): array
{
return $this->slots;
}

/**
* Set slot
*
* @return $this;
*/
public function setSlot(
string $name,
string $slot
): static {
$this->slots[$name] = $slot;
return $this;
}

/**
* Get slot
*/
public function getSlot(string $name): ?string
{
if (array_key_exists($name, $this->slots)) {
return $this->slots[$name];
}

return $this->slots[$name] = $this->generateSlot($name);
}

protected function generateSlot(string $name): ?string
{
$manifest = Integra::getLocalManifest();
Expand Down Expand Up @@ -127,9 +57,6 @@ protected function generateSlot(string $name): ?string
case 'pkgIntro':
return $this->getPackageIntro();

case 'date':
return date('Y-m-d');

case 'phpExtensions':
return implode(', ', $this->getPackagePhpExtensions());

Expand All @@ -144,33 +71,7 @@ protected function generateSlot(string $name): ?string
}
}

return null;
}


/**
* Interpolate and save to file
*/
public function saveTo(
string|File $file
): File {
$content = (string)preg_replace_callback('/{{ ?([a-zA-Z0-9_]+) ?}}/', function ($matches) {
$name = $matches[1];
$output = $this->getSlot($name);

if ($output === null) {
$output = $matches[0];
}

return $output;
}, $this->templateFile->getContents());

$content = (string)preg_replace('/^\#\!(.*)\n/m', '', $content);

$file = Atlas::file($file);
$file->putContents($content);

return $file;
return parent::generateSlot($name);
}


Expand Down

0 comments on commit 378838a

Please sign in to comment.