Uh oh!
There was an error while loading. Please reload this page.
forked from nlf/precommit-hook
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
Latest commit
33 lines (26 loc) · 851 Bytes
/
Copy pathutils.js
File metadata and controls
33 lines (26 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
varpath=require('path');
varexec=require('child_process').exec;
// use git rev-parse to find the .git directory
exports.findGitRoot=function(callback){
exec('git rev-parse --show-toplevel',function(err,stderr){
if(err){
returncallback(err);
}
callback(null,stderr.trim());
});
};
// traverse from this module's directory upwards until you find
// the project root, which is the first directory
// *not* named node_modules
exports.findProjectRoot=function(base){
base=base||__dirname;
vardir=path.resolve(base,'..');
if(path.basename(dir)!=='node_modules'){
returndir;
}
returnexports.findProjectRoot(dir);
};
exports.findPackageJson=function(){
vardir=exports.findProjectRoot();
returnpath.join(dir,'package.json');
};