Created
April 3, 2014 14:56
-
-
Save kemitchell/9955884 to your computer and use it in GitHub Desktop.
Single Source File CoffeeScript Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_MODULES := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))node_modules | |
NODE = $(shell which node) | |
COFFEE = $(NODE_MODULES)/coffee-script/bin/coffee | |
UGLIFY = $(NODE_MODULES)/uglify-js/bin/uglifyjs | |
MOCHA_PHANTOM = $(NODE_MODULES)/mocha-phantomjs/bin/mocha-phantomjs | |
DOCCO = $(NODE_MODULES)/docco/bin/docco | |
BUILD_TOOLS = $(COFFEE) $(UGLIFY) $(MOCHA_PHANTOM) $(DOCCO) | |
BASE = index | |
SOURCE = $(BASE).coffee | |
MINIFIED_INFIX = .min | |
JAVASCRIPTS = $(BASE)$(MINIFIED_INFIX).js $(BASE).js | |
SOURCEMAPS = $(BASE).map $(BASE)$(MINIFIED_INFIX).map | |
DOC = index.html | |
TEST_SOURCES = $(wildcard test/*.coffee) | |
TESTS = $(TEST_SOURCES:.coffee=.js) | |
TEST_RUNNER = test/index.html | |
.DEFAULT_GOAL: all | |
all: $(JAVASCRIPTS) $(SOURCEMAPS) $(TESTS) $(DOC) | |
$(BUILD_TOOLS): | |
npm install | |
%$(MINIFIED_INFIX).js: %.js %.map $(UGLIFY) | |
$(NODE) $(UGLIFY) --compresss --mangle --source-map $(@:$(MINIFIED_INFIX).js=$(MINIFIED_INFIX).map) --in-source-map $(word 2,$^) --output $@ $< | |
%$(MINIFIED_INFIX).map: %$(MINIFIED_INFIX).js | |
%.js %.map: %.coffee $(COFFEE) | |
$(NODE) $(COFFEE) --map --compile $< | |
$(DOC): $(DOCCO) | |
@ $(NODE) $(DOCCO) -o . $(SOURCE) && mv $(BASE).html $(DOC) | |
.PHONY: all doc test clean | |
doc: $(DOC) | |
test: $(TESTS) $(MOCHA_PHANTOM) | |
$(MOCHA_PHANTOM) $(TEST_RUNNER) | |
tests: $(TESTS) | |
clean: | |
@rm -rf $(JAVASCRIPTS) $(SOURCEMAPS) $(DOC) $(TESTS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment