1 | var fs = require('fs'),
|
2 | path = require('path');
|
3 |
|
4 | var existsSync = fs.existsSync || path.existsSync;
|
5 |
|
6 | var projectPath = path.resolve(__dirname, '../../'),
|
7 | filePath = path.join(__dirname, 'files'),
|
8 | pcPath = path.join(projectPath, '.git', 'hooks', 'pre-commit'),
|
9 | jsiPath = path.join(projectPath, '.jshintignore'),
|
10 | jsrcPath = path.join(projectPath, '.jshintrc');
|
11 |
|
12 | if (existsSync(path.join(projectPath, '.git'))) {
|
13 | if (existsSync(pcPath)) fs.unlinkSync(pcPath);
|
14 | if (!existsSync(path.dirname(pcPath))) fs.mkdirSync(path.dirname(pcPath));
|
15 | console.log('Found .git directory, adding pre-commit hook');
|
16 | var pcHook = fs.readFileSync(path.join(filePath, 'pre-commit'));
|
17 | fs.writeFileSync(pcPath, pcHook);
|
18 | fs.chmodSync(pcPath, '755');
|
19 | }
|
20 |
|
21 | if (!existsSync(jsiPath)) {
|
22 | console.log('Did not find a .jshintignore, creating one');
|
23 | var jsiFile = fs.readFileSync(path.join(filePath, 'jshintignore'));
|
24 | fs.writeFileSync(jsiPath, jsiFile);
|
25 | }
|
26 |
|
27 | if (!existsSync(jsrcPath)) {
|
28 | console.log('Did not find a .jshintrc, creating one');
|
29 | var jsrcFile = fs.readFileSync(path.join(filePath, 'jshintrc'));
|
30 | fs.writeFileSync(jsrcPath, jsrcFile);
|
31 | }
|