Skip to content

Commit dfcc820

Browse files
committed
Merge branch 'ErjanGavalji/add-sha-info'
2 parents 753ee11 + 16f7047 commit dfcc820

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

gruntfile.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = function(grunt) {
2323
var updateModulesPackageDef = function(content, srcPath) {
2424
return updatePackageDef(content, function(contentAsObject) {
2525
contentAsObject.version = localCfg.packageVersion;
26+
if (localCfg.commitSHA) {
27+
contentAsObject.repository.url += "/commit/" + localCfg.commitSHA;
28+
}
2629
});
2730
};
2831

@@ -33,6 +36,15 @@ module.exports = function(grunt) {
3336
contentAsObject.name = "tns-samples-" + currentAppName;
3437
contentAsObject.description = "Nativescript " + currentAppName + " sample application";
3538
contentAsObject.license = "BSD";
39+
if (!contentAsObject.repository) {
40+
contentAsObject.repository = {};
41+
}
42+
if (!contentAsObject.repository.url) {
43+
contentAsObject.repository.url = localCfg.mainPackageContent.repository.url;
44+
}
45+
if (localCfg.commitSHA) {
46+
contentAsObject.repository.url += "/commit/" + localCfg.commitSHA;
47+
}
3648
});
3749
};
3850

@@ -42,16 +54,32 @@ module.exports = function(grunt) {
4254
contentAsObject.name = "tns-definitions";
4355
contentAsObject.description = "NativeScript Module definitions";
4456
contentAsObject.license = "Apache-2.0";
57+
if (localCfg.commitSHA) {
58+
contentAsObject.repository.url += "/commit/" + localCfg.commitSHA;
59+
}
4560
});
46-
}
61+
};
62+
63+
var getCommitSha = function() {
64+
if (process.env.GIT_COMMIT) {
65+
return process.env.GIT_COMMIT;
66+
}
67+
return "";
68+
};
4769

48-
var getPackageVersion = function(packageFilePath) {
49-
packageContent = grunt.file.readJSON(packageFilePath);
70+
var assignGitSHA = function(err, stdout, stderr, cb) {
71+
if (!localCfg.commitSHA) {
72+
localCfg.commitSHA = stdout.replace("\n", "");
73+
}
74+
cb();
75+
};
76+
77+
var getPackageVersion = function() {
5078
var buildVersion = process.env.PACKAGE_VERSION;
5179
if (!buildVersion) {
52-
return packageContent.version;
80+
return localCfg.mainPackageContent.version;
5381
}
54-
return packageContent.version + "-" + buildVersion;
82+
return localCfg.mainPackageContent.version + "-" + buildVersion;
5583
};
5684

5785
var processAppFile = function(content, srcPath) {
@@ -88,7 +116,10 @@ module.exports = function(grunt) {
88116
"!./ui/slide-out/**/*.*"
89117
]
90118
};
119+
120+
localCfg.mainPackageContent = grunt.file.readJSON(localCfg.packageJsonFilePath);
91121
localCfg.packageVersion = getPackageVersion(localCfg.packageJsonFilePath);
122+
localCfg.commitSHA = getCommitSha();
92123
localCfg.defaultExcludes = [
93124
"!" + localCfg.outDir + "/**/*.*",
94125
"!./node_modules/**/*.*",
@@ -283,6 +314,14 @@ module.exports = function(grunt) {
283314
return targetDirs;
284315
}()
285316
}
317+
},
318+
shell: {
319+
getGitSHA: {
320+
command: "git rev-parse HEAD",
321+
options: {
322+
callback: assignGitSHA
323+
}
324+
}
286325
}
287326
});
288327

@@ -292,6 +331,7 @@ module.exports = function(grunt) {
292331
grunt.loadNpmTasks("grunt-exec");
293332
grunt.loadNpmTasks("grunt-tslint");
294333
grunt.loadNpmTasks("grunt-multi-dest");
334+
grunt.loadNpmTasks("grunt-shell");
295335

296336
var cloneTasks = function(originalTasks, taskNameSuffix)
297337
{
@@ -403,6 +443,7 @@ module.exports = function(grunt) {
403443

404444
grunt.registerTask("default", ((typeof(grunt.option('runtslint')) != "undefined" && !grunt.option('runtslint')) ? [] : ["tslint:build"]).concat([
405445
"clean:build",
446+
"shell:getGitSHA",
406447

407448
"collect-apps-raw-files",
408449
"collect-definitions-raw-files",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "tns-core",
33
"description": "Telerik NativeScript Core",
44
"version": "0.4.2",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/NativeScript/cross-platform-modules"
8+
},
59
"files": [
610
"**/*.*",
711
"**/*"
@@ -13,6 +17,7 @@
1317
"grunt-contrib-copy": "0.5.0",
1418
"grunt-exec": "0.4.5",
1519
"grunt-multi-dest": "1.0.0",
20+
"grunt-shell": "1.1.2",
1621
"grunt-ts": "1.12.1",
1722
"grunt-tslint": "0.4.2",
1823
"typescript": "1.4.1"

0 commit comments

Comments
 (0)