From 6bd298bd818203d9f1b3c28db028b6f3f2d9665e Mon Sep 17 00:00:00 2001 From: Slava Bacherikov Date: Sun, 17 Jul 2016 02:13:33 +0300 Subject: [PATCH] Build everything to one script --- .gitignore | 1 + Makefile | 30 ++++++++++++++++++++++-------- index.html | 5 +---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 8dbf586..5544386 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.bak upload/ build/ +temp/ diff --git a/Makefile b/Makefile index 2e2c722..c27de22 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,40 @@ .PHONY: clean COMPILE_COMMAND ?= closure-compiler -UPLOAD_DIR = upload +TEMPLATE_COMMAND = mako-render --var script_file=$(SCRIPT_NAME) +UPLOAD_DIR := upload +TEMP_DIR := temp JS_FILES = $(wildcard *.js) -COMPILED_JS_FILES = $(JS_FILES:%.js=$(UPLOAD_DIR)/%.min.js) +TEMP_SCRIPT := $(TEMP_DIR)/script.js +TEMP_MAP := $(TEMP_DIR)/script.map +SCRIPT_NAME = script.$(VERSION).js +SCRIPT = $(UPLOAD_DIR)/$(SCRIPT_NAME) +SCRIPT_MAP = $(UPLOAD_DIR)/script.$(VERSION).map +INDEX_FILE := index.html -INDEX_FILE = index.html +calc_hash = $(shell openssl dgst -sha1 $(1) | cut -d' ' -f2 | cut -b1-8) all: $(UPLOAD_DIR) $(UPLOAD_DIR)/index.html $(COMPILED_JS_FILES) $(UPLOAD_DIR)/bootstrap.min.css -$(UPLOAD_DIR)/%.min.js: %.js $(UPLOAD_DIR) - $(COMPILE_COMMAND) $< --js_output_file $@ +$(TEMP_SCRIPT) $(TEMP_MAP): $(JS_FILES) $(TEMP_DIR) + $(COMPILE_COMMAND) --js $(JS_FILES) --js_output_file $(TEMP_SCRIPT) --create_source_map $(TEMP_MAP) -$(UPLOAD_DIR)/index.html: $(INDEX_FILE) $(UPLOAD_DIR) - cp "$<" "$@" +$(UPLOAD_DIR)/index.html $(UPLOAD_DIR)/script%.js $(UPLOAD_DIR)/script%.map: $(INDEX_FILE) $(UPLOAD_DIR) $(TEMP_SCRIPT) + $(eval VERSION := $(call calc_hash,$(TEMP_SCRIPT))) + cp -f $(TEMP_SCRIPT) $(SCRIPT) + cp -f $(TEMP_MAP) $(SCRIPT_MAP) + $(TEMPLATE_COMMAND) $(INDEX_FILE) > $(UPLOAD_DIR)/index.html -$(UPLOAD_DIR)/%.css: %.css +$(UPLOAD_DIR)/%.css: %.css $(UPLOAD_DIR) cp "$<" "$@" $(UPLOAD_DIR): mkdir "$(UPLOAD_DIR)" +$(TEMP_DIR): + mkdir "$(TEMP_DIR)" + clean: @$(RM) -r $(UPLOAD_DIR) + @$(RM) -r $(TEMP_DIR) diff --git a/index.html b/index.html index e5a7b75..ae8fed7 100644 --- a/index.html +++ b/index.html @@ -9,10 +9,7 @@ - - - +