diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dd3db55 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2013 Antonio J. García Lagar + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a969100 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c57bf4b --- /dev/null +++ b/composer.json @@ -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": "aj@garcialagar.es", + "homepage": "http://aj.garcialagar.es", + "role": "developer" + } + ], + "require": { + "symfony/filesystem": ">=2.1.0" + }, + "require-dev": { + "composer/composer": "*@dev" + }, + "autoload": { + "psr-0": { + "Ajgl": "src/" + } + } +} diff --git a/src/Ajgl/Composer/ScriptSymlinker.php b/src/Ajgl/Composer/ScriptSymlinker.php new file mode 100644 index 0000000..4f69741 --- /dev/null +++ b/src/Ajgl/Composer/ScriptSymlinker.php @@ -0,0 +1,45 @@ + + */ +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 $originPath --> $targetPath"); + $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; + } +} +