2013-07-31 08:55:19 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2013-07-31 08:55:19 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Builder;
|
|
|
|
use PHPCensor\Model\Build;
|
|
|
|
use PHPCensor\Plugin;
|
2013-10-10 02:01:06 +02:00
|
|
|
|
2013-07-31 08:55:19 +02:00
|
|
|
/**
|
2017-01-10 18:46:19 +01:00
|
|
|
* Grunt Plugin - Provides access to grunt functionality.
|
2018-03-08 04:31:31 +01:00
|
|
|
*
|
2017-03-04 16:39:56 +01:00
|
|
|
* @author Tobias Tom <t.tom@succont.de>
|
2017-01-10 18:46:19 +01:00
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
class Grunt extends Plugin
|
2013-07-31 08:55:19 +02:00
|
|
|
{
|
|
|
|
protected $directory;
|
|
|
|
protected $task;
|
|
|
|
protected $preferDist;
|
|
|
|
protected $grunt;
|
|
|
|
protected $gruntfile;
|
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'grunt';
|
|
|
|
}
|
2018-03-08 04:31:31 +01:00
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
2016-07-11 18:00:04 +02:00
|
|
|
* {@inheritdoc}
|
2014-12-08 12:25:33 +01:00
|
|
|
*/
|
2016-07-22 09:05:34 +02:00
|
|
|
public function __construct(Builder $builder, Build $build, array $options = [])
|
2013-07-31 08:55:19 +02:00
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
parent::__construct($builder, $build, $options);
|
2018-03-08 04:31:31 +01:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
$path = $this->builder->buildPath;
|
2013-10-10 02:01:06 +02:00
|
|
|
$this->directory = $path;
|
2016-07-11 18:00:04 +02:00
|
|
|
$this->task = null;
|
2017-07-19 05:26:51 +02:00
|
|
|
$this->grunt = $this->findBinary('grunt');
|
2013-10-10 02:01:06 +02:00
|
|
|
$this->gruntfile = 'Gruntfile.js';
|
|
|
|
|
|
|
|
// Handle options:
|
|
|
|
if (isset($options['directory'])) {
|
2018-03-08 04:31:31 +01:00
|
|
|
$this->directory = $path . '/' . $options['directory'];
|
2013-10-10 02:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['task'])) {
|
|
|
|
$this->task = $options['task'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['grunt'])) {
|
|
|
|
$this->grunt = $options['grunt'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['gruntfile'])) {
|
|
|
|
$this->gruntfile = $options['gruntfile'];
|
|
|
|
}
|
2013-07-31 08:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes grunt and runs a specified command (e.g. install / update)
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
// if npm does not work, we cannot use grunt, so we return false
|
2014-03-12 18:37:57 +01:00
|
|
|
$cmd = 'cd %s && npm install';
|
2016-07-22 09:05:34 +02:00
|
|
|
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
2013-07-31 08:55:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build the grunt command
|
|
|
|
$cmd = 'cd %s && ' . $this->grunt;
|
|
|
|
$cmd .= ' --no-color';
|
|
|
|
$cmd .= ' --gruntfile %s';
|
|
|
|
$cmd .= ' %s'; // the task that will be executed
|
|
|
|
|
|
|
|
// and execute it
|
2016-07-22 09:05:34 +02:00
|
|
|
return $this->builder->executeCommand($cmd, $this->directory, $this->gruntfile, $this->task);
|
2013-07-31 08:55:19 +02:00
|
|
|
}
|
|
|
|
}
|