php-censor/src/PHPCensor/Plugin/Gulp.php

82 lines
2 KiB
PHP
Raw Normal View History

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
/**
* Gulp Plugin - Provides access to gulp functionality.
*
2017-03-04 16:39:56 +01:00
* @author Dirk Heilig <dirk@heilig-online.com>
*/
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';
}
/**
2016-07-11 18:00:04 +02:00
* {@inheritdoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
2014-10-02 22:57:36 +02:00
{
parent::__construct($builder, $build, $options);
2016-07-11 18:00:04 +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;
$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'])) {
$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';
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
return $this->builder->executeCommand($cmd, $this->directory, $this->gulpfile, $this->task);
2014-10-02 22:57:36 +02:00
}
}