-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add brunch support #239
Add brunch support #239
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ parameters: | |
ant: ~ | ||
atoum: ~ | ||
behat: ~ | ||
brunch: ~ | ||
clover_coverage: ~ | ||
codeception: ~ | ||
composer: ~ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Brunch | ||
|
||
The Brunch task will run your automated frontend tasks. | ||
It lives under the `brunch` namespace and has following configurable parameters: | ||
|
||
```yaml | ||
# grumphp.yml | ||
parameters: | ||
tasks: | ||
brunch: | ||
task: build | ||
env: production | ||
jobs: 4 | ||
debug: false | ||
triggered_by: [js, jsx, coffee, ts, less, sass, scss] | ||
``` | ||
|
||
**brunch_file** | ||
|
||
*Default: null* | ||
|
||
If your `brunch-config.js file is located at an exotic location, you can specify your custom brunch file location with this option. | ||
This option is set to `null` by default. | ||
This means that `brunch-config.js` is automatically loaded if the file exists in the current directory. | ||
|
||
|
||
**task** | ||
|
||
*Default: build* | ||
|
||
This option specifies which Brunch task you want to run. | ||
This option is set to `build` by default. | ||
This means that brunch will run the `build` task. | ||
Note that this task should be used to compile your assets. | ||
It is also possible to alter code during commit, but this is surely **NOT** recommended! | ||
|
||
**env** | ||
|
||
*Default: production* | ||
|
||
This option specifies in which format you want to compile your assets. | ||
E.g: `--env production`. You can specify the env you set up in your brunch config file. | ||
|
||
**jobs** | ||
|
||
*Default: 4* | ||
|
||
This option enables experimental multi-process support. May improve compilation speed of large projects. Try different WORKERS amount to see which one works best for your system. | ||
|
||
**debug** | ||
|
||
*Default: false* | ||
|
||
It enables verbose debug output. | ||
|
||
**triggered_by** | ||
|
||
*Default: [js, jsx, coffee, ts, less, sass, scss]* | ||
|
||
This option will specify which file extensions will trigger the brunch task. | ||
By default Brunch will be triggered by altering a front-end file. | ||
You can overwrite this option to whatever file you want to use! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace spec\GrumPHP\Task; | ||
|
||
use GrumPHP\Collection\FilesCollection; | ||
use GrumPHP\Collection\ProcessArgumentsCollection; | ||
use GrumPHP\Configuration\GrumPHP; | ||
use GrumPHP\Formatter\ProcessFormatterInterface; | ||
use GrumPHP\Process\ProcessBuilder; | ||
use GrumPHP\Runner\TaskResult; | ||
use GrumPHP\Runner\TaskResultInterface; | ||
use GrumPHP\Task\Brunch; | ||
use GrumPHP\Task\Context\ContextInterface; | ||
use GrumPHP\Task\Context\GitPreCommitContext; | ||
use GrumPHP\Task\Context\RunContext; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Class BrunchSpec | ||
*/ | ||
class BrunchSpec extends ObjectBehavior | ||
{ | ||
function let(GrumPHP $grumPHP, ProcessBuilder $processBuilder, ProcessFormatterInterface $formatter) | ||
{ | ||
$grumPHP->getTaskConfiguration('brunch')->willReturn([]); | ||
$this->beConstructedWith($grumPHP, $processBuilder, $formatter); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(Brunch::class); | ||
} | ||
|
||
function it_should_have_a_name() | ||
{ | ||
$this->getName()->shouldBe('brunch'); | ||
} | ||
|
||
function it_should_have_configurable_options() | ||
{ | ||
$options = $this->getConfigurableOptions(); | ||
$options->shouldBeAnInstanceOf(OptionsResolver::class); | ||
$options->getDefinedOptions()->shouldContain('task'); | ||
$options->getDefinedOptions()->shouldContain('env'); | ||
$options->getDefinedOptions()->shouldContain('jobs'); | ||
$options->getDefinedOptions()->shouldContain('debug'); | ||
$options->getDefinedOptions()->shouldContain('triggered_by'); | ||
} | ||
|
||
function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) | ||
{ | ||
$this->canRunInContext($context)->shouldReturn(true); | ||
} | ||
|
||
function it_should_run_in_run_context(RunContext $context) | ||
{ | ||
$this->canRunInContext($context)->shouldReturn(true); | ||
} | ||
|
||
function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) | ||
{ | ||
$processBuilder->createArgumentsForCommand('brunch')->shouldNotBeCalled(); | ||
$processBuilder->buildProcess()->shouldNotBeCalled(); | ||
$context->getFiles()->willReturn(new FilesCollection()); | ||
|
||
$result = $this->run($context); | ||
$result->shouldBeAnInstanceOf(TaskResultInterface::class); | ||
$result->getResultCode()->shouldBe(TaskResult::SKIPPED); | ||
} | ||
|
||
function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) | ||
{ | ||
$arguments = new ProcessArgumentsCollection(); | ||
$processBuilder->createArgumentsForCommand('brunch')->willReturn($arguments); | ||
$processBuilder->buildProcess($arguments)->willReturn($process); | ||
|
||
$process->run()->shouldBeCalled(); | ||
$process->isSuccessful()->willReturn(true); | ||
|
||
$context->getFiles()->willReturn(new FilesCollection([ | ||
new SplFileInfo('test.js', '.', 'test.js') | ||
])); | ||
|
||
$result = $this->run($context); | ||
$result->shouldBeAnInstanceOf(TaskResultInterface::class); | ||
$result->isPassed()->shouldBe(true); | ||
} | ||
|
||
function it_throws_exception_if_the_process_fails( | ||
ProcessBuilder $processBuilder, | ||
Process $process, | ||
ContextInterface $context | ||
) { | ||
$arguments = new ProcessArgumentsCollection(); | ||
$processBuilder->createArgumentsForCommand('brunch')->willReturn($arguments); | ||
$processBuilder->buildProcess($arguments)->willReturn($process); | ||
|
||
$process->run()->shouldBeCalled(); | ||
$process->isSuccessful()->willReturn(false); | ||
|
||
$context->getFiles()->willReturn(new FilesCollection([ | ||
new SplFileInfo('test.js', '.', 'test.js') | ||
])); | ||
|
||
$result = $this->run($context); | ||
$result->shouldBeAnInstanceOf(TaskResultInterface::class); | ||
$result->isPassed()->shouldBe(false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace GrumPHP\Task; | ||
|
||
use GrumPHP\Runner\TaskResult; | ||
use GrumPHP\Task\Context\ContextInterface; | ||
use GrumPHP\Task\Context\GitPreCommitContext; | ||
use GrumPHP\Task\Context\RunContext; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* Brunch task | ||
*/ | ||
class Brunch extends AbstractExternalTask | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'brunch'; | ||
} | ||
|
||
/** | ||
* @return OptionsResolver | ||
*/ | ||
public function getConfigurableOptions() | ||
{ | ||
$resolver = new OptionsResolver(); | ||
$resolver->setDefaults([ | ||
'task' => 'build', | ||
'env' => 'production', | ||
'jobs' => 4, | ||
'debug' => false, | ||
'triggered_by' => ['js', 'jsx', 'coffee', 'ts', 'less', 'sass', 'scss'] | ||
]); | ||
|
||
$resolver->addAllowedTypes('task', ['string']); | ||
$resolver->addAllowedTypes('env', ['string']); | ||
$resolver->addAllowedTypes('jobs', ['int']); | ||
$resolver->addAllowedTypes('debug', ['bool']); | ||
$resolver->addAllowedTypes('triggered_by', ['array']); | ||
|
||
return $resolver; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function canRunInContext(ContextInterface $context) | ||
{ | ||
return ($context instanceof GitPreCommitContext || $context instanceof RunContext); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function run(ContextInterface $context) | ||
{ | ||
$config = $this->getConfiguration(); | ||
$files = $context->getFiles()->extensions($config['triggered_by']); | ||
if (0 === count($files)) { | ||
return TaskResult::createSkipped($this, $context); | ||
} | ||
|
||
$arguments = $this->processBuilder->createArgumentsForCommand('brunch'); | ||
$arguments->addRequiredArgument('%s', $config['task']); | ||
$arguments->addOptionalArgument('--env %s', $config['env']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will result in the escaped CLI argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should result to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I guess you should use |
||
$arguments->addOptionalArgument('--jobs %s', $config['jobs']); | ||
$arguments->addOptionalArgument('--debug', $config['debug']); | ||
|
||
$process = $this->processBuilder->buildProcess($arguments); | ||
$process->run(); | ||
|
||
if (!$process->isSuccessful()) { | ||
return TaskResult::createFailed($this, $context, $this->formatter->format($process)); | ||
} | ||
|
||
return TaskResult::createPassed($this, $context); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The brunch_file section is removed from the task.
Is there a reason why it is removed or can it be re-added?
If no, then this section in the documentation should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brunch_file doesn't exist anymore since 2.0, i'll remove it.