diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2b502d78bf7d6da7322b46b12896881baf2b48e3 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +SHELL := /bin/bash +CURL := curl + +# NodeJS Find/Install +NODE_PATH = $(shell ./find-node-or-install) +PATH := $(NODE_PATH):$(shell echo $$PATH) + +# External Build Tools +NODE_DIR = node_modules +LESSC = $(NODE_DIR)/less/bin/lessc +UGLIFYJS = $(NODE_DIR)/uglify-js/bin/uglifyjs + +# Local Vars +LESS_LIB = www/less/lib + +# External Dependencies +LESSHAT := $(LESS_LIB)/lesshat.less +WDN_MIXINS := \ + $(LESS_LIB)/breakpoints.less \ + $(LESS_LIB)/colors.less \ + $(LESS_LIB)/fonts.less + +WDN_LIB_RAW = https://raw.githubusercontent.com/unl/wdntemplates/master/wdn/templates_4.0/less/_mixins/ +LESSHAT_RAW = https://raw.githubusercontent.com/csshat/lesshat/c8c211b2442734bfc1ae2509ff0ccebdc2e73664/build/lesshat.less + +# Built Files +CSS_OBJ = www/css/search.css +JS_OBJ = www/js/search.min.js + +all: less js + +less: $(CSS_OBJ) + +js: $(JS_OBJ) + +clean: + rm -r $(NODE_DIR) + rm -r $(LESS_LIB) + rm $(JS_OBJ) + rm $(CSS_OBJ) + +$(CSS_OBJ): www/less/search.less $(LESSC) $(LESSHAT) $(WDN_MIXINS) + $(LESSC) --clean-css $< $@ + +$(LESSC): + npm install less + +$(LESS_LIB)/%.less: + @mkdir -p $(@D) + $(CURL) -s $(WDN_LIB_RAW)$(@F) -o $@ + +$(LESSHAT): + @mkdir -p $(@D) + $(CURL) -s $(LESSHAT_RAW) -o $@ + +$(UGLIFYJS): + npm install uglify-js + +$(JS_OBJ): www/js/search.js $(UGLIFYJS) + $(UGLIFYJS) -c -m -o $@ -p 2 --source-map $(<).map --source-map-url $(<F).map $< + +.PHONY: all less js clean diff --git a/find-node-or-install b/find-node-or-install new file mode 100755 index 0000000000000000000000000000000000000000..37a3e86b04e3a9205f5c8d95ea9e40e4c32cbda5 --- /dev/null +++ b/find-node-or-install @@ -0,0 +1,58 @@ +#!/bin/bash +############################################################################## +# Finds the bin directory where node and npm are installed, or installs a +# local copy of them in a temp folder if not found. Then outputs where they +# are. +# +# Usage and install instructions: +# https://github.com/hugojosefson/find-node-or-install +############################################################################## + +# Creates temp dir which stays the same every time this script executes +function setTEMP_DIR() +{ + local NEW_OS_SUGGESTED_TEMP_FILE=$(mktemp -t asdXXXXX) + local OS_ROOT_TEMP_DIR=$(dirname ${NEW_OS_SUGGESTED_TEMP_FILE}) + rm ${NEW_OS_SUGGESTED_TEMP_FILE} + TEMP_DIR=${OS_ROOT_TEMP_DIR}/nvm + mkdir -p ${TEMP_DIR} +} + +# Break on error +set -e + +# Try to find node, but don't break if not found +NODE=$(which node || true) + +if [[ -n "${NODE}" ]]; then + # Good. We found it. + echo $(dirname ${NODE}) +else + # Did not find node. Better install it. + # Do it in a temp dir, which stays the same every time this script executes + setTEMP_DIR + cd ${TEMP_DIR} + + # Do we have nvm here? + if [[ ! -d "nvm" ]]; then + git clone git://github.com/creationix/nvm.git >/dev/null + fi + + # Clear and set NVM_* env variables to our installation + mkdir -p .nvm + export NVM_DIR=$( (cd .nvm && pwd) ) + unset NVM_PATH + unset NVM_BIN + + # Load nvm into current shell + . nvm/nvm.sh >/dev/null + + # Install and use latest 0.10.* node + nvm install 0.10 >/dev/null + nvm alias default 0.10 >/dev/null + nvm use default >/dev/null + + # Find and output node's bin directory + NODE=$(which node) + echo $(dirname ${NODE}) +fi