Skip to content

Instantly share code, notes, and snippets.

@frodosghost
Last active March 24, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frodosghost/2eed1b3667cd7e5225c7 to your computer and use it in GitHub Desktop.
Save frodosghost/2eed1b3667cd7e5225c7 to your computer and use it in GitHub Desktop.
Dependency Inception: Installing Bower dependencies with Composer
{
"name": "bower install",
"description": "Install Bower from Composer",
"version": "0.0.0",
"homepage": "https://antelopestudios.com.au",
"license": "MIT",
"private": true,
"dependencies": {
"jquery": "~2.1.1",
}
}
{
"directory": "app/Resources/public/js",
"interactive": false
}
....
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"AppBundle\\Composer\\ScriptHandler::bowerInstall",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"AppBundle\\Composer\\ScriptHandler::bowerInstall",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
....
{% block foot_script %}
{% javascripts
'%kernel.root_dir%/Resources/public/js/jquery/dist/jquery.js'
'@AppBundle/Resources/public/js/your-script.js'
output="js/dashboard.js"
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
<?php
namespace AppBundle\Composer;
use Composer\Script\Event;
use Symfony\Component\Process\Process;
/**
* Script for Running NPM as part of Composer Update
*
*/
class ScriptHandler
{
public static function npmInstall(Event $event)
{
$IO = $event->getIO();
$IO->write("Running NPM Install", false);
static::executeCommand($event, 'npm install');
$IO->write(" ... <info>OK</info>");
}
public static function bowerInstall(Event $event)
{
$IO = $event->getIO();
$IO->write("Running Bower Install", false);
static::executeCommand($event, 'bower install');
$IO->write(" ... <info>OK</info>");
}
protected static function executeCommand(Event $event, $cmd, $timeout = 300)
{
$process = new Process($cmd, null, null, null, $timeout);
$process->run(function ($type, $buffer) use ($event) { $event->getIO()->write($buffer, false); });
if (!$process->isSuccessful()) {
throw new \RuntimeException(sprintf("An error occurred when executing the \"%s\" command:\n\n%s\n\n%s.", escapeshellarg($cmd), $process->getOutput(), $process->getErrorOutput()));
}
}
}
{% block foot_script %}
{% javascripts
'%kernel.root_dir%/Resources/public/js/jquery/dist/jquery.js'
'@AppBundle/Resources/public/js/your-script.js'
output="js/dashboard.js"
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment