forked from scotlandphp/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
118 lines (105 loc) · 2.99 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
/**
* Build the project (dev by default)
*
* @option $dist Set whether buildDist should be executed
*/
public function build($opts = ['dist|d' => false])
{
$this->buildDev();
if (isset($opts['dist']) && $opts['dist']) {
$this->buildDist();
}
}
public function buildDev()
{
// remove existing dev and dist folder
$this->clear();
// recreate the dev folder
$this->_mkdir('dev');
// copy required files
$this->_copyDir('pages', 'dev');
$this->_copyDir('images', 'dev');
$this->_copyDir('favicon', 'dev');
// compile scss
$this->compileScss('assets/sass/ie8.scss', 'dev/ie8.css');
$this->compileScss('assets/sass/ie9.scss', 'dev/ie9.css');
$this->compileScss('assets/sass/leaflet.scss', 'dev/leaflet.css');
$this->compileScss('assets/sass/main.scss', 'dev/main.css');
// fetch javascript
$this->taskFlattenDir([
'assets/js' => 'dev',
])->run();
}
public function buildDist()
{
// remove existing dist folder
$this->_deleteDir('dist');
// recreate the dist folder
$this->_mkdir('dist');
// copy pages
$this->_copyDir('dev', 'dist');
foreach (glob('dist/*.css') as $cssFile) {
$this->taskMinify($cssFile)
->to($cssFile)
->run();
}
}
public function clear()
{
$this->taskDeleteDir([
'dev',
'dist',
])->run();
}
public function watch()
{
// build dev environment
$this->build();
$this->taskWatch()
->monitor('assets/sass', function() {
foreach (glob('assets/sass/*.scss') as $file) {
$this->compileScss(
$file,
basename($file, '.scss') . '.css'
);
}
})
->monitor('assets/js', function() {
$this->taskFlattenDir([
'assets/js' => 'dev',
])->run();
})
->monitor('pages', function() {
$this->_copyDir('pages', 'dev');
})
->monitor('favicon', function() {
$this->_copyDir('favicon', 'dev');
})
->monitor('images', function() {
$this->_copyDir('images', 'dev');
})
->run();
}
/**
* @param $src
* @param $dest
*/
private function compileScss($src, $dest)
{
// waiting for https://github.com/leafo/scssphp/issues/409
/*$this->taskScss([
$src => $dest
])
->setImportPaths([dirname($src)])
->run();*/
$this->_exec("sass {$src} {$dest}");
}
}