-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathget-folder-in-path.js
More file actions
33 lines (26 loc) · 806 Bytes
/
get-folder-in-path.js
File metadata and controls
33 lines (26 loc) · 806 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
'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, logger) {
const result = resolve(path, folder)
if (!exists(result)) {
logger.log('pre-commit:')
logger.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, logger)
}
if (fs.lstatSync(result).isDirectory()) {
logger.log('pre-commit:')
logger.log('pre-commit: Found ' + folder + ' folder in', result)
return result
}
return null
}
module.exports = getFolderInPath