Gulp::setDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
4
namespace Genesis\Commands\Assets;
5
6
7
use Genesis\Commands;
8
9
/**
10
 * @author Adam Bisek <[email protected]>
11
 */
12
class Gulp extends Commands\Command
13
{
14
15
	private $gulpfile = 'gulpfile.js';
16
17
	private $directory;
18
19
20
	/**
21
	 * @return string
22
	 */
23 1
	public function getGulpfile()
24
	{
25 1
		return $this->gulpfile;
26
	}
27
28
29
	/**
30
	 * @param string $gulpfile
31
	 */
32 1
	public function setGulpfile($gulpfile)
33
	{
34 1
		$this->gulpfile = $gulpfile;
35 1
	}
36
37
38
	/**
39
	 * Returns working directory.
40
	 * @return string
41
	 */
42 1
	public function getDirectory()
43
	{
44 1
		return $this->directory;
45
	}
46
47
48
	/**
49
	 * Sets working directory. System will switch to this directory before running gulp.
50
	 * @param string $directory
51
	 */
52 1
	public function setDirectory($directory)
53
	{
54 1
		$this->directory = $directory;
55 1
	}
56
57
58 1
	public function execute($gulpCommand = NULL)
59
	{
60 1
		$path = $this->directory . DIRECTORY_SEPARATOR . $this->gulpfile;
61 1
		if (!file_exists($path)) {
62
			$this->error(sprintf("Cannot find gulpfile '%s'.", $path));
63
		}
64
65 1
		$cmd = 'cd ' . escapeshellarg($this->directory) . ' && gulp ' . $gulpCommand;
66 1
		$command = new Commands\Exec();
67 1
		$command->setCommand($cmd);
68 1
		$result = $command->execute();
69 1
		if ($result->getResult() !== 0) {
70
			$this->error(sprintf("Gulp task '%s' in directory %s failed.", $gulpCommand, $this->directory));
71
		}
72 1
		return $result;
73
	}
74
75
}