2

I'm writing a build script and it executes commands like:

  • npm install bower -g
  • npm install gulp -g

Installing these packages will take around 30-60 seconds on my machine even if they are already installed (e.g. installed from previous run of the build script).

I was thinking there could be a way to detect if bower or gulp are already installed and in that case skip the installation to save some time during the build.

Is something like that possible? How would I do that?

I'm using Windows and PowerShell, but I suppose some solutions in bash might be possible to port to Windows...

Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
  • Not a direct answer to your question, but it should not take 30-60 seconds if they are already on your machine, unless it's trying to determine a version match. If you're explicit on the version in your package.json and bower.json, it won't need to take time to hit the registry to see if there is a newer version available. – Paul Aug 08 '16 at 08:28
  • @Paul: Thanks for the response. I thought that package.json was not being used in global installs. I actually don't think I have bower listed in my package.json file at all. Also bower.json is not related to this since all of this is npm installs... – Tom Pažourek Aug 08 '16 at 08:32
  • Ok, I was completely misreading, thanks. So, you're right about the .json files not being used for global installs, sorry. That said, my comment stands about using a specific version in the command that you're running the install with. – Paul Aug 08 '16 at 08:35
  • @Paul: Yeah, good idea. I tried running `npm install gulp@3.9.1 -g` couple of times and it still takes around 10 seconds each time I run it, but I think it is a bit faster. – Tom Pažourek Aug 08 '16 at 08:40

1 Answers1

3

On Win7+ you can use where <command> e.g.

@echo off
where gulp > nul
if %ERRORLEVEL% GEQ 1 (npm i gulp -g) else (echo Gulp already installed)
Aikon Mogwai
  • 4,954
  • 2
  • 18
  • 31