Nick
Nick

Reputation: 14293

gulp - variable argument in task

I've checked already some other answers here on stack overflow (23023650, 28538918), but they all seam to cover something that is slightly different from what I'm after.

Basically, what i'd like to do is something like this:

gulp compileUnit -about

where about is my page name.

The goal here for me is to be able to use different pages, and change the path according to the page.

Little example:

var argv = require('yargs');
var gulpif = require('gulp-if');

var singleUnit = argv; //hoping that singleUnit = about

var paths: {compile: [singleUnit],...}
gulp.task('compileUnit', function (done) {
    gulp.src(paths.compile)
        .pipe(coffee({bare: true})
            .on('error', gutil.log.bind(gutil, 'Coffee Error')))
        .pipe(concat('unit.js'))
        .pipe(gulp.dest('./src/tests/unit/'))
        .on('end', done)
});

The code above should be pretty easy, but I'll explain a bit more in detail:

I'd like to set singleUnit value to be the param I typed in (gulp compileUnit -about) so that the path to run gulp compileUnit changes to about.

I hope this is clear enough. Any help will be really appreciated.

Thanks

Upvotes: 0

Views: 97

Answers (1)

RWAM
RWAM

Reputation: 7018

You already use gulp-util. What's about with a similar solution like https://stackoverflow.com/a/23088183/1295622?

var singleUnit = gutil.env.page; //hoping that singleUnit = about

var paths: {compile: [singleUnit],...}

gulp.task('compileUnit', function (done) {
    gulp.src(paths.compile)
        .pipe(coffee({bare: true})
            .on('error', gutil.log.bind(gutil, 'Coffee Error')))
        .pipe(concat('unit.js'))
        .pipe(gulp.dest('./src/tests/unit/'))
        .on('end', done)
});

And then

gulp compileUnit --page about

Upvotes: 1

Related Questions