I'd like to make my Node projects a bit more idiomatic, making use of popular Node technologies like grunt. How should I rewrite my dependent shell tasks in my Makefiles in something like Gruntfile.js? There doesn't seem to be clear documentation on how to do this.
Is there another Node build technology I should be using? I would just write one-liner scripts in package.json, but npm doesn't have a way to specity that tasks dependent on one another.
Everything in grunt are tasks. You can use a task like grunt-shell to run your shell commands.
There's an open ticket for better docs about this.
Related
I'm looking for the proper way to distribute/deploy a node.js app that would run as a small webserver on the user's machine.
Is there a stub method or install script or a "install wizard" that would download all node_modules dependencies, download the latest nodejs binary, set up the environment, etc... or I have to distribute it bulk with everything packed? Is there any guide for that purpose?
Edited :
You could install node and npm, download your dependencies by running npm install in the command line (first declare them within your package.json) only then users can run your script. This is how you do development in Node.js, or deploy to a development server. See using npm. You could automate that with a shell script if that is what you are after.
However, when distributing programs to end-users that might not be the best approach. Linux users are used to a package (.deb for instance) and Windows users are used to an .exe or a setup wizard.
That is why I recommended the tools below. I also assumed you were targeting Windows as this is less of a problem is unix-like environments.
If you want a single file (.exe), pkg and nexe are made for that purpose. These Node.js tools are used by the developer to compile JavaScript code into a single executable binary that is convenient for end-users and Windows deployment. The resulting .exe file is very light and does not require node to be installed on the end-user’s computers.
Electron along with electron-packager can produce setup wizards, but it installs a lot of files even for the smallest program. Your program will include all of node and webkit, that is why it produces heavy installs.
NSIS can also create a setup wizard, it is simple and does common stuff well (copying files, running shell scripts).
Original answer:
Short answer is: not really.
You have to keep in mind that Javascript is and has always been interpreted, so until recently never compiled to binary as you might do with other languages. Some exploration has been going on, but essentially you won’t get a "good practice" answer.
The long answer is, maybe, for some limited use cases:
There is the fresh new pkg that does exactly this, and it looks promising.
There has been nexe for a while, it works great for some use cases (maybe yours). Native/compiled modules are still an issue however.
Electron might work for a full blown app with a significant user interface, but it is not light or compact.
You could always use browserify to concatenate and uglify all your code with the modules you use and then make an installer with something like NSIS to setup node and your script. Native modules would still be a problem however.
So the thing is I went through the internet and checked for available linters. Mostly all the the LESS linters available provide a command line interface or a plugin for grunt or gulp. What I really want is a simple Node Plugin which is configurable and usable with NODEJS through Code and not through CLI.
Also due to unavailability of the tags such as LESSLINT and SCSSLINT could not add those tags to the questions.
Is there any node plugin available to do this?
If not, How can I use CLI through NodeJS and also get the callbacks?
I need the callbacks since that's the most powerful feature of NodeJS and besides my code is dependent on the callbacks..
P.S.: I do not need any code, all I need is directions.
Thanks for the support
A Node port of scss-lint was recently released, you can get it here: https://github.com/FWeinb/scsslint
It can be used either in Grunt or just as a normal Node module.
LESS has built-in linting, but it doesn't seem to be accessible through Node. You can use spawn or exec and the LESS CLI with the --lint flag. See the LESS docs here: http://lesscss.org/usage/#command-line-usage-options
I want to start formally documenting my NodeJS project written in CoffeeScript. After investigating most of the documentation options I've decided to (attempt to) go with JSDoc.
Given that I've installed this globally with NodeJS, is there any way I can get JSDoc to recognize my .coffee files the way Mocha and Node itself do? (Both support compiler flags, eliminating the need for build tools like Grunt or Gulp)
Since JSDoc uses espree(JavaScript AST parser), you can't do that. But some alternatives like Codo or Docco exist.
So I've been reading about Gulp and Grunt, and how they can minify code, compress files, combine files into one, livereload etc. However, Meteor does all that already, with Isobuild.
The reason I'm asking is someone suggested using Gulp with Meteor, and I don't see a need for it. What are some possible reasons why I should run Gulp alongside Meteor? Or it is simply redundant?
If it is not redundant, what features does Gulp has that is not in Isobuild? And will the Meteor team plan to incorporate Gulp into its next versions?
Need is probably not the right word. Whether you want it or not is a different story.
As the comments mentioned above, Meteor include a very clever build system of its own called isobuild, which builds your WHOLE application for you. But there are certainly instances where you may want your own tasks which would best be accomplished through grunt or gulp. (The range of tasks you can accomplish with these is staggering, so I'm only going to list a couple simple common examples.)
The most obvious is going to be for assets you want to put in your public folder. But this is far from an exhaustive list of tasks that you may want to automate on a larger project.
Compile SASS files not using the libsass compiler (because it doesn't support all the features)
Compress and optimize images, svg files, favicons, etc.
Create multiple sizes / versions of images
Create Sprite Sheets
Concatenate and minify scripts in your own order / manner
Combine with Bower to manage front end packages that aren't available through atmosphere etc.
The way I would approach it is by putting all of this into the private folder, so its avoided by the meteor isobuild build system.
I believe these are enough reasons to not consider Gulp or Grunt redundant, and the range of tasks possible with grunt or gulp are so varied they can't all be listed here. Needless to say IsoBuild is fantastic for what it does, but would not replace everything possible with these task runners, and to my knowledge there are no plans to incorporate Gulp into IsoBuild. IsoBuild is core to what Meteor is, gulp and grunt are very powerful automation tools with thousands of possible uses.
Heres a really great starter for gulp, its super simple to get started with: NodeJitsu Gulp tutorial
So, sure, you don't need grunt or gulp, but they could certainly have a productive place in your meteor project and they're definitely worthwhile tools to get to grips with to streamline your dev processes.
If you would like to use either grunt or gulp, this is how I approach structure my project:
Project-folder
|__ webapp // my meteor app lives here
|__ assets // scss / images / svgs
|__ node_modules
| gruntfile.js
| .eslintrc
| package.json
I then build, minify, and process my assets, with my target directories in webapp/public
Note that with full npm support coming in Meteor#1.3 this may change, though I'm unclear about whether we'll be able to mvoe this into the project yet.
I am new to NodeJS and Grunt world. I am working on a project where we have multiple modules dependent on each other. So my question how can I automate my process of build for each of projects(modules)
like currently when I take update, I have to manually go in each of projects and have to run
npm install
and then
grunt
I think we'd need a little more information on what your project is and how its setup. Overall though, if you have several projects, each that uses grunt to build it, you'll need to run grunt for each one.
The way I handle this is to use TMUX, and more specifically TMUXINATOR https://github.com/tmuxinator/tmuxinator to setup workspaces for each of my projects. For example, I might type:
mux service-framework
Doing so could launch (for example), four terminals, my editor, start several grunt projects, and load a browser. Its a great tool for the situation you described.
There are a lot of tools for doing this type of thing, TMUX and TMUXINATOR are only one. Hopefully this helps a bit!