2014-10-02 22:57:36 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2014-10-02 22:57:36 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Builder;
|
|
|
|
use PHPCensor\Model\Build;
|
|
|
|
use PHPCensor\Plugin;
|
2014-10-02 22:57:36 +02:00
|
|
|
|
|
|
|
/**
|
2017-01-10 18:46:19 +01:00
|
|
|
* Gulp Plugin - Provides access to gulp functionality.
|
|
|
|
*
|
2017-03-04 16:39:56 +01:00
|
|
|
* @author Dirk Heilig <dirk@heilig-online.com>
|
2017-01-10 18:46:19 +01:00
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
class Gulp extends Plugin
|
2014-10-02 22:57:36 +02:00
|
|
|
{
|
|
|
|
protected $directory;
|
|
|
|
protected $task;
|
|
|
|
protected $preferDist;
|
|
|
|
protected $gulp;
|
|
|
|
protected $gulpfile;
|
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'gulp';
|
|
|
|
}
|
|
|
|
|
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 = [])
|
2014-10-02 22:57:36 +02:00
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
parent::__construct($builder, $build, $options);
|
2016-07-11 18:00:04 +02:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
$path = $this->builder->buildPath;
|
2014-10-02 22:57:36 +02:00
|
|
|
$this->directory = $path;
|
2016-07-11 18:00:04 +02:00
|
|
|
$this->task = null;
|
2016-07-22 09:05:34 +02:00
|
|
|
$this->gulp = $this->builder->findBinary('gulp');
|
2016-07-11 18:00:04 +02:00
|
|
|
$this->gulpfile = 'gulpfile.js';
|
2014-10-02 22:57:36 +02:00
|
|
|
|
|
|
|
// Handle options:
|
|
|
|
if (isset($options['directory'])) {
|
2015-10-23 05:18:22 +02:00
|
|
|
$this->directory = $path . DIRECTORY_SEPARATOR . $options['directory'];
|
2014-10-02 22:57:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['task'])) {
|
|
|
|
$this->task = $options['task'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['gulp'])) {
|
|
|
|
$this->gulp = $options['gulp'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['gulpfile'])) {
|
|
|
|
$this->gulpfile = $options['gulpfile'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes gulp and runs a specified command (e.g. install / update)
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
// if npm does not work, we cannot use gulp, so we return false
|
|
|
|
$cmd = 'cd %s && npm install';
|
2016-07-22 09:05:34 +02:00
|
|
|
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
2014-10-02 22:57:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build the gulp command
|
|
|
|
$cmd = 'cd %s && ' . $this->gulp;
|
|
|
|
$cmd .= ' --no-color';
|
|
|
|
$cmd .= ' --gulpfile %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->gulpfile, $this->task);
|
2014-10-02 22:57:36 +02:00
|
|
|
}
|
|
|
|
}
|