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 pathinstall.js
More file actions
Latest commit
47 lines (41 loc) · 2.14 KB
/
Copy pathinstall.js
File metadata and controls
47 lines (41 loc) · 2.14 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
varfs=require('fs');
varpath=require('path');
varexistsSync=fs.existsSync||path.existsSync;
varprojectPath=path.resolve(__dirname,'../../../');
varpackagePath=path.join(projectPath,'package.json');
varprojectName=path.basename(projectPath);
varfilePath=path.join(__dirname,'files');
vargitPath=path.join(projectPath,'.git');
varpcPath=path.join(gitPath,'hooks','pre-commit');
varjsiPath=path.join(projectPath,'.jshintignore');
varjsrcPath=path.join(projectPath,'.jshintrc');
varpcModulePath=path.join(projectPath,'../','.git','modules',projectName,'hooks');
if(existsSync(gitPath)){
varstats=fs.lstatSync(path.join(projectPath,'.git'));
if(stats.isDirectory()){
if(existsSync(pcPath))fs.unlinkSync(pcPath);
if(!existsSync(path.dirname(pcPath)))fs.mkdirSync(path.dirname(pcPath));
console.log('Found .git directory, adding pre-commit hook');
varpcHook=fs.readFileSync(path.join(filePath,'pre-commit'));
fs.writeFileSync(pcPath,pcHook);
fs.chmodSync(pcPath,'755');
}
}elseif(existsSync(pcModulePath)){
console.log('Found submodule .git directory, adding pre-commit hook');
varpcHook=fs.readFileSync(path.join(filePath,'pre-commit'));
varpcModuleFullPath=path.join(pcModulePath,'pre-commit');
fs.writeFileSync(pcModuleFullPath,pcHook);
fs.chmodSync(pcModuleFullPath,'755');
}else{
console.error('This project doesn\'t appear to be a git repository. JSHint configuration will be created anyway. To enable the pre-commit hook, run `git init` and reinstall precommit-hook.');
}
if(!existsSync(jsiPath)){
console.log('Did not find a .jshintignore, creating one');
varjsiFile=fs.readFileSync(path.join(filePath,'jshintignore'));
fs.writeFileSync(jsiPath,jsiFile);
}
if(!existsSync(jsrcPath)&&(!existsSync(packagePath)||!require(packagePath).hasOwnProperty('jshintConfig'))){
console.log('Did not find a .jshintrc and package.json does not contain jshintConfig, creating .jshintrc');
varjsrcFile=fs.readFileSync(path.join(filePath,'jshintrc'));
fs.writeFileSync(jsrcPath,jsrcFile);
}