1

I have a bunch of JS files that I split up, but want to concatenate automatically (so I don't define a bunch of files in HTML). Right now, I copied the command from Twitter Bootstrap. Makefile:

scripts:
 cat scripts/*.js > public/scripts/scripts.js

watchScripts: 
  watchr -e "watch('scripts/.*\.js') {system 'make scripts'}"

However, I've found watchr to be very inconsistent (on Mac OS X 10.8)

  1. Sometimes when I save a js file, it doesn't run make scripts. Other times, it does.
  2. One time, it just kept running make scripts continuously after a single save.
  3. Sometimes, it will run the command a few seconds after the last save.

Am I doing something wrong? I'm working using node.js and not Ruby, so are there any node.js command-line alternatives? The same issues seem to happen to me when I try make watch in Bootstrap.

Aside question: I have another watch command:

stylus -w -u nib styles/styles.styl -o public/styles

How can I run two watch commands in a single Makefile command? IE make watch will watch both .styl files to compile, and .js files to concatenate. Right now I'm opening up two terminals, for each watch command, but I'd prefer a single one.

Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118
  • installed `gem install rev` as told by `https://github.com/mynyml/watchr/` and it seems to fix the problem. – Jonathan Ong Aug 20 '12 at 23:10
  • +1. So, to `make watch` in Bootstrap, are we supposed to use _watchr_ for Node.js or gem? _watchr_ for Node.js: _https://github.com/bevry/watchr_ _watchr_ for gem: _https://github.com/mynyml/watchr_ – moey Apr 28 '13 at 12:25
  • I installed _watchr_ `gem install watchr` and also `gem install rev`, `gem install ruby-fsevent` but `make watch` didn't do anything when there was a change in one of the LESS files. I was on Mac OS X 10.8.3. – moey Apr 28 '13 at 12:31

1 Answers1

0

Have you tried brunch? It's really great for this kind of stuff when working on node.js. You can just use a skeleton or set it up manually and have a script your whole directory, merging and compiling on the go.

dignifiedquire
  • 1,360
  • 9
  • 14
  • this seems overly complicated and large for what i need (just concatenating js files). i don't understand why they feel it is necessary to install basically everything with brunch. – Jonathan Ong Aug 20 '12 at 23:05
  • plus, why is it written in coffeescript? – Jonathan Ong Aug 20 '12 at 23:09
  • 1
    Basically any advanced watcher process is a quite complicated thing. For example, it needs to preserve user’s script order even if user uses different languages (stylus, css, sass, less), it needs to able to lint or auto-wrap files in modules etc etc. Brunch makes stuff just work, but if you have really small project I guess it will be better to manually set up stuff. As for CoffeeScript, it gives a lot cleaner code, especially if you prefer functional paradigm. – Paul Miller Aug 21 '12 at 09:19