From 5683fa37dc188f5b60698085f73b49723e480299 Mon Sep 17 00:00:00 2001 From: Schorsch3000 Date: Thu, 2 Oct 2014 22:57:36 +0200 Subject: [PATCH] Added Gulp JS plugin. Closes #606 --- PHPCI/Plugin/Gulp.php | 85 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 PHPCI/Plugin/Gulp.php diff --git a/PHPCI/Plugin/Gulp.php b/PHPCI/Plugin/Gulp.php new file mode 100644 index 00000000..b79fdbfc --- /dev/null +++ b/PHPCI/Plugin/Gulp.php @@ -0,0 +1,85 @@ + +* @package PHPCI +* @subpackage Plugins +*/ +class Gulp implements \PHPCI\Plugin +{ + protected $directory; + protected $task; + protected $preferDist; + protected $phpci; + protected $build; + protected $gulp; + protected $gulpfile; + + public function __construct(Builder $phpci, Build $build, array $options = array()) + { + $path = $phpci->buildPath; + $this->build = $build; + $this->phpci = $phpci; + $this->directory = $path; + $this->task = null; + $this->gulp = $this->phpci->findBinary('gulp'); + $this->gulpfile = 'gulpfile.js'; + + // Handle options: + if (isset($options['directory'])) { + $this->directory = $path . '/' . $options['directory']; + } + + 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 (IS_WIN) { + $cmd = 'cd /d %s && npm install'; + } + if (!$this->phpci->executeCommand($cmd, $this->directory)) { + return false; + } + + // build the gulp command + $cmd = 'cd %s && ' . $this->gulp; + if (IS_WIN) { + $cmd = 'cd /d %s && ' . $this->gulp; + } + $cmd .= ' --no-color'; + $cmd .= ' --gulpfile %s'; + $cmd .= ' %s'; // the task that will be executed + + // and execute it + return $this->phpci->executeCommand($cmd, $this->directory, $this->gulpfile, $this->task); + } +}