Skip to content

Commit 82415fd

Browse files
author
Teppo Koivula
committed
Automatically PascalCase module directory name and attempt to resolve site/site/ issues when installing modules from site directory
1 parent 0b4b40a commit 82415fd

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.5] - 2019-06-16
11+
12+
### Changed
13+
- Convert installed module directories automatically to Pascal Case.
14+
- Modify base path when installing from the site directory to avoid nested site/site/ directories.
15+
1016
## [0.0.4] - 2019-06-10
1117

1218
### Fixed

src/ComposerInstaller/BaseInstaller.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function supports($packageType)
4343
* @return string Base path.
4444
*/
4545
protected function getBasePath($defaultBasePath) {
46+
// if we're already in the site directory, remove "site/" from the beginning
47+
// of the default base path to avoid creating nested /site/site/ directories
48+
if (basename(\getcwd()) === 'site' && substr($defaultBasePath, 0, 5) === 'site/') {
49+
$defaultBasePath = substr($defaultBasePath, 5);
50+
}
51+
4652
// get the extra configuration of the top-level package
4753
$extra = [];
4854
if ($rootPackage = $this->composer->getPackage()) {
@@ -70,7 +76,7 @@ protected function getBasePath($defaultBasePath) {
7076
* "installer-name" in the composer.json of the package in question.
7177
*
7278
* @param PackageInterface $package
73-
* @return string Module or site profile name.
79+
* @return string Module or site profile directory name.
7480
*/
7581
protected function getName(PackageInterface $package) {
7682
// determine the directory name from its package name

src/ComposerInstaller/ModuleInstaller.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,42 @@ public function getInstallPath(PackageInterface $package)
3535
{
3636
return $this->getFullPath($package, static::BASE_PATH);
3737
}
38+
39+
/**
40+
* Get the directory name from package name
41+
*
42+
* Default directory name can be overridden by specifying extra argument
43+
* "installer-name" in the composer.json of the package in question.
44+
*
45+
* @param PackageInterface $package
46+
* @return string Module directory name.
47+
*/
48+
protected function getName(PackageInterface $package) {
49+
// fetch initial directory name
50+
$name = parent::getName($package);
51+
52+
// make sure that the directory name is in Pascal Case
53+
$name = $this->pascalCase($name);
54+
55+
return $name;
56+
}
57+
58+
/**
59+
* Convert string to Pascal Case
60+
*
61+
* Typically used for ProcessWire module directory names, which are loosely
62+
* expected to follow a PascalCase type naming convention.
63+
*
64+
* @param string $string
65+
* @return string String in PascalCase
66+
*/
67+
protected function pascalCase($string) {
68+
$replace_chars = [
69+
'_',
70+
'-',
71+
'/',
72+
' '
73+
];
74+
return str_replace($replace_chars, '', ucwords($string, implode($replace_chars)));
75+
}
3876
}

src/ComposerInstaller/SiteProfileInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getInstallPath(PackageInterface $package)
6767
* "installer-name" in the composer.json of the package in question.
6868
*
6969
* @param PackageInterface $package
70-
* @return string Module or site profile name.
70+
* @return string Site profile directory name.
7171
*/
7272
protected function getName(PackageInterface $package) {
7373
// fetch initial directory name

0 commit comments

Comments
 (0)