From 4987dc2ef07dac082fb13941a0acc4f30044398c Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 31 Mar 2015 12:09:52 +0300 Subject: [PATCH] Use grunt-shell to retrieve git commit if not existent as environment variable --- gruntfile.js | 19 +++++++++++++++++++ package.json | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index d5f922271..f6430a073 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -63,9 +63,17 @@ module.exports = function(grunt) { var getCommitSha = function() { if (process.env.GIT_COMMIT) { return process.env.GIT_COMMIT; + } return ""; }; + var assignGitSHA = function(err, stdout, stderr, cb) { + if (!localCfg.commitSHA) { + localCfg.commitSHA = stdout.replace("\n", ""); + } + cb(); + }; + var getPackageVersion = function() { var buildVersion = process.env.PACKAGE_VERSION; if (!buildVersion) { @@ -108,6 +116,7 @@ module.exports = function(grunt) { "!./ui/slide-out/**/*.*" ] }; + localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath); localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath); localCfg.commitSHA = getCommitSha(); @@ -305,6 +314,14 @@ module.exports = function(grunt) { return targetDirs; }() } + }, + shell: { + getGitSHA: { + command: "git rev-parse HEAD", + options: { + callback: assignGitSHA + } + } } }); @@ -314,6 +331,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-exec"); grunt.loadNpmTasks("grunt-tslint"); grunt.loadNpmTasks("grunt-multi-dest"); + grunt.loadNpmTasks("grunt-shell"); var cloneTasks = function(originalTasks, taskNameSuffix) { @@ -425,6 +443,7 @@ module.exports = function(grunt) { grunt.registerTask("default", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([ "clean:build", + "shell:getGitSHA", "collect-apps-raw-files", "collect-definitions-raw-files", diff --git a/package.json b/package.json index 6ea8db87b..c67ed0e22 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "description": "Telerik NativeScript Core", "version": "0.4.2", "repository": { - "type": "git", - "url": "https://github.com/NativeScript/cross-platform-modules" + "type": "git", + "url": "https://github.com/NativeScript/cross-platform-modules" }, "files": [ "**/*.*", @@ -17,6 +17,7 @@ "grunt-contrib-copy": "0.5.0", "grunt-exec": "0.4.5", "grunt-multi-dest": "1.0.0", + "grunt-shell": "1.1.2", "grunt-ts": "1.12.1", "grunt-tslint": "0.4.2", "typescript": "1.4.1"