Skip to content

Commit

Permalink
Add utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Feb 4, 2022
1 parent b5094ff commit 0177bc6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/tasks/MergeMinifyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,15 @@ public function main()
// Scripts bundle
if ($xml->alledia->minify->scripts) {
/** @var AppendTask $append */
$append = $this->project->createTask('append');
$append->setOwningTarget($this->getOwningTarget());
$append->setTaskName($this->getTaskName());
$append->setLocation($this->getLocation());
$append->init();
$append = $this->initProjectTask('append');

foreach ($xml->alledia->minify->scripts as $bundle) {
if (!empty($bundle->script)) {
$destination = $bundle['destination'];
if ($bundle->script) {
$destination = (string)$bundle['destination'];

// Remove destination, if exists
$fullPath = $this->basePath . '/' . $destination;
if (file_exists($fullPath)) {
if (is_file($fullPath)) {
unlink($fullPath);
}

Expand Down
22 changes: 22 additions & 0 deletions src/tasks/TraitShack.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,26 @@ protected function findRegexStrings(array $strings, string $subject): array

return [];
}

/**
* Initialize another task in the project
*
* @param string $taskName
*
* @return Task
*/
protected function initProjectTask(string $taskName): Task
{
if ($task = $this->project->createTask($taskName)) {
$task->setOwningTarget($this->getOwningTarget());
$task->setTaskName($this->getTaskName());
$task->setLocation($this->getLocation());
$task->init();

return $task;
}

$this->throwError('Unable to initialize task: ' . $taskName);
die();
}
}

0 comments on commit 0177bc6

Please sign in to comment.