diff --git a/Makefile b/Makefile index 519466185..f5c06826e 100644 --- a/Makefile +++ b/Makefile @@ -87,9 +87,14 @@ POPCORN_COMPLETE_LIST := --js ${POPCORN_SRC} \ POPCORN_COMPLETE_DIST = ${DIST_DIR}/popcorn-complete.js POPCORN_COMPLETE_MIN = ${DIST_DIR}/popcorn-complete.min.js -# Create a versioned license header for js files we ship: arg1=source arg2=dest -add_license = cat ${PREFIX}/LICENSE_HEADER | sed -e 's/@VERSION/${VERSION}/' > $(2) ; \ - cat $(1) >> $(2) +# Create a versioned license header for js files we ship +add_license = cat $(PREFIX)/LICENSE_HEADER | sed -e 's/@VERSION/${VERSION}/' > $(1).__hdr__ ; \ + cat $(1).__hdr__ $(1) >> $(1).__tmp__ ; rm -f $(1).__hdr__ ; \ + mv $(1).__tmp__ $(1) + +# Create a version parameter for Popcorn +add_version = cat $(1) | sed -e 's/@VERSION/${VERSION}/' > $(1).__tmp__ ; \ + mv $(1).__tmp__ $(1) # Run the file through jslint run_lint = @@$(RHINO) build/jslint-check.js $(1) @@ -104,23 +109,25 @@ ${DIST_DIR}: popcorn: ${POPCORN_DIST} -${POPCORN_DIST}: ${POPCORN_SRC} | ${DIST_DIR} - @@echo "Building" ${POPCORN_DIST} - @@$(call add_license, $(POPCORN_SRC), $(POPCORN_DIST)) +${POPCORN_DIST}: $(POPCORN_SRC) | $(DIST_DIR) + @@echo "Building" $(POPCORN_DIST) + @@cp $(POPCORN_SRC) $(POPCORN_DIST) + @@$(call add_license, $(POPCORN_DIST)) + @@$(call add_version, $(POPCORN_DIST)) min: ${POPCORN_MIN} ${MODULES_MIN} ${PLUGINS_MIN} ${PARSERS_MIN} ${PLAYERS_MIN} $(EFFECTS_MIN) ${POPCORN_COMPLETE_MIN} ${POPCORN_MIN}: ${POPCORN_DIST} @@echo "Building" ${POPCORN_MIN} - @@$(call compile, --js ${POPCORN_DIST}, ${POPCORN_MIN}.tmp) - @@$(call add_license, ${POPCORN_MIN}.tmp, ${POPCORN_MIN}) - @@rm ${POPCORN_MIN}.tmp + @@$(call compile, --js $(POPCORN_DIST), $(POPCORN_MIN)) + @@$(call add_license, $(POPCORN_MIN)) + @@$(call add_version, $(POPCORN_MIN)) ${POPCORN_COMPLETE_MIN}: update ${POPCORN_SRC} ${MODULES_SRC} ${PLUGINS_SRC} ${PARSERS_SRC} $(EFFECTS_SRC) ${DIST_DIR} @@echo "Building" ${POPCORN_COMPLETE_MIN} - @@$(call compile, ${POPCORN_COMPLETE_LIST}, ${POPCORN_COMPLETE_MIN}.tmp) - @@$(call add_license, ${POPCORN_COMPLETE_MIN}.tmp, ${POPCORN_COMPLETE_MIN}) - @@rm ${POPCORN_COMPLETE_MIN}.tmp + @@$(call compile, $(POPCORN_COMPLETE_LIST), $(POPCORN_COMPLETE_MIN)) + @@$(call add_license, $(POPCORN_COMPLETE_MIN)) + @@$(call add_version, $(POPCORN_COMPLETE_MIN)) modules: ${MODULES_DIST} @@ -174,9 +181,9 @@ $(EFFECTS_DIST): $(EFFECTS_SRC) $(DIST_DIR) complete: update ${POPCORN_SRC} ${MODULES_SRC} ${PARSERS_SRC} ${PLUGINS_SRC} ${PLAYERS_SRC} $(EFFECTS_SRC) ${DIST_DIR} @@echo "Building popcorn + modules + plugins + parsers + players + effects..." - @@cat ${POPCORN_SRC} ${MODULES_SRC} ${PLUGINS_SRC} ${PARSERS_SRC} ${PLAYERS_SRC} $(EFFECTS_SRC) > ${POPCORN_COMPLETE_DIST}.tmp - @@$(call add_license, ${POPCORN_COMPLETE_DIST}.tmp, ${POPCORN_COMPLETE_DIST}) - @@rm ${POPCORN_COMPLETE_DIST}.tmp + @@cat ${POPCORN_SRC} ${MODULES_SRC} ${PLUGINS_SRC} ${PARSERS_SRC} ${PLAYERS_SRC} $(EFFECTS_SRC) > $(POPCORN_COMPLETE_DIST) + @@$(call add_license, $(POPCORN_COMPLETE_DIST)) + @@$(call add_version, $(POPCORN_COMPLETE_DIST)) lint: @@echo "Checking Popcorn against JSLint..." diff --git a/popcorn.js b/popcorn.js index fa99b4e74..2cdd16a8b 100644 --- a/popcorn.js +++ b/popcorn.js @@ -60,6 +60,9 @@ return new Popcorn.p.init( entity, options || null ); }; + // Popcorn API version, automatically inserted via build system. + Popcorn.version = "@VERSION"; + // Instance caching Popcorn.instances = []; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 5a6f18e9f..7ea4a844c 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -92,6 +92,15 @@ test("Popcorn.forEach", function() { equal(count, Popcorn.sizeOf(object), Popcorn.sizeOf(object) + " properties in object"); }); +test("Popcorn.version", function() { + // We can't know the version itself, but we can make sure that we get a string. + // Popcorn.version should give something like "1.0.1" or a git sha "9a3e67" or + // the string "@VERSION" if it hasn't yet been replaced. + expect(1); + + equal(typeof Popcorn.version, "string", "Popcorn.version exists and returns a string"); +}); + test("Popcorn.util.toSeconds" , function() { var framerate = 24, storedStartTime,