0

Current Code:

var open = require('open');
var gulp = require("gulp");
var pkg = require("../../package.json");

//opens the launchpage with default browser
gulp.task("open", function () {
    open('http://localhost:' + pkg.webServerPort + '/commonclient/launchpage.html');
});

Right now, running the gulp command starts the server and does a bunch of other compilation tasks. How to modify this to run the "open" task only if I type in gulp -o or something like that in command line?

antonpug
  • 13,724
  • 28
  • 88
  • 129
  • 1
    possible duplicate of [Is it possible to pass a flag to Gulp to have it run tasks in different ways?](http://stackoverflow.com/questions/23023650/is-it-possible-to-pass-a-flag-to-gulp-to-have-it-run-tasks-in-different-ways) – Nick Tomlin Jun 19 '15 at 17:21
  • Sometimes I think that 90% of the comments on StackOverflow these days are "possible duplicate of" responses. I'm starting to think it's a bot. Nostalgic about the days when people actually answered the questions to help fellow developers. – antonpug Jun 19 '15 at 17:23
  • 1
    Sometimes removing duplication _is_ an actual aid to other developers. This question (albeit not in this exact form) has already been answered much better than I could answer it in the suggested duplicate. – Nick Tomlin Jun 19 '15 at 19:02
  • We are answering it, by telling giving you the link to the solution. Why spend the energy to write the exact same answer? If the linked solution doesn't work for you, then explain why. – Colonel Thirty Two Jun 19 '15 at 19:14

1 Answers1

0

You can do this by inspecting process.argv, or simply looking for an ENV flag on process.env

gulp.task("open", function () {
  if (process.argv.indexOf('-o') > -1) {
    open('http://localhost:' + pkg.webServerPort + '/commonclient/launchpage.html');
  }
});

Or with an env variable

gulp.task("open", function () {
  if (processs.env.USE_OPEN) {
    open('http://localhost:' + pkg.webServerPort + '/commonclient/launchpage.html');
  }
});
Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90