A tool which could get the dirpath of a function method’s caller
1
npm install caller-dir
Usually, if you want to get the current path, you can use __dirname in Nodejs, if you want to get the caller’s dirpath, you can call the function with a parameter which is __dirname, but it’s not graceful.
Now you can use this little tool caller-dir to get the caller’s dirpath gracefully.
var exec = require('child_process').exec; var spawn = require('child_process').spawn;
var gitEmail = spawn('git', ['config', 'user.email']); gitEmail.stdout.on('data', function (data) { var email = firstLineFromBuffer(data); var commitMsgFile = process.argv[2];
fs.readFile( commitMsgFile, function (err, buffer) { var message = firstLineFromBuffer(buffer);
// 公钥 var FD_f1342fFDFdsaf = 'MIGfMA0GCSqGSIb3DQfdsafdsafdsDCBiQKBgQDkAh06uqqrA8qIsyd98/E1p4oL0GAzUifdsafdsaOZpCwAdrh+I77Ws14u2UJWz4cBNnZBnS5hX/kWeUizGkPbW2AfdsafdsakuFfdsafdsanTJUQIDAQAB'; var encrypt = newJSEncrypt(); encrypt.setPublicKey(FD_f1342fFDFdsaf); returnfunction(opt) { var form = this; var beforeSubmit = opt.beforeSubmit; opt.beforeSubmit = function(fields) { var result = beforeSubmit && beforeSubmit.apply(this, arguments);