Dina Dina - 1 month ago 10
Node.js Question

Setting up build server using Node and Gulp

I'm developing a front-end package and this is my environment:


  • IDE: Visual Studio (I'm on Windows and we use TypeScript)

  • Package manager: NPM

  • Task runner: Gulp

  • CI: TeamCity



My problem is that I'm trying to avoid installing node and Gulp globally on my build servers (mainly because I don't want to bother managing this - installing, updating, synchronizing, etc.).

So I found a NuGet package (https://www.nuget.org/packages/Npm.js/) which allowed me to restore all the packages without having node installed on the machine. But then the problem was that the local Gulp I installed assumes there's a node.exe right next to it or in the machine's path:

@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\gulp\bin\gulp.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\gulp\bin\gulp.js" %*
)


Now obviously this won't work since I don't have node installed on the build machine and there's no local node installation inside node_modules.

So is there any way to avoid installing my build tools globally on each build server? Or were Node and Gulp intended to be installed everywhere? How should then updates be maintained? It's not like a Visual Studio release which comes out once every few months... Or do you just ignore frequent releases of the build tools?

I could also add the NuGet package to the path but that (the path where node.exe is located) depends on the version of the NuGet package and requires more maintenance whenever updating it. So I prefer not going this way either...

Answer

It's not optimal but here's what I ended up doing: I used a NuGet package for setting environment variables in MSBuild and created the following build configuration:

<Target Name="GulpBuild">
    <SetEnvVariable Name="path" Value="%path%;..\packages\Node.js.5.3.0" />
    <Exec Command="node_modules/.bin/gulp" />
</Target>

Now when I build the solution in VS (CTRL+Shift+B) it adds the node location to the path and then calls gulp. Of course I guess I could have just written the gulp command myself including the node path. In any case, this is of course not optimal because I need to manually update the location if I update the Node.js version, but I couldn't find any better solution.

At least the path configuration is defined inside the repository and does not depend on any machine configuration.

Comments