-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFile.php
146 lines (133 loc) · 3.82 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* This is the RoboFile for Bootgenie
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
private $vendorDir;
private $assetPackages;
/**
* Contruct for the class, checks and creates the dist folders
*/
public function __construct() {
// check the build folder
$buildDirs = array(
'assets/styles',
'assets/scripts',
'assets/fonts'
);
$this->createPaths($buildDirs);
// get the vendorDir
$io = new Composer\IO\NullIO();
$factory = new Composer\Factory();
$composer = $factory->createComposer($io);
$this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');
// go through installed packages (taken from Composer\Command\ShowCommand.php)
$installedRepo = $composer->getRepositoryManager()->getLocalRepository();
$this->assetPackages = [];
foreach ($installedRepo->getPackages() as $package) {
if ($package->getType() == 'bower-asset-library' ) {
// store the extra information for assets
$this->assetPackages[$package->getPrettyName()] = $package;
}
}
}
private function createPaths($paths){
// iterate through paths array and create folder
foreach ($paths as $path) {
// use Symfony 2 mkdir for recursive directory creation
if (! is_dir($path)) {
$this->_mkdir($path);
}
}
}
private function getAssetPath($packageName) {
foreach ($this->assetPackages as $k => $package) {
if ( strpos($k, $packageName) !== FALSE) {
return $this->vendorDir .'/'. $k . '/';
}
}
}
private function getAssetMain($packageName) {
foreach ($this->assetPackages as $k => $package) {
if ( strpos($k, $packageName) !== FALSE) {
$extra = $package->getExtra();
$main = '';
if (isset($extra['bower-asset-main'])) $main = $extra['bower-asset-main'];
// check if single value is given, then return a string instead of an array
if (is_array($main) && count($main) == 1){
$main = $this->vendorDir.'/bower-asset/'.$packageName.'/'.$main[0];
}
return $main;
}
}
}
/**
* Main build step
*/
public function build() {
$this->styles();
$this->scripts();
$this->fonts();
$this->images();
}
/**
* Compiles and optimizes SCSS stylesheets
*/
public function styles() {
$this->taskScss(
[
'sources/styles/main.scss' => 'assets/styles/bootgenie.css'
]
)
->addImportPath('sources/styles')
->addImportPath($this->getAssetPath('bootstrap').'/assets/stylesheets')
// add custom function to include plain CSS file
->addImportPath(function($path) {
if (!file_exists($this->getAssetPath('yamm3').$path)) return null;
return $this->getAssetPath('yamm3').$path;
})
->setFormatter('Leafo\ScssPhp\Formatter\Compressed')
->run();
}
/**
* Minimize scripts and put them into the asset folder
*/
public function scripts() {
$this->taskMinify($this->getAssetPath('bootstrap').'assets/javascripts/bootstrap.js')
->to('assets/scripts/bootstrap.js')
->run();
}
/**
* Grab all the fonts and put them in a flattened directory structure
*/
public function fonts() {
$fonts = $this->getAssetPath('bootstrap').'assets/fonts/bootstrap/*';
/*
$this->taskFlattenDir($fonts)
->to('assets/fonts')
->run();
*/
}
/**
* Run lossless compression on all the images.
*/
public function images() {
$this->say('TODO: implement imagemin');
}
/**
* Watch the files and recompile them
*/
public function watch() {
$this->taskWatch()
->monitor('assets/styles/main.scss', function() {
$this->styles();
})
->monitor('assets/styles/bootgenie.scss', function() {
$this->styles();
})
->run();
}
}