From eaceb1bfc3ad27d53bce83d4fcc10e7b39d33413 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrg=20Lehni?= <juerg@scratchdisk.com>
Date: Mon, 18 Jan 2016 01:18:57 +0100
Subject: [PATCH] Some more work on gulp

Change the way versions are handled, and append the branch name if we're not publishing from master.
---
 gulpfile.js    | 30 +++++++++++++++++++++++++++---
 src/load.js    |  5 +----
 src/options.js |  8 +-------
 src/paper.js   |  2 +-
 4 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index 2b9a6066..47de9e7a 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -22,7 +22,7 @@ var gulp = require('gulp'),
     merge = require('merge-stream'),
     del = require('del'),
     zip = require('gulp-zip'),
-    gitty = require('gitty')('.'),
+    gitty = require('gitty'),
     fs = require('fs');
 
 /**
@@ -54,6 +54,30 @@ var acornPath = 'bower_components/acorn/';
 var buildNames = Object.keys(buildOptions);
 var docNames = Object.keys(docOptions);
 
+/**
+ * Git
+ */
+
+var gitRepo = gitty('.');
+
+function git(param) {
+    var args = arguments.length === 1 ? param.split(' ') : [].slice.apply(arguments);
+    var operation = args.shift();
+    return new gitty.Command(gitRepo, operation, args).execSync().trim();
+}
+
+var gitDate = git('log -1 --pretty=format:%ad');
+var gitVersion = git('describe --abbrev=0 --tags');
+var gitBranch = git('rev-parse --abbrev-ref HEAD');
+if (gitBranch !== 'master')
+    gitVersion += '-' + gitBranch;
+
+gulp.task('nop');
+
+/**
+ * Task: default
+ */
+
 gulp.on('error', function(err) {
     console.error(err.toString());
     gulp.emit('end');
@@ -120,7 +144,6 @@ gulp.task('build',
 );
 
 // Get the date of the last commit from git.
-var gitLog = gitty.logSync('-1');
 buildNames.forEach(function(name) {
     gulp.task('build:' + name, ['build:start'], function() {
         return gulp.src('src/paper.js')
@@ -128,7 +151,8 @@ buildNames.forEach(function(name) {
                 evaluate: ['src/constants.js', 'src/options.js'],
                 setup: function() {
                     var options = buildOptions[name];
-                    options.date = gitLog[0].date;
+                    options.version = gitVersion;
+                    options.date = gitDate;
                     // This object will be merged into the Prepro.js VM scope,
                     // which already holds a __options object from the above
                     // include statement.
diff --git a/src/load.js b/src/load.js
index 01632223..8a0403ad 100644
--- a/src/load.js
+++ b/src/load.js
@@ -45,10 +45,7 @@ if (typeof window === 'object') {
         // This object will be merged into the Prepro.js VM scope, which already
         // holds a __options object from the above include statement.
         return {
-            __options: {
-                version: 'dev',
-                environment: 'node'
-            }
+            __options: { environment: 'node' }
         };
     });
     // Load Paper.js library files.
diff --git a/src/options.js b/src/options.js
index 756c0f11..47ee4f3a 100644
--- a/src/options.js
+++ b/src/options.js
@@ -14,14 +14,8 @@
 // browser based compile-time preprocessing when loading the separate source
 // files directly through load.js / Prepro.js during development.
 
-// The paper.js version.
-// NOTE: Adjust value here before calling publish.sh, which then updates and
-// publishes the various JSON package files automatically.
-var version = '0.9.25';
-
 var __options = {
-    // If this file is loaded in the browser, we're in dev mode through load.js
-    version: typeof window === 'object' ? 'dev' : version,
+    version: 'dev',
     environment: 'browser',
     parser: 'acorn',
     svg: true,
diff --git a/src/paper.js b/src/paper.js
index 035b9abc..d19d89e6 100644
--- a/src/paper.js
+++ b/src/paper.js
@@ -1,5 +1,5 @@
 /*!
- * Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting.
+ * Paper.js *#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting.
  * http://paperjs.org/
  *
  * Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey