0

Wondering what would be the best way to accomplish this.

I have multiple themes in my web app, let's say:

/themes/theme_one/
/themes/theme_two/
… etc.

And I don't want to write one big gulp file that handles all of these. Instead I would like to be able to just write gulp theme_one, and that would run all gulp tasks associated with that theme automatically.

I have realized that what I am really doing is creating a shortcut for gulp --gulpfile themes/theme_one/gulpfile.js

I was thinking a root Gulpfile.js that was something like this:

var gulp   = require('gulp');
var themes = ['theme_one', 'theme_two', 'theme_three'];

themes.forEach(function(theme){
    gulp.task(theme, function(){
        require(__dirname+'/themes/'+theme+'/gulp-tasks.js');
        gulp.run('default'); // all theme gulpfiles need a default task
    });
});

I see though that gulp.run is deprecated. How should I restructure this to avoid using gulp.run?

Torkil Johnsen
  • 2,375
  • 1
  • 18
  • 18

2 Answers2

1

You don't have to use gulp to run various gulp tasks, you can just do cd themes/theme_one/ && gulp or write a program to do that without using gulp.

var path = require('path');
var process = require('child_process');

var themeDir = process.args[0] || 'theme_one';
var directory = path.join(__dirname + '/themes/' + themeDir);

process.exec('cd ' + directory + ' && gulp', function(err, stdout, stderr) {
    if (err) {
        console.log(stderr);
        console.log('err');
    } else {
        console.log(stdout);
    }
});

So you can run this using node index theme_two.

user3995789
  • 3,452
  • 1
  • 19
  • 35
0

Use a gulp task for each theme

You can write your gulpfile and use a task for each process you want.

For example:

// setup requires ...

gulp.task('theme_1', function () {
  return gulp.src( '/theme/1/*/**' )
  .pipe(zip('theme_1.zip'))
  .pipe(gulp.dest('dist'));
});

gulp.task('theme_2', function () {
  return gulp.src( '/theme/2/*/**' )
  .pipe(zip('theme_2.zip'))
  .pipe(gulp.dest('dist'));
});

gulp.task('default', ['theme_1','theme_2']);

You can run your theme task by simply typing:

gulp theme_1
// or
gulp theme_2

Run all your theme tasks by default by just typing gulp

hitautodestruct
  • 20,081
  • 13
  • 69
  • 93