Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add commit hash check

  • Loading branch information...
commit e099b4546809b433e5843735d880a16199a5215f 1 parent 20ebab6
@carlos8f carlos8f authored
Showing with 26 additions and 5 deletions.
  1. +13 −5 index.js
  2. +13 −0 lib/commit-hash.js
View
18 index.js
@@ -2,6 +2,7 @@ var npm = require('npm')
, sha1 = require('./lib/sha1')
, readJson = require('read-package-json')
, path = require('path')
+ , commithash = require('./lib/commit-hash')
function list (str) {
return str.split(/ *, */).map(function (val) {
@@ -52,14 +53,21 @@ program
var name = data.name
, version = data.version
- npm.load(function (err) {
+ commithash(program.root, function (err, commit) {
ifErr(err);
- npm.commands.cache(['add', program.root], function (err) {
+ npm.load(function (err) {
ifErr(err);
- var file = path.join(npm.cache, name, version, 'package.tgz');
- sha1.get(file, function (err, sha1sum) {
+ npm.commands.cache(['add', program.root], function (err) {
ifErr(err);
- console.log('cached project with sha1 sum: ' + sha1sum);
+ var file = path.join(npm.cache, name, version, 'package.tgz');
+ sha1.get(file, function (err, sha1sum) {
+ ifErr(err);
+ console.log('deployed project at ' + program.root);
+ console.log('sha1 sum: ' + sha1sum);
+ if (commit) {
+ console.log('git hash: ' + commit);
+ }
+ });
});
});
});
View
13 lib/commit-hash.js
@@ -0,0 +1,13 @@
+var fs = require('fs')
+ , path = require('path')
+ , exec = require('child_process').exec
+
+module.exports = function (dir, cb) {
+ fs.exists(path.join(dir, '.git'), function (exists) {
+ if (!exists) return cb();
+ exec('git log -n1 --pretty=oneline', {cwd: dir}, function (err, stdout, stderr) {
+ if (err) return cb(err);
+ cb(null, stdout.split(/\s+/)[0]);
+ });
+ });
+};
Please sign in to comment.
Something went wrong with that request. Please try again.