Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgarlag committed Mar 4, 2013
0 parents commit ee1b41b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2013 Antonio J. García Lagar <[email protected]>

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions of
the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AjglComposerSymlinker
=====================

The AjglComposerSymlinker script allows you to easily symlink assets after composer assets installation.

License
-------

This component is under the MIT license. See the complete license in the LICENSE file.

About
-----

AjglComposerSymlinker is an [ajgarlag](http://aj.garcialagar.es) initiative.
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "ajgl/composer-symlinker",
"description": "Composer script to symlink assets.",
"keywords": ["composer", "assets", "composer"],
"homepage": "https://github.com/ajgarlag/AjglComposerSymlinker",
"license": "MIT",
"authors": [
{
"name": "Antonio J. García Lagar",
"email": "[email protected]",
"homepage": "http://aj.garcialagar.es",
"role": "developer"
}
],
"require": {
"symfony/filesystem": ">=2.1.0"
},
"require-dev": {
"composer/composer": "*@dev"
},
"autoload": {
"psr-0": {
"Ajgl": "src/"
}
}
}
45 changes: 45 additions & 0 deletions src/Ajgl/Composer/ScriptSymlinker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace Ajgl\Composer;
/**
* @category Ajgl
* @package Ajgl\Composer
*/
use Composer\Script\Event;
use Symfony\Component\Filesystem\Filesystem;

/**
* Script to symlink resources installed with composer
*
* @author Antonio J. García Lagar <[email protected]>
*/
class ScriptSymlinker
{
public static function createSymlinks(Event $event)
{
$symlinks = static::getSymlinks($event);
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
$fs = new Filesystem();

foreach ($symlinks as $package => $symlinksDefinition) {
foreach ($symlinksDefinition as $origin => $target) {
$originPath = realpath($vendorDir) . "/$package/$origin";
$targetPath = realpath($vendorDir) . "/$target";
$event->getIO()->write("Symlinking <comment>$originPath</comment> --> <comment>$targetPath</comment>");
$fs->symlink($originPath, $targetPath);
}
}
}

protected static function getSymlinks(Event $event)
{
$options = $event->getComposer()->getPackage()->getExtra();
$symlinks = array();

if (isset($options['ajgl-symlinks']) && is_array($options['ajgl-symlinks'])) {
$symlinks = $options['ajgl-symlinks'];
}

return $symlinks;
}
}

0 comments on commit ee1b41b

Please sign in to comment.