Use grunt-shell to retrieve git commit if not existent as environment variable

This commit is contained in:
Erjan Gavalji
2015-03-31 12:09:52 +03:00
parent a6837a82fe
commit 4987dc2ef0
2 changed files with 22 additions and 2 deletions

View File

@@ -63,9 +63,17 @@ module.exports = function(grunt) {
var getCommitSha = function() { var getCommitSha = function() {
if (process.env.GIT_COMMIT) { if (process.env.GIT_COMMIT) {
return process.env.GIT_COMMIT; return process.env.GIT_COMMIT;
}
return ""; return "";
}; };
var assignGitSHA = function(err, stdout, stderr, cb) {
if (!localCfg.commitSHA) {
localCfg.commitSHA = stdout.replace("\n", "");
}
cb();
};
var getPackageVersion = function() { var getPackageVersion = function() {
var buildVersion = process.env.PACKAGE_VERSION; var buildVersion = process.env.PACKAGE_VERSION;
if (!buildVersion) { if (!buildVersion) {
@@ -108,6 +116,7 @@ module.exports = function(grunt) {
"!./ui/slide-out/**/*.*" "!./ui/slide-out/**/*.*"
] ]
}; };
localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath); localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath);
localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath); localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath);
localCfg.commitSHA = getCommitSha(); localCfg.commitSHA = getCommitSha();
@@ -305,6 +314,14 @@ module.exports = function(grunt) {
return targetDirs; 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-exec");
grunt.loadNpmTasks("grunt-tslint"); grunt.loadNpmTasks("grunt-tslint");
grunt.loadNpmTasks("grunt-multi-dest"); grunt.loadNpmTasks("grunt-multi-dest");
grunt.loadNpmTasks("grunt-shell");
var cloneTasks = function(originalTasks, taskNameSuffix) 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([ grunt.registerTask("default", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([
"clean:build", "clean:build",
"shell:getGitSHA",
"collect-apps-raw-files", "collect-apps-raw-files",
"collect-definitions-raw-files", "collect-definitions-raw-files",

View File

@@ -3,8 +3,8 @@
"description": "Telerik NativeScript Core", "description": "Telerik NativeScript Core",
"version": "0.4.2", "version": "0.4.2",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/NativeScript/cross-platform-modules" "url": "https://github.com/NativeScript/cross-platform-modules"
}, },
"files": [ "files": [
"**/*.*", "**/*.*",
@@ -17,6 +17,7 @@
"grunt-contrib-copy": "0.5.0", "grunt-contrib-copy": "0.5.0",
"grunt-exec": "0.4.5", "grunt-exec": "0.4.5",
"grunt-multi-dest": "1.0.0", "grunt-multi-dest": "1.0.0",
"grunt-shell": "1.1.2",
"grunt-ts": "1.12.1", "grunt-ts": "1.12.1",
"grunt-tslint": "0.4.2", "grunt-tslint": "0.4.2",
"typescript": "1.4.1" "typescript": "1.4.1"