robrich / gulp-if

Conditionally run a task
MIT License
655 stars 29 forks source link

How do you negate? #48

Closed binarykitchen closed 8 years ago

binarykitchen commented 9 years ago
.pipe(gulpIf('!*.map', autoprefixer()))

does not work. How can I skip the autoprefixer when the file ends with *.map?

robrich commented 9 years ago

Negate removed matches from the glob. What you've specified here is "from no selected files, ignore everything that ends with map." Add a positive match first.

binarykitchen commented 9 years ago

@robrich Thanks but I'm sorry I do not understand ...

robrich commented 9 years ago

Bad: .pipe(gulpIf('!*.map', autoprefixer()))

Good: .pipe(gulpIf(['', '!.map'], autoprefixer()))

Bad says "Pick nothing and also don't pick map."

binarykitchen commented 9 years ago

Ah, I see. Many thanks!

binarykitchen commented 9 years ago

@robrich Hello again. I experience issues again. Somehow the following does not work:

    .pipe(gulpIf(['*.scss', '*.css'], autoprefixer(
      ...
    )))

It does not process files ending with .scss or .css at all. How can I achieve this OR combination?

robrich commented 9 years ago

'*.css': CSS files in the current directory

'/.css': CSS files in any child directory one level deep

'*/.css': CSS files in any child directory recursively including the current one

binarykitchen commented 9 years ago

Thanks but I meant, how to test for two different extensions?

Something like

if ('*.scss' or '*.css') then autoprefix()

That OR combination ... how do you do this with gulpIf?

robrich commented 9 years ago

gif(['.css','.scss'], autoprefixer())

binarykitchen commented 9 years ago

No, this doesn't work. I tried various combinations:

cssTransform = (filename, sources) ->
  gulp.src(sources)
    .pipe(gulpIf('*.scss', rubySass(config.sass)))
    .pipe(gulpIf(['*.css', '*.scss'], autoprefixer(
      '> 1%'
      'last 5 versions'
      'Firefox ESR'
    )))
    .pipe(concat(filename))
    .pipe(gulpIf(config.compress, minifyCSS()))
    .pipe(gulp.dest("#{paths.public}/styles"))
    .pipe(tap(logFile))

Like that the autoprefixer won't process CSS files.

But if I change to

    .pipe(gulpIf('*.css', autoprefixer(
      '> 1%'
      'last 5 versions'
      'Firefox ESR'
    )))

then CSS files only become autprefixed.

Somehow gif(['*.css','*.scss'], autoprefixer()) is not working. A bug?

robrich commented 9 years ago

Interesting. Do you have a pastebin or a github link?

binarykitchen commented 9 years ago

I'm afraid, it's a private project. But can you please add the above scenario to your unit tests? A glob with two different file types (OR combination).

robrich commented 9 years ago

See https://github.com/robrich/gulp-match/blob/master/test/array.js

binarykitchen commented 9 years ago

On what line? I do not see the same scenario

edouard-lopez commented 9 years ago

I'm trying to concat dist scripts (the minified files from each lib) with the result of uglify on the one that aren't minified.

Sources

I got a list af scripts such as:

var bower = {
    scripts_vendor: [
        'bower_components/ng-breadcrumbs/dist/ng-breadcrumbs.min.js',
        'bower_components/d3/d3.min.js',
        'bower_components/bootstrap/dist/js/bootstrap.min.js',

        'bower_components/ui.bootstrap/src/position/position.js',
        'bower_components/ui.bootstrap/src/progressbar/progressbar.js'    
    ]
}

Task

and a task as:

gulp.task('scripts_vendor', function () {
    return gulp.src(bower.scripts_vendor)
            .pipe(gulpif(/ui\.bootstrap/, uglify({mangle: false})))
            .pipe(concat('vendor.min.js'))
            .pipe(gulp.dest('../static/js'));
});

This works but look awkard as it may be difficlut to maintain.

Question

I tried to use !/min/ at first but it doesn't minify the non-minified files.

robrich commented 9 years ago

From the docs at https://github.com/robrich/gulp-if: use a condition function.

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

var uglify = require('gulp-uglify');

var beautify = require('gulp-beautify');

var condition = function (file) {

// TODO: add business logic

return true;

}

gulp.task('task', function() {

gulp.src('./src/*.js')

.pipe(gulpif(condition, uglify(), beautify()))

.pipe(gulp.dest('./dist/'));

});