How to install/update javascript vendors in symfony2 project?
There may be fancier ways... but I just use the paths in my base template like so:
{% javascripts filter='yui_js' '../vendor/twitter/bootstrap/js/bootstrap-tab.js' '../vendor/harvesthq/chosen/coffee/lib/select-parser.coffee' '../vendor/harvesthq/chosen/coffee/lib/abstract-chosen.coffee' '../vendor/harvesthq/chosen/coffee/chosen.jquery.coffee' '@SOTBCoreBundle/Resources/public/js/script.js'%} <script src="{{ asset_url }}"></script>{% endjavascripts %}
Composer can be used to manage javascript dependencies as well. By default composer is using only one repository called Packagist which is a repository for PHP libraries only. However, as suggested here, you can add your own repositories for javascript (or any other) libraries.
Here's my composer.json that adds a custom knockout-js repository:
{ "require": { "php": ">=5.3.2", "symfony/symfony": ">=2.0.10,<2.1.0-dev", "doctrine/orm": ">=2.1.0,<2.2.0-dev", "twig/extensions": "*", "symfony/assetic-bundle": "2.0.*", "sensio/generator-bundle": "2.0.*", "sensio/framework-extra-bundle": "2.0.*", "sensio/distribution-bundle": "2.0.*", "jms/security-extra-bundle": "1.0.*", "knockout/knockout-js": "2.1.0" }, "autoload": { "psr-0": { "Acme": "src/" } }, "repositories": [ { "type": "package", "package": { "name": "knockout/knockout-js", "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/SteveSanderson/knockout.git", "reference": "v2.1.0" } } }, { "type": "package", "package": { "name": "knockout/knockout-js", "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/SteveSanderson/knockout.git", "reference": "v2.0.0" } } } ]}
Repository consists of packages (which is combination of source and version of library). Here I have 2 packages (2.1.0, 2.0.0) that already contain pre-built source of knockout.js, so you don't have to compile anything.
Now, there are times when you might want to compile and use latest code. To automate this routine, i figured, one can use git post-checkout hook.Add a new package that refers to the latest code:
{ "type": "package", "package": { "name": "knockout/knockout-js", "version": "master", "source": { "type": "git", "url": "https://github.com/SteveSanderson/knockout.git", "reference": "master" } } }
Reference this package in require section:
"knockout/knockout-js": "master"
And a post-checkout hook with build instructions. For knockout.js it is simple:
// vendor/knockout/knockout-js/.git/hooks/post-checkout#!/bin/shecho "Building knockout.js";`cd build && ./build-linux`;