gulpjs / gulp-util

[deprecated] - See https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
MIT License
830 stars 103 forks source link

Feature Request : Not Glob Pattern #87

Closed jmorille closed 9 years ago

jmorille commented 9 years ago

Add a function that revert a glob pattern expression. the ain is to have

notGlob('**/*.{scss,sass}') = '!**/*.{scss,sass}'

or

 notGlob(!bower_components{,/**}' )=  'bower_components{,/**}',

A possible implementation could be something like that

var notGlob = function (elt) {
  if (!elt) {
    return undefined;
  }
  if ('string' === typeof elt) {
    if ('!' === elt.slice(0, 1)) {
      return elt.slice(1);
    } else {
      return '!' + elt;
    }
  } else if (Array.isArray(elt)) {
    return elt.reduce(function (acc, current) {
      var notelt = notGlob(current);
      if (notelt) {
        acc.push(notelt);
      }
      return acc;
    }, []);
  }
};
jmorille commented 9 years ago

The common use case is when you write some pattern for sass, and you want to copy the unmangement files... like this sample, I believe that could be very usefull for many people and a good place to be.

var config_cp = {
  src_patch: ['**', notGlob(src.sass), notGlob(src.bower_components)]
}

gulp.task('cp', function (cb) {
  var DEST_DIR = path.build_generated;
  return gulp.src(config_cp.src_patch, { cwd:path.app,  base: path.app})
    .pipe(cache('cping', {optimizeMemory: true}))
    .pipe(changed(DEST_DIR))
    .pipe(debug({title: 'changed:'}))
    .pipe(gulp.dest(DEST_DIR));
});

gulp.task('sass', function () {
  var DEST_DIR = path.build_generated;
  var SASS_OPTS = prod ? {outputStyle: 'compressed'} : {};
  return gulp.src(src.sass, {cwd: path.app,  base: path.app  })
    .pipe(cache('sassing', {optimizeMemory: true}))
    .pipe(changed(DEST_DIR, {extension: '.css'}))
    .pipe(debug({title: 'changed:'}))
    .pipe(sass(SASS_OPTS))
    // Pass the compiled sass through the prefixer with defined
    .pipe(prefix(
      'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'
    ))
    .pipe(gulp.dest(DEST_DIR));
});
yocontra commented 9 years ago

You should publish a module that does this, gulp-util is deprecated and won't have anything added to it. After gulp 4 we will recommend people don't use it.