Skip to content

Commit

Permalink
Merge pull request #1 from JanDC/feature/optional-options
Browse files Browse the repository at this point in the history
Allow for options to be passed to the scripts being run
  • Loading branch information
JanDC authored May 2, 2019
2 parents b72e391 + 19d6fff commit f73e099
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Task/YarnTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ public function getName(): string
public function getConfigurableOptions(): OptionsResolver
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
'script' => null,
'triggered_by' => ['js', 'jsx', 'coffee', 'ts', 'less', 'sass', 'scss'],
'working_directory' => './',
'is_run_task' => false,
]);
$resolver->setDefaults(
[
'script' => null,
'triggered_by' => ['js', 'jsx', 'coffee', 'ts', 'less', 'sass', 'scss'],
'working_directory' => './',
'is_run_task' => false,
'options' => '',
]
);

$resolver->addAllowedTypes('script', ['string']);
$resolver->addAllowedTypes('options', ['string']);
$resolver->addAllowedTypes('triggered_by', ['array']);
$resolver->addAllowedTypes('working_directory', ['string']);
$resolver->addAllowedTypes('is_run_task', ['bool']);
Expand Down Expand Up @@ -58,10 +62,12 @@ public function run(ContextInterface $context): TaskResultInterface
$arguments = $this->processBuilder->createArgumentsForCommand('yarn');
$arguments->addOptionalArgument('run', $config['is_run_task']);
$arguments->addRequiredArgument('%s', $config['script']);
$arguments->addOptionalArgument('%s', $config['options']);

$process = $this->processBuilder->buildProcess($arguments);
$process->setWorkingDirectory(realpath($config['working_directory']));
$process->run();

$status = $process->run();

if (!$process->isSuccessful()) {
return TaskResult::createFailed($this, $context, $this->formatter->format($process));
Expand All @@ -70,4 +76,4 @@ public function run(ContextInterface $context): TaskResultInterface
return TaskResult::createPassed($this, $context);
}

}
}

0 comments on commit f73e099

Please sign in to comment.