]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Add Popcorn.version with test.
authorDavid Humphrey <david.humphrey@senecac.on.ca>
Fri, 23 Sep 2011 15:24:30 +0000 (11:24 -0400)
committerDavid Humphrey <david.humphrey@senecac.on.ca>
Fri, 23 Sep 2011 15:24:30 +0000 (11:24 -0400)
Makefile
popcorn.js
test/popcorn.unit.js

index 519466185c5c64c3beacdd59a66e0736ff16d89e..f5c06826ec59a80d67c6bb5d76aad979ab590e74 100644 (file)
--- 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..."
index fa99b4e747e7cff432fa6067d003ad137c4a6a32..2cdd16a8b32bc095a584122fff95cc6d8e9a349d 100644 (file)
@@ -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 = [];
 
index 5a6f18e9f49c6994ea9e228850e7f4d87d65bc77..7ea4a844cc8c33f2b5fbee5f5eefce68fe38f7d7 100644 (file)
@@ -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,