Skip to content

Instantly share code, notes, and snippets.

@frodosghost
Last active March 24, 2016 16:12
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/745ca78e904e460bbca5 to your computer and use it in GitHub Desktop.
Save frodosghost/745ca78e904e460bbca5 to your computer and use it in GitHub Desktop.
Dependency Inception: Composer, Installing NPM, Installing Bower
{
"name": "bower install",
"description": "Install Bower from Composer",
"version": "0.0.0",
"homepage": "https://antelopestudios.com.au",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "1.4.x",
"angular-mocks": "1.4.x",
"angular-resource": "1.4.x",
"angular-route": "1.4.x",
}
}
{
"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::npmInstall",
"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::npmInstall",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
....
# Bower and NPM
/app/Resources/public/js/*
/node_modules/*
{% block foot_script %}
{% javascripts
'%kernel.root_dir%/Resources/public/js/angular/angular.js'
'%kernel.root_dir%/Resources/public/js/angular-route/angular-route.js'
'%kernel.root_dir%/Resources/public/js/angular-resource/angular-resource.js'
'@AppBundle/Resources/public/js/your-script.js'
output="js/dashboard.js"
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock foot_script %}
{
"version": "0.0.0",
"private": true,
"name": "npm packages",
"description": "Install NPM from Composer",
"license": "MIT",
"devDependencies": {
"karma": "^0.12.16",
"karma-chrome-launcher": "^0.1.4",
"karma-firefox-launcher": "^0.1.3",
"karma-jasmine": "~0.1.0",
"tmp": "0.0.23",
"bower": "^1.3.1",
"shelljs": "^0.2.6"
},
"scripts": {
"postinstall": "bower install",
"prestart": "npm install",
"pretest": "npm install",
"test": "node node_modules/karma/bin/karma start test/karma.conf.js",
"test-single-run": "node node_modules/karma/bin/karma start test/karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update"
}
}
<?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>");
}
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/angular/angular.js'
'%kernel.root_dir%/Resources/public/js/angular-route/angular-route.js'
'%kernel.root_dir%/Resources/public/js/angular-resource/angular-resource.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