2

I would to know how I can run a drush command like drush @alias cc all with a gulp workflow ?

This is my starting code:

var plugins = require('gulp-load-plugins')();
    gulp.task('drush:cc', function () {

      return gulp.src(source)
        .pipe(plugins.shell([
          'drush @vmdevd6mg cc all'
        ])) 
        .pipe(plugins.notify({
          title: "Caches cleared",
          message: "Drush Drupal CSS/JS caches cleared.",
          onLast: true
        }));
    });

Thanks EDIt: another way to run drush but seem not to work too,no error message given.

// Run drush to clear the theme registry.
gulp.task('drush', plugins.shell.task([
   'drush @vmdevd6mg cc all'
]));

both tasks give:

gulp drush 
Error: spawn drush @vmdevd6mg cc all ENOENT

EDIT1: New test

My new task and the result:

//Vidage de cache Drupal avec Drush
gulp.task('drush', function() {
  return gulp.src(basePaths.drushscript, {
      read: false
    })

    .pipe(plugins.shell([
      'drush @vmdevd6pf cron && drush @vmdevd6pf cc all'

    ]))
    .pipe(plugins.notify({
      title: "Vidage de Cache",
      message: "Cache Drupal vidé complètement.",
      onLast: true
    }));
});

Part of the global launch task:

gulp.watch(folderPaths.js.jsd68, ['drush']);

Give:

 /bin/sh: 1: drush: Permission denied

    events.js:160
          throw er; // Unhandled 'error' event
          ^
    Error: Command `drush @vmdevd6pf cron && drush @vmdevd6pf cc all` failed with exit code 127

EDIT: final gulp task work like //Vidage de cache Drupal avec child_process - 2020-06

gulp.task('drush-cp', function(done) {
  return cp.spawn('drush', ['cache-rebuild'], {stdio: 'inherit'})
  .on('close', done)
   /*  .pipe(plugins.notify({
    title: "Vidage de Cache avec Drush",
    message: "Cache Drupal vidé complètement.",
    onLast: true
  })); */
  ;
});
14
  • Well, have you installed gulp shell plugin?
    – Kevin
    Commented Apr 28, 2017 at 10:12
  • yes I did install it.
    – user8753
    Commented May 2, 2017 at 14:24
  • What is supposed to call this task?
    – Kevin
    Commented May 2, 2017 at 14:25
  • This task is suppose to clear cache of a D6 site with using drush 8 and alias
    – user8753
    Commented May 3, 2017 at 9:10
  • No., what calls this task?
    – Kevin
    Commented May 3, 2017 at 10:50

1 Answer 1

2

Try:

The first thing you’ll need is to import the dependency for “child process.” Next, you’ll want to set up an array variable containing all the paths to files you want auto-cache clearing setup for. This will basically be any Drupal template file. I would start with the main template directories you know you need it set up for and then add the additional paths along the way. Once we have our variables set, we then build our “clearcache” task using the “child_process” dependency that is shown below. Once we have all the pieces setup, we combine them in a watch task and let the magic happen! Using this task in your workflow will save you so much time, and even more importantly, save you the headache of clearing your cache every 2 minutes.

If you do run into some issues having your task running, make sure your Drush is setup and working in your command line as these Gulp task relies on Drush to complete its work.

code:

var cp = require('child_process');
var drupal_files = "paths/to/your/drupal/files/you/want/auto-cache-clearing";
 
// Clearcache Task
gulp.task('clearcache', function(done) {
  return cp.spawn('drush', ['cache-rebuild'], {stdio: 'inherit'})
  .on('close', done);
});
 
gulp.watch(drupal_files, ['clearcache']);

Source: http://serversideguy.com/2018/02/05/how-can-i-automatically-clear-cache-for-drupal-using-gulp/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.