Skip to content

Commit 163f8c3

Browse files
committed
Merge pull request #3 from xelax90/master
Added package.json as config file
2 parents 67b4e31 + b879fb8 commit 163f8c3

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/BowerModule/Bower/Service.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,20 @@ public function getModulePaths($module, $minified = false)
197197

198198
/**
199199
* Returns path to bower.json for specified module
200+
* If usePackageJson option is set to true and bower.json is not readable, returns path to package.json
200201
* @param string $module
201202
* @return string
202203
*/
203204
public function getModuleBowerConfigFilePath($module)
204205
{
205-
return $this->getPathBuilder()->getOsPath($this->getBowerFolder(), $module, 'bower.json');
206+
$path = $this->getPathBuilder()->getOsPath($this->getBowerFolder(), $module, 'bower.json');
207+
if(!is_readable($path) && $this->getConfig()->getUsePackageJson()){
208+
$path = $this->getPathBuilder()->getOsPath($this->getBowerFolder(), $module, 'package.json');
209+
}
210+
if(!is_readable($path)){
211+
throw new \RuntimeException('Failed to access configuration for "'.$module.'".');
212+
}
213+
return $path;
206214
}
207215

208216
/**
@@ -214,10 +222,6 @@ public function getModuleBowerConfig($module)
214222
{
215223
//TODO add caching
216224
$filePath = $this->getModuleBowerConfigFilePath($module);
217-
if (!is_readable($filePath))
218-
{
219-
throw new \RuntimeException('Failed to access configuration for "'.$module.'".');
220-
}
221225
$config = file_get_contents($filePath);
222226
if ($config === false)
223227
{

src/BowerModule/Config/Module.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ class Module extends AbstractOptions
3838
* @var bool
3939
*/
4040
protected $debugMode;
41-
41+
/**
42+
* Set to true if you want to scan for package.json file in addition to bower.json
43+
* @var bool
44+
*/
45+
protected $usePackageJson = false;
46+
4247
/**
4348
* @param array|Folder $bowerFolder
4449
*/
@@ -154,4 +159,12 @@ public function getDebugMode()
154159
{
155160
return (bool) $this->debugMode;
156161
}
162+
163+
public function getUsePackageJson() {
164+
return (bool) $this->usePackageJson;
165+
}
166+
167+
public function setUsePackageJson($usePackageJson) {
168+
$this->usePackageJson = $usePackageJson;
169+
}
157170
}

src/BowerModule/View/Helper/Bower.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function __invoke(
7676
{
7777
$bower = $this->getBower();
7878
$modules = $bower->findDependencies($pack->getModules());
79+
if($place == self::PLACE_PREPEND){
80+
$modules = array_reverse($modules);
81+
}
7982
foreach ($modules as $moduleName)
8083
{
8184
$insert($pathBuilder->getDebugWebPath($moduleName));

0 commit comments

Comments
 (0)