-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgetFolderInPath.js
More file actions
34 lines (27 loc) · 843 Bytes
/
getFolderInPath.js
File metadata and controls
34 lines (27 loc) · 843 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
34
'use strict'
const fs = require('fs')
const path = require('path')
const resolve = path.resolve
const exists = path.existsSync || fs.existsSync
// Function to recursively finding a folder
function getFolderInPath (folder, path) {
const result = resolve(path, folder)
if (!exists(result)) {
console.log('pre-commit:')
console.log('pre-commit: Not found ' + folder + ' folder in', result)
const newPath = resolve(path, '..')
// Stop if we on top folder
if (path === newPath) {
return null
}
return getFolderInPath(folder, newPath)
}
if (fs.lstatSync(result).isDirectory()) {
console.log('pre-commit:')
console.log('pre-commit: Found ' + folder + ' folder in', result)
return result
}
return null
}
module.exports = getFolderInPath
module.exports.getFolderInPath = getFolderInPath