GithubHelp home page GithubHelp logo

gulp-util's People

Contributors

ben-eb avatar bumbu avatar caleyd avatar erikkemperman avatar floatdrop avatar hughsk avatar jamesplease avatar jdalton avatar jonschlinkert avatar kevva avatar lazd avatar makky3939 avatar milang avatar mtscout6 avatar pascalduez avatar peterdavehello avatar pgilad avatar phated avatar rr2do2 avatar safareli avatar saschagehlich avatar saturation avatar shinnn avatar sindresorhus avatar stephenlacy avatar stringparser avatar sttk avatar trysound avatar yocontra avatar zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-util's Issues

Feature Request : Not Glob Pattern

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;
    }, []);
  }
};

gutil.env not works

var gulp = require('gulp');
var gutil = require('gulp-util');

gulp.task('default', function() {
  console.log(gutil.env);
});

it logs { _: [] } so I can't check if it is production

Getting error when trying to install

when i typed in gulp i goto the message that i require gulp-util, but the whole thing was working earlier. So i did the normal install but came across a vat of errors.

Error: ENOENT, utime ‘……/node_modules/gulp-util/node_modules/lodash.template/node_modules/lodash.escape/node_modules/lodash._escapehtmlchar/node_modules/lodash._htmlescapes/README.md

command "node" "/usr/local/bin/npm" "install" "gulp-util" "--save-dev"
node -v v0.10.28
npm -v 1.4.9
code ENOENT
errno 34
fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Failed to parse json
npm ERR! Unexpected end of input
npm ERR! File: /Users/????????/.npm/object-keys/0.4.0/package/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript

now this is preventing me form continuing, any ideas. The initiator of this was after a npm update call.

Beep number of times?

Why not add an optional parameter (with default=1) to the beep function, so that we can play the "beep" multiple times (to keep attention, ex. when there is an error on watch)?
So instead of:

var onError = function (err) {
    gutil.beep();
    gutil.beep();
    gutil.beep();
    gutil.log(gutil.colors.red("Error: ") + err);
};

one could simply write:

var onError = function (err) {
    gutil.beep(3);
    gutil.log(gutil.colors.red("Error: ") + err);
};

fileName is undefined for certain PluginErrors

This is noticable when using gulp-react, the error it throws doesn't have a filename as part of the error object passed in. However, gulp-react does manually pass in the filename.

However, in PluginError.js, if options.message is an instance of Error, it always obtains the fileName from the error, even if the fileName isn't part of the error. It ignores any parameters explicitly passed into the PluginError construction that would augment the error passed in.

Note that this might well be a gulp-react bug, it could put the filename on the error before it creates the PluginError. If this is the intended behaviour I'll make a pull request for gulp-react instead.

gutil.identity function?

I didn't want to open a PR until I was sure I was on the right track.

I've stumbled upon a use-case where some sort of 'stream-identity' function might be nice. Here is an example of what I am doing now:

var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var es = require('event-stream');
var identity = function(i) { return i; };

gulp.task('scripts', function() {
  gulp.src('src/**/*.js')
    .pipe(concat('script.js'))
     // do nothing for dev, else minify scripts
    .pipe(gulp.env.development ? es.mapSync(identity) : uglify()) 
    .pipe(gulp.dest('dist/');
});

Basically, the ideal gutil.identity function would stop my project from needing event-stream in my package.json and stop the little bit of boilerplate. Ideally, I could write:

gulp.task('scripts', function() {
  gulp.src('src/**/*.js')
    .pipe(concat('script.js'))
    .pipe(gulp.env.production ? uglify() : gutil.identity())
    .pipe(gulp.dest('dist/');
});

Maybe identity isn't the best name (perhaps noop or something), but you get the picture.

What do you think?

Transform stream pipe

I would like to compose two Transform streams into one Transform stream. Though only the second one works if I write something like

var composed = test().pipe(test());
gulp.src('source/*').pipe(composed);

How should I do it?

PluginError: setting showStack to false not working

I'm using gulp-jshint and gulp-jscs, all of then using gulp-util.PluginError for emitting error and all of them doing with false showStack option (gulp-jscs, gulp-jshint, but when I'm running it, all linter showing up stack trace (image, output).

You can try these errors in my stub project, I created special branch for demonstration (gulp-util-bug-demo):

git clone [email protected]:matmuchrapna/webapp-base.git
cd webapp-base
git co gulp-util-bug-demo

# stack trace =(
gulp jshint 

# stack trace =(
gulp jscs

PluginError options.properties is overly complicated

The current list of default properties that will get copied include:

  • name
  • message
  • fileName
  • lineNumber
  • stack

I feel that "name", "fileName", and "lineNumber" where included to address specific errors, they can be removed right?

"message", and "stack" are there to ensure that they are copied from the original error, I vote they stay.

The feature that allows for the options properties to override the properties on the error via the same list of whitelisted properties is where the true complexity lies. Both these features feel like separate concerns being shoved into one.

I propose that this feature be lifted to another property on the options say options.data, where any key value pair there is copied directly to the error.

Use gulp-util to log in .pipe

Hi there,

I'm trying to figure out how to do a console.log-type of messaging during the stream. So, I thought I'd try something like:

.pipe(gutil.log('my message'))

but that throws an error:

TypeError: Object #<Object> has no method 'on'
    at Stream.pipe (stream.js:65:8)

Clearly I'm either missing something or .log is not meant to work that way at all.

Can you please point me in the direction to get this working? (if there is a direction)

thanks,
Scott

Is gutil.combine deprecated?

It seems to be undocumented (and I remember that it used to be), but it doesn't look very deprecated—nothing is saying to not use it, it just isn't documented.

Plugin name in logging

Docs says:

Prefix any errors with the name of your plugin

I think it would be nice if the logging function this this by default. That way it could be consistent and I wouldn't have to care.

gray is a bad color for timestamps

in gulp-util/lib/log.js, line 5:

var time = '['+chalk.grey(dateformat(new Date(), 'HH:MM:ss'))+']';

this can have a very low-contrast appearance in certain light-on-dark color schemes.

Combine() side-effects

Node: v0.10.20
Gulp: CLI version 3.5.0, Local version 3.5.2
Gulp-util: 2.2.14


I have a gulpfile.js like this:

var gulp = require('gulp');
var gutil = require('gulp-util');
var coffee = require('gulp-coffee');
var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
var replace = require('gulp-replace');

var requireWorkaround = gutil.combine(
    replace('require', 'requireClient'),
    replace('nequire', 'require')
);

gulp.task('default', ['background-scripts', 'browser-scripts']);

gulp.task('background-scripts', function(){
    gulp.src(paths.background.scripts)
        .pipe(coffee())
        .pipe(requireWorkaround())
        .pipe(gulp.dest(paths.public.backgroundScripts));
});

gulp.task('browser-scripts', function(){
    gulp.src(paths.browser.appEntryScript, {read:false})
        .pipe(browserify({
            transform: ['coffeeify'],
            extensions: ['.coffee']
        }))
        .pipe(requireWorkaround())
        .pipe(rename('app.js'))
        .pipe(gulp.dest(paths.public.browserScriptsRoot));
});

None of the paths are overlapping or within each other.

Notice the rename step in browser-scripts. That's because browserify will output app.coffee if app.js is passed in. So without this step, I'd expect app.coffee to exist at paths.public.browserScriptsRoot.

Both of these tasks work as expected when ran on their own.

The problem

When ran together, browser-scripts seems to run perfectly but background-scripts seems to run some steps from background-scripts's pipeline.

With background-scripts, at paths.public.backgroundScripts I see the same JS files as the browser-scripts task would output (browserified, converted to JS, with .js extension but in the wrong place) as expected. But I also get the same file again with the .coffee extension. Hmm.

I noticed how the combine example ends the pipeline within the function (i.e. no pipes after the combined function when calling it) but I think it would be reasonable to assume I can just combine steps and resuse them in the middle of a pipeline.

The twist

So I went to debug this. I added a gulp-debug step in my combined function;

var requireWorkaround = gutil.combine(
    debug(),
    replace('require', 'requireClient'),
    replace('nequire', 'require')
);

Strangely the debug output only tells me that one file was passed (requireWorkaround should be called twice with one unique file each time).

But the really weird part is that when running the parent task (running both tasks together), everything just works as it should. No pointless .coffee files. The JS files in paths.public.backgroundScripts are the correct ones.

It's really strange how adding a call to gulp-debug could reduce the side-effects of this problem. Although, I know it is a third party plugin.

gutil.template requires a file attribute

Why wrap lodash's template function in such a way?

> var t = gutil.template('<%= test %>', { test: 'something' });
// Error: Failed to provide the current file as "file" to the template
> var t = gutil.template('<%= test %>', { test: 'something else', file: 'what?' });
console.log('t:', t); // something else

Not displaying name / message on error?

This is really frustrating for things like gulp-uglify where the message tells you what the actual uglification error is, and this utility completely cuts that away.

The only way to display it is by doing this:

module.exports = function uglifyError (message, options) {
    return new PluginError('gulp-uglify', {
        message: message
    }, options);
};

Which will output the message, but now the stack is no longer from the actual error, but from the location PluginError is called, when you add stack as an option to message object, it no longer shows the message, nor name, nor anything else, just the stack.

Currently, this is what I am having to do to get a viable error + stack trace:

module.exports = function uglifyError (message, options) {
    return new PluginError('gulp-uglify', {
        message: message,
        stack: options.stack.replace(
            'Error\n',
            'Error [' + message + ']' +
            '\n    in: ' + options.fileName +
            '\n    at line: ' + options.lineNumber +
            '\n'
        )
    }, options);
};

Changelog missing

There does not appear to be a changelog anywhere, for this module. This makes it really hard to determine what has changed across releases, and whether it is safe to update to a new major version (in my particular case, from 2.2.17 to 3.0.7).

buffer() not handling stream errors?

  it('should pass err to callback on stream errors', function(done){
    var errObj = new Error('broken');
    var inp = es.map(function (data, cb) { cb(errObj); });
    inp.write('hey');
    inp.pipe(util.buffer(function(err, data){
      err.should.eql(errObj);
      done();
    }));
  });

If I put this as an additonal test on the buffer function, it fails. Is the test bad? I'm coming to this from my app, which recently seems to have begun failing to handle errors generated in the stream processing, where at the end of it all is one of these buffers intended to "do stuff" after the stream processing is complete, regardless of whether an error occurred. The callback never happens.

          var out = runBuild(files).pipe(
            $.util.buffer(function (err, files) {
              console.log('I am not called when an error is emitted from the runBuild stream');
          ...

Remove timestamp from log

image

The timestamp prefix doesn't match the gulp log very well, and in my experience removes more line space than it adds in value. What do you think about removing the timestamp and wrapping the first argument / gulp plugin name in brackets like the gulp log messages?

Beep when done

Hi, I want to make voice control for build. I wrote something like this below, but it is not working.
Does anybody know how to fix it? :)

It throws this error - http://prntscr.com/6lxpzu

// Compile Sass, autoprefix properties, generate CSS.
gulp.task('sass', function () {
    return sass('src/sass/style.scss', {style: 'compressed'})
        .pipe(autoprefixer())
        .pipe(rename('style.css'))
        .pipe(gulp.dest('src/css/'))
        .pipe(gutil.beep()); // beep when build is done
});

PluginError and inconsistent showStack output

Following the examples, I'm constructing an error as such:

  var gutil = require('gulp-util');

  swig.error = function (entityName, message) {
    var err = new Error(message);
    return new gutil.PluginError(entityName, err, { showStack: true });
  }

  throw swig.error('publish-verify', 'Testing errors');

The output that's generated between constructors is pretty inconsistent. Using the constructor above results in a redundant 'Message:', since it's repeated at the top of the stack that's rendered, and a phantom 'Stack:' section with no content.

[09:40:55] Starting 'publish-verify'...
[09:40:55] 'publish-verify' errored after 2.72 ms
[09:40:55] Error in plugin 'publish-verify'
Message:
    Testing errors
Stack:
Error: Testing errors
    at Object.swig.error (/Users/[...]/utilities/swig-util/lib/error.js:21:15)
    at Gulp.publishVerifyTask (/Users/[...]/tasks/swig-publish/index.js:29:16)
    at module.exports (/Users/[...]/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /Users/[...]/.nvm/v0.11.13/lib/node_modules/gulp/bin/gulp.js:121:20
    at process._tickCallback (node.js:343:11)
    at Function.Module.runMain (module.js:492:11)
    at startup (node.js:124:16)

(Granted that the first line in the stack points to my utility function, that's expected)

If I change the utility function to use a different constructor signature (again based on the samples) to:

  var gutil = require('gulp-util');

  swig.error = function (entityName, message) {
    return new gutil.PluginError(entityName, message, { showStack: true });
  }

  throw swig.error('publish-verify', 'Testing errors');

I get the following output:

[09:59:24] Starting 'publish-verify'...
[09:59:24] 'publish-verify' errored after 531 μs
[09:59:24] Error in plugin 'publish-verify'
Error
    at Object.swig.error (/Users/[...]/utilities/swig-util/lib/error.js:21:12)
    at Gulp.publishVerifyTask (/Users/[...]/tasks/swig-publish/index.js:29:16)
    at module.exports (/Users/[...]/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/[...]/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /Users/[...]/.nvm/v0.11.13/lib/node_modules/gulp/bin/gulp.js:121:20
    at process._tickCallback (node.js:343:11)
    at Function.Module.runMain (module.js:492:11)
    at startup (node.js:124:16)

The message is now missing and isn't displayed anywhere, the phantom empty 'Stack:' isn't rendered (yay) but the rendered stack is just prefixed with 'Error'. Inconsistencies like this may not be a big deal on the surface, but it makes tying in any kind of reporting utility on build errors a hefty task due to the different forms of output from different constructors (and data) used. Ideally, this should be uniform.

discourage instanceof

Different versions of vinyl should be able to co-exist, since plugins will now be relying on it directly. The README should discourage usage of instanceof

(related: #103)

consider externalizing PluginError?

Would you consider making PluginError a module? I have a number of plugins that only use this method, and we also use PluginError in non-gulp applications that use vinyl/vinyl-fs.

I just created a module to do this, but would be happy to transfer to gulpjs and/or do pr to gulp-util to use that module (wherever it lives). fwiw, only formatting changes were made the module I created, no changes to actual behavior - but I'd be happy to make whatever changes are necessary to those as well.

Gulp-util throwing error: cannot find module 'dateformat'

I'm not sure, but I think this may be related to latest versions of NPM that produce a flat node_modules structure? In any case, can't seem to get my gulp scripts running because of this error.

Error: Cannot find module 'dateformat'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/gulp-util/index.js:5:9)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)

`showStack` - PluginError

From readme:

By default the stack will not be shown. Set options.showStack to true if you think the stack is important for your error.

In reality it does show by default.

In addition it should be clear when it should be used and when it's not needed. When the error is coming from eg. linting. The stack isn't needed. But from a syntax error it is. Hiding the stack in correct cases improves the UX.

PluginError toString output

Currently console.log'ing the error outputs way too much:

{ [Error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]
  message: 'error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-ruby-sass',
  __safety: { toString: [Function] } }

It should only output:

[Error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]

Or even better:

[gulp-ruby-sass error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]

Just define a .toString method for it outputting what we want.

re yeoman/generator-webapp#242 (comment)

gulp-util logger - default datetime color

Its very good, that you can use chalk, to make different colors. But it would be the best, if there could be possibility to change prefixed "datetime" in log module.

I am using osx terminal with theme "Solarized", and datetimes are just invisible.
Image of Yaktocat

Same problem has HTOP (osx), MidnightCommander (osx), but it is quickly fixable.

Thank you!

gutil.combine only passes the first file.

I think this might be an issue with change to using multipipe, but I'm only getting the first file out of the pipeline.

If I run debug() before entering the pipe, and then inline as the first item within the pipe, then after the pipe, I get an output that looks something like this:

File:
path: ~/app/src/js/app.js

File:
path: ~/app/src/js/app.js

File:
path: ~/app/src/js/app.js

File:
path: ~/app/src/js/other/foo.js

File:
path: ~/app/src/js/other/bar.js

The first file is duplicated because it is shown before the pipeline, within the pipeline, and after, but the rest are only shown before the pipeline.

Real logger

  • levels
    • errors go to STDERR
  • ability to ignore certain things and use globbing (like the debug module)
  • ability to set a new logger
  • time prefix

color documentation for .log switched

The README.md says numbers etc. are colored in cyan and strings are colored in magenta. For one this is confusing because .log doesn't auto-color. The second issue is that if you follow this guideline and compare this to the default output from gulp the colors will actually be switched.

tl;dr
numbers are in magenta
strings are in cyan

The docs should note this as a guide, not suggest auto-coloring.

.log() to support logging levels

It would be nice if as a plugin author I could specify gulpUtil.log(gulpUtil.level.FATAL, "my message") and it would also fail the build, or as a consumer I could specify I only want to see gulpUtil.level.ERROR or greater and thus get a more condensed output. Perhaps gulp.silent could shim into this (though I think it may have since been removed).

Error 'Arguments to path.join must be strings' when trying to pipe after gutil.buffer()

I am trying to use gutil to filter a set of files, but it seems if I attempt to pipe after an empty call to buffer, I receive the above error.

My source is fairly simple...

gulp.src([
    './**/*.scss'
])
.pipe(gutil.buffer(function (err, files) {
    // Nothing, its just empty
}))
.pipe(sass({
    style: 'expanded',
    debugInfo: false,
    noCache: true
}))

And I receive the following error:

path.js:204
        throw new TypeError('Arguments to path.join must be strings');
              ^
TypeError: Arguments to path.join must be strings
    at f (path.js:204:15)
    at Object.filter (native)
    at Object.exports.join (path.js:209:40)
    at Transform.transform._transform (\node_modules\gulp-ruby-sass\node_modul
es\gulp-intermediate\index.js:27:29)
    at Transform._read (_stream_transform.js:179:10)
    at Transform._write (_stream_transform.js:167:12)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at Transform.Writable.write (_stream_writable.js:183:11)
    at write (\node_modules\gulp-util\node_modules\through2\node_modules\reada
ble-stream\lib\_stream_readable.js:623:24)

Removing the pipe for the buffer allows this task to function as expected.

So, I want to know, am I using the buffer function incorrectly?
Can I actually filter the file list before sending it on to the next piped task?
Is this a genuine error or is it just my misunderstanding on how to use it?

...Forgive me if this isn't a genuine error, I just can't seem to find any valid usages of this method.

recursive gutil.template

How about make gutil.template - recursive

var variables = {
    options: 'folder/<%= subfolder %>/subfolder2',
    subfolder: 'subfolder1'
}

gutil.template('<%= options %>/**/*', variables)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.