From 4a3da30ebd673a4c0c3cb63aad5395ad2d32b87d Mon Sep 17 00:00:00 2001 From: Wouter R Date: Sat, 23 Apr 2016 17:36:35 +0200 Subject: [PATCH] Log git/version information in web console (#305). The information is dynamically inserted when grunt is run. --- .gitignore | 9 +----- .settings/com.eclipsesource.jshint.ui.prefs | 2 ++ Gruntfile.js | 32 ++++++++++++++++++++- js/main.js | 3 +- package.json | 6 ++-- 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .settings/com.eclipsesource.jshint.ui.prefs diff --git a/.gitignore b/.gitignore index 817405d..68d87cf 100644 --- a/.gitignore +++ b/.gitignore @@ -18,18 +18,11 @@ img/logo/logo_smaller.png img/logo/logo_smaller_8bit.png img/logo/logo_smaller_wide_8bit.png img/logo/logo_smallest.png -css/_backup20131010/* -css/_backup20131011/* d3d_btns.css -index.html.orig -js/Thermometer.js.orig -js/buttonbehaviors.js.orig -js/gcodeGenerating_v01.js.orig -js/init_layout backup20130918.js js/main.js.orig -js/previewRendering_v02.js.orig less/verticalshapes.css less/verticalshapes_backup.css __settings.html css/_settings.css node_modules/* +js/main.js.out diff --git a/.settings/com.eclipsesource.jshint.ui.prefs b/.settings/com.eclipsesource.jshint.ui.prefs new file mode 100644 index 0000000..1d1f2e4 --- /dev/null +++ b/.settings/com.eclipsesource.jshint.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +included=//*.js diff --git a/Gruntfile.js b/Gruntfile.js index 4a33db7..008b2b4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,6 +10,31 @@ module.exports = function(grunt) { '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', + gitinfo: { + options: {}, + commands: { 'tag': ['tag', '--points-at', 'HEAD'] } + }, + template: { + 'add_build_info': { + options: { + data: function() { + grunt.task.requires('gitinfo'); + var gi = grunt.config('gitinfo'); + var lbc = gi.local.branch.current; + + var tag = (gi.tag == '') ? 'no_tag' : gi.tag; + var commitMsg = lbc.lastCommitMessage.slice(1, -1).split('\n')[0].replace(/"/g, '\\\"'); + + var buildInfo = lbc.shortSHA + "/" + lbc.name + "/" + tag + + " (" + lbc.lastCommitTime.slice(1, -1) + "; \'" + commitMsg + "'"; + return { 'build_info': buildInfo }; + } + }, + files: { + 'js/main.js.out': ['js/main.js'] + } + } + }, concat: { options: { // separator: ';' @@ -22,7 +47,8 @@ module.exports = function(grunt) { 'js/*.js', // make sure we put main.js last '!js/main.js', - 'js/main.js', ], + 'js/main.js.out' + ], dest: 'www/js/<%= pkg.name %>.js' } }, @@ -129,6 +155,8 @@ module.exports = function(grunt) { }); // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-gitinfo'); + grunt.loadNpmTasks('grunt-template'); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); @@ -139,6 +167,8 @@ module.exports = function(grunt) { // Default task. grunt.registerTask('default', [ + 'gitinfo', + 'template', 'less', 'autoprefixer', 'cssmin', diff --git a/js/main.js b/js/main.js index b4d4dbc..5c49cb2 100644 --- a/js/main.js +++ b/js/main.js @@ -34,7 +34,8 @@ var POPUP_SHOW_DURATION = 175; var BUTTON_GROUP_SHOW_DURATION = 80; $(function() { - console.log("ready"); + console.log("Doodle3D client ready"); + console.log("Build information - <%= build_info %>)"); if (getURLParameter("d") != "null") debugMode = (getURLParameter("d") == "1"); if (getURLParameter("p") != "null") sendPrintCommands = (getURLParameter("p") == "1"); diff --git a/package.json b/package.json index 7a3b83f..bdf172d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "author": "Peter Uithoven, Adriaan Wormgoor, Rick Companje, Wouter Reckman", "readmeFilename": "README.md", "devDependencies": { - "grunt": "~0.4.1", + "grunt": "~0.4.5", "grunt-cli": "~0.1.9", "grunt-contrib-less": "~0.7.0", "grunt-contrib-watch": "~0.5.3", @@ -17,6 +17,8 @@ "grunt-contrib-jshint": "~0.6.4", "grunt-autoprefixer": "~0.4.0", "grunt-contrib-cssmin": "~0.6.2", - "grunt-contrib-concat": "~0.3.0" + "grunt-contrib-concat": "~0.3.0", + "grunt-gitinfo": "~0.1.7", + "grunt-template": "~0.2.3" } }