by snprbob86 · 14y ago · 0 comments
He says that maintaining a monolithic Makefile doesn't scale, but that seems unlikely considering how far BSD stretches Makefiles for it's ports system. Sure, Make has some rough edges, but I don't see how Javascript is possibly preferable for gluing together build processes.
The fundamental problem here is that "task based build system" is a silly idea. Make isn't a programming language, you don't define function names. Make is a dependency graph with files for nodes and command lines for edges. We already have a system for "tasks": stick things in ./script or add things to PATH!
By all means, make a metapackage for your test, lint, etc scripts, but define your concatonation like this:
out/foo.js: banner src/foo.js
cat $^ > $@
And generalize your minification using a pattern rule, here's ours: %.min.js: %.js
$(yui) --type js --nomunge < $< > $@
Then add in a gzipping rule: %.gz: %
gzip --best < $< > $@
You could trivially stick that sort of thing into `grunt.mk`...And here's how you'd use that:
include grunt.mk
my-app.min.js.gz: my-app.min.js
my-app.min.js: $(find src -name '*.js')
That said, sometimes it is nice to add some "tasks" for discoverability & encouraging their usage: include grunt.mk
.PHONY: all lint test
all: my-app.min.js.gz lint test
my-app.min.js.gz: my-app.min.js
my-app.min.js: $(find src -name '*.js')
test:
./test/run
lint:
./script/lint src
What if you want to run a subset of tests? Or lint with particular flags? Run a shell command like this one: $ grep test: -A1 Makefile
Then copy paste and edit the output!Simpler is better.
Here's what it takes to make a new Javascript project:
mkdir project
cd project
touch foo.js bar.js
echo -e 'project.js: foo.js bar.js\n\tcat $^ > $@' > Makefile
Unless you're jQuery, you don't need minification or GZipping because clients of your library already have their own. You don't need your own linting because you can trivially run `jshint project.js`.If you find yourself running the same command in your shell a bunch of times, add it to your Makefile. It's that simple.
Also, based on your comments, I think you and I have different definitions of "simple". :)
You might be using it to mean what he's defined as "easy".
for the rule:
%.gz: %
wouldn't you need something like patsubst? Regardless of your response, could you share more info?edit, that rule above only makes sense to me if the file name to be gzipped was passed to make. Is that correct? (I'm new to make)