Running Gulp Tasks During Composer Installation

I am deploying a PHP application to Heroku using Composer. I am currently using Gulp to compress CSS / JS and transfer it to a Git repository. I was wondering if it makes sense to run Gulp tasks with Composer post-install-cmd . What is the best thing for?

+5
source share
4 answers

You use the so-called "multi-line package" to execute both Node.js (for installing Gulp) and PHP for deployment.

Here is an example that I built some time ago that uses Bower to install Bootstrap in Composer post-install-cmd , but the principle will be the same:

http://heroku-multipack-nodejs-php-ex.herokuapp.com

Sources with README that explain the process: https://github.com/dzuelke/heroku-multipack-nodejs-php-example

You can also use the composer compile step if you prefer the Gulp installation not to run on each composer install : https://devcenter.heroku.com/articles/php-support#custom-compile-step

+4
source

gulp provides flexible tools for team tasks, so it is probably best to use gulp to update or install composer dependencies? Take a look at this gulp-composer package.

Example:

 composer = require('gulp-composer'); gulp.task('composer', function () { composer({ cwd: './php-stuff', bin: 'composer' }); }); 
+1
source

Think of Gulp as a one-stop job for tasks, rather than using Composer post-install-cmd (or similar) to fix additional tasks. The PHP package manager should not be responsible for retrieving or compressing front-end assets, not for the job. Gulp is not just for interface related tasks.

For me, it is most convenient to use gulp-composer .

+1
source

I would recommend using the Symfony Process Component for this inside some script handler and then running it as post-install-cmd , as you said.

scripts / composer / ScriptHandler.php

 use Composer\Script\Event; use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; class ScriptHandler { public static function gulpBuild(Event $event) { $process = new Process('cd /path/to/my/theme && gulp build'); $process->run(); // executes after the command finishes if (!$process->isSuccessful()) { throw new ProcessFailedException($process); $event->getIO()->write($process->getOutput()); } else { $event->getIO()->write("Recompiled and compressed CSS/JS"); } } } 

composer.json

 "autoload": { "classmap": [ "scripts/composer/ScriptHandler.php" ] }, "scripts": { "post-update-cmd": [ "DrupalProject\\composer\\ScriptHandler::gulpBuild" ] }, 

Check out the composer template for Drupal projects for more inspiration. (For example, a dynamic path to your topic so that this command runs successfully in each environment.)

0
source

Source: https://habr.com/ru/post/1214311/


All Articles