Skip to content

Commit 9000911

Browse files
committed
Merge branch 'develop'
2 parents 8b0e9ef + a85c036 commit 9000911

10 files changed

+384
-140
lines changed

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
php:
3+
- "5.5"
4+
- "5.4"
5+
- "5.3"
6+
before_install:
7+
- composer self-update
8+
install:
9+
- composer install --no-interaction --prefer-source
10+
script:
11+
- ./vendor/bin/phpcs .
12+
- ./vendor/bin/phpunit

CustomInstaller.php

-93
This file was deleted.

README.md

+56-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,80 @@
11
Composer Custom Type Installer
22
==============================
3+
[![Build Status](https://travis-ci.org/davidbarratt/custom-installer.svg?branch=develop)](https://travis-ci.org/davidbarratt/custom-installer)
4+
35
Adds a root-level custom [type](https://getcomposer.org/doc/04-schema.md#type) installer path to composer.json. Any custom type can be used to define a path the [type](https://getcomposer.org/doc/04-schema.md#type) should be installed in.
46

57
## Installation
68
Simply require this library in your composer.json file. Typically this will be added as a dependency of the custom [type](https://getcomposer.org/doc/04-schema.md#type) to ensure that the library is loaded before the library that needs it. However, this can be added to the root composer.json, as long as it goes before any library that needs it.
79
```json
810
{
911
"require": {
10-
"davidbarratt/custom-installer": "1.0.*@alpha"
12+
"davidbarratt/custom-installer": "1.0.*@dev"
1113
}
1214
}
1315
```
1416

1517
## Usage
16-
The added parameter(s) are only allowed on the root to avoid conflicts between multiple libraries. This also prevents a project owner from having a directory accidentally wiped out by a library.
18+
The added parameter(s) are only allowed on the root to avoid conflicts between multiple libraries. This also prevents a project owner from having a directory accidentally wiped out by a library. Note: Each package will go in it’s respective folder in the order in which they are installed.
19+
20+
The configuration has to be added in `custom-installer` of `composer.json`'s `extra` section. It is similar to [Composer installer's installation paths](https://github.com/composer/installers#custom-install-paths).
21+
22+
### Pattern syntax
23+
24+
The key of the the configuration array is the path pattern. You can use some
25+
replacement tokens:
26+
27+
- `{$name}`: The name of the package (e.g. `yaml` of `symfony/yaml`)
28+
- `{$vendor}`: The vendor of the package (e.g. `symfony` of `symfony/yaml`)
29+
- `{$type}`: for the composer package type (e.g. `library`, `drupal-module`)
30+
31+
### Package filters
32+
33+
The value of the configuration array has to be an array. It holds the package
34+
filter for the given pattern. The pattern will be applied if any filter matches.
35+
36+
#### Package type filter
1737

18-
#### custom-installer (root-level)
19-
You may use [Composer Installer](https://github.com/composer/installers) type [installation paths](https://github.com/composer/installers#custom-install-paths) with the variables `{$name}`, `{$vendor}`, and `{$type}`. Each package will go in it’s respective folder in the order in which they are installed.
38+
With `type:[package-type]` you can define a pattern per package type. You can use
39+
any custom package type and [are not limited to a predefined set](https://github.com/composer/installers#should-we-allow-dynamic-package-types-or-paths-no).
40+
41+
Composer specific package types `metapackage` or `composer-plugin` will never be
42+
handled by _Custom Installer_.
43+
44+
Example: `type:custom-library` for package type `custom-library`
45+
46+
#### Package name filter
47+
48+
You can specify a pattern per full package name (`[vendor]/[name]`).
49+
50+
_Custom Installer_ will only handle a specific package if a configuration exists
51+
that also handles the package type in general.
52+
53+
### Examples
2054

2155
```json
2256
{
2357
"extra": {
2458
"custom-installer": {
25-
"drupal-core": "web/",
26-
"drupal-site": "web/sites/{$name}/",
27-
"random-type": "custom/{$type}/{$vendor}/{$name}/"
59+
"web/": ["type:drupal-core"],
60+
"web/sites/{$name}/": ["type:drupal-site"],
61+
"custom/{$type}/{$vendor}/{$name}/": ["type:random-type"],
62+
"vendor/{$vendor}/{$name}/": ["type:library"],
63+
"web/sites/all/libraries/{$name}/": [
64+
"type:component",
65+
"ckeditor/ckeditor",
66+
"flesler/jquery.scrollto"
67+
],
68+
"custom-folder-for-single-package": ["myvendorname/single-package"],
2869
}
2970
}
3071
}
3172
```
73+
74+
In the example we want to make sure _CKEditor_ and _Jquery ScrollTo_ will be
75+
placed in `web/sites/all/libraries`. Both packages are of of package type
76+
`library`. In order to change the path of those packages, we must declare a
77+
fallback for the package type `library`. It shall stay in the default vendor
78+
location (as `library` is the default composer package type). If you do not do
79+
that the custom installer cannot handle the single packages (`ckeditor` and
80+
`flesler/jquery.scrollto` ) due to [the way composer installer plugins work](https://github.com/composer/composer/pull/4059).

Tests/CustomInstallerTest.php

+72-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
/**
3-
* Custom Installer Test.
4-
*
5-
* @author David Barratt <[email protected]>
6-
* @copyright Copyright (c) 2014, David Barratt
7-
*/
3+
* Custom Installer Test.
4+
*
5+
* @author David Barratt <[email protected]>
6+
* @copyright Copyright (c) 2014, David Barratt
7+
*/
88
namespace DavidBarratt\CustomInstaller\Tests;
99

1010
use DavidBarratt\CustomInstaller\CustomInstaller;
@@ -17,16 +17,21 @@
1717
class CustomInstallerTest extends PHPUnit_Framework_TestCase
1818
{
1919

20-
/**
21-
* testInstallPath
22-
*
23-
* @dataProvider dataForInstallPath
24-
*/
25-
public function testInstallPath($name, $type, $path, $expected)
20+
/**
21+
* Tests installation path for given package/spec combination.
22+
*
23+
* @param string $name Full package name (including vendor)
24+
* @param string $type Composer package type
25+
* @param array $spec Custom-Installer configuration
26+
* @param string $expected Expected path
27+
*
28+
* @dataProvider dataForInstallPath
29+
*/
30+
public function testInstallPath($name, $type, $spec, $expected)
2631
{
2732

2833
$composer = new Composer();
29-
$config = new Config();
34+
$config = new Config(false, realpath('.'));
3035
$composer->setConfig($config);
3136

3237
$repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
@@ -38,37 +43,73 @@ public function testInstallPath($name, $type, $path, $expected)
3843
$consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
3944
$composer->setPackage($consumerPackage);
4045
$consumerPackage->setExtra(array(
41-
'custom-installer' => array(
42-
$type => $path,
43-
),
46+
'custom-installer' => $spec,
4447
));
4548
$result = $installer->getInstallPath($package);
4649
$this->assertEquals($expected, $result);
4750
}
4851

52+
/**
53+
* Data provider for testing multiple install paths.
54+
*
55+
* @return array
56+
*/
4957
public function dataForInstallPath()
5058
{
51-
return array(
59+
return array(
60+
array(
61+
'davidbarratt/davidwbarratt',
62+
'drupal-site',
63+
array('drupal-site' => 'sites/{$name}/'),
64+
'sites/davidwbarratt/',
65+
),
66+
array(
67+
'awesome/package',
68+
'custom-type',
69+
array('custom-type' => 'custom/{$vendor}/{$name}/'),
70+
'custom/awesome/package/',
71+
),
72+
array(
73+
'drupal/core',
74+
'drupal-core',
75+
array('drupal-core' => 'web/'),
76+
'web/',
77+
),
78+
// Without spec.
79+
array(
80+
'package/without-spec',
81+
'library',
82+
array(),
83+
realpath('.') . '/vendor/package/without-spec',
84+
),
85+
// New format
86+
array(
87+
'config/with-new-format',
88+
'custom-type',
5289
array(
53-
'davidbarratt/davidwbarratt',
54-
'drupal-site',
55-
'sites/{$name}/',
56-
'sites/davidwbarratt/',
90+
'custom/{$type}/{$vendor}/{$name}/' => array('type:custom-type'),
5791
),
92+
'custom/custom-type/config/with-new-format/',
93+
),
94+
// Per package
95+
array(
96+
'config/per-package',
97+
'custom-type',
5898
array(
59-
'awesome/package',
60-
'custom-type',
61-
'custom/{$vendor}/{$name}/',
62-
'custom/awesome/package/',
99+
'custom/{$vendor}/{$name}/' => array('config/per-package'),
63100
),
101+
'custom/config/per-package/',
102+
),
103+
// Package over type
104+
array(
105+
'config/package-over-type',
106+
'custom-type',
64107
array(
65-
'drupal/core',
66-
'drupal-core',
67-
'web/',
68-
'web/',
108+
'type-folder/{$vendor}/{$name}/' => array('type:custom-type'),
109+
'package-folder/{$vendor}/{$name}/' => array('config/package-over-type'),
69110
),
70-
);
111+
'package-folder/config/package-over-type/',
112+
),
113+
);
71114
}
72-
73-
74115
}

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
"homepage": "https://github.com/davidbarratt/custom-installer",
77
"autoload": {
88
"psr-4": {
9-
"DavidBarratt\\CustomInstaller\\": ""
9+
"DavidBarratt\\CustomInstaller\\": "src"
1010
}
1111
},
1212
"extra": {
1313
"class": "DavidBarratt\\CustomInstaller\\CustomInstallerPlugin"
1414
},
1515
"require": {
16-
"composer-plugin-api": "1.0.0"
16+
"composer-plugin-api": "~1.0"
1717
},
1818
"require-dev": {
19-
"composer/composer": "1.0.*@dev",
20-
"phpunit/phpunit": "4.1.*"
19+
"composer/composer": "~1.0@dev",
20+
"phpunit/phpunit": "~4.1",
21+
"squizlabs/php_codesniffer": "~2.5"
2122
}
2223
}

phpcs.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="custom-installer">
3+
<description>The coding standard for Custom Installer.</description>
4+
<exclude-pattern>vendor/</exclude-pattern>
5+
<rule ref="PSR2"></rule>
6+
</ruleset>

0 commit comments

Comments
 (0)