robrich / gulp-if

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

Inverted condition? #77

Closed reintroducing closed 6 years ago

reintroducing commented 6 years ago

I'm using node v10.3.0 and just noticed that my gulpif condition is always running the opposity of what i'm expecting.

const isDev = (npmEvent === 'start');
console.log(isDev, typeof isDev);

...

.pipe(gulpif(isDev, eslint.format(friendlyFormatter), eslint.format('checkstyle', fs.createWriteStream(`${projectPath(PATH_CONFIG.root.path)}/checkstyle-eslint.xml`))))

The checkstyle-eslint.xml file is always being created when i run npm start but when i run npm run build it does not get created. I can't figure out why this is backwards.

Logging isDev and typeof isDev produces the correct output: true 'boolean'

Any ideas?

robrich commented 6 years ago

Weird. Do you have a gist, plunker, stackblitz link that repro's this?

reintroducing commented 6 years ago

Unfortunately its pretty deeply embedded into my project setup so i do not. I was hoping you'd see something I'm doing out of the ordinary (although based on that code there really is nothing visible). I'm going to table it for now because I have to keep moving forward on some of the other implementation details I need to do, but I am going to come back to this and at that point do a deep dive into reproduction and set up a code sample that will do this. If possible, keep this issue open for me and I'll double back when i get to the point that I'm troubleshooting this (probably one of the last things i do on this project).

robrich commented 6 years ago

Another option since it looks like this conditional may be a global, pre-evaluated thing:

let eslintStream;
if (isDev) {
  eslintStream = eslint.format(friendlyFormatter);
} else {
  let stream = fs.createWriteStream(`${projectPath(PATH_CONFIG.root.path)}/checkstyle-eslint.xml`);
  eslintStream = eslint.format('checkstyle', stream);
}

// ...
.pipe(eslintStream)

The added benefit with this approach is it's a touch more legible, and you don't spin up the other stream that it'll never use. (e.g. because gulp-if takes in two already initialized streams and just chooses one of them, it'll read checkstyle-eslint.xml even in dev mode.)

reintroducing commented 6 years ago

That did the trick, thanks!