Last active
March 24, 2016 16:08
-
-
Save frodosghost/2eed1b3667cd7e5225c7 to your computer and use it in GitHub Desktop.
Dependency Inception: Installing Bower dependencies with Composer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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", | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"directory": "app/Resources/public/js", | |
"interactive": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
"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" | |
] | |
}, | |
.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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())); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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