6

Suppose that I have a project written in JS via such frameworks like Node.js and Express. It also uses Mocha as a test framework and Gulp as a build system.

I wonder what is the best way to expose installation, testing and deployment to users.

I mean, users typically have to do the following stuff:

  • Install Node.js and npm
  • Install dependencies (npm, bower etc)
  • Preprocess CSS / JS (e.g. Sass, Less etc), minify images etc
  • Run tests
  • Run application

Which of these tasks should be handled via build system (in this case Gulp) and which by npm?

I guess there are two ways:

  • Do all stuff via Gulp. gulp install will install all npm and bower dependencies, gulp preprocess will preprocess CSS / JS / images, gulp test will run Mocha etc. Anyway, npm start should be handled separately because running a web-server is not a typical build system's task.
  • Force user to do all stuff via npm commands like this:

package.json

  "scripts": {
    "ins": "npm install && bower install && gulp preprocess",
    "test": "gulp test",
    "start": "node --harmony server.js",
    "deploy": "npm run ins && gulp --harmony"
  }

Yeah, it uses gulp under the hood anyway but it's hidden from user so it looks like he uses npm only. I think that it's cool to limit user to npm, so they doesn't have to know anything about additional tool, and we can switch to another build system anytime later w/o rewriting deployment process manual.

What do you think? Is there any best practices related to this problem?

2

Do not use gulp. Gulp is a time waster. Use npm to install dependencies, use a postinstall npm script to run preprocessors, and use npm scripts or just plain old documentation to tell your users which files to run node tests and node main on. I'm sure similar stuff can be done via bower.

For more info about why you should stop using grunt or gulp, read here: https://www.keithcirkel.co.uk/why-we-should-stop-using-grunt/

  • 1
    This is a pretty opinionated answer. That said, I do think npm scripts should be able to handle this pretty well. – neilsimp1 Mar 2 '17 at 16:27
  • This is certainly an opinionated answer. Its just what I would suggest. There are tons of ways of doing this, so my answer is simply a recommendation. Its simple and gets rid of one complication (grunt) whereas if you use grunt you still need npm (so going that way out of the OPs two options seems objectively worse). – B T Mar 4 '17 at 7:24
  • 1
    It's opinionated, but I agree with it. I'd suggest it could be improved by explaining more of the "why", rather than just dropping a link. For myself, it's simply easier to maintain and pass on to other developers if you always follow the same convention. Build systems come and go (webpack and SystemJS being the newer hotness), but my team can always look at the npm scripts block to see supported operations. – Paul Apr 2 '17 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.