-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get internalPaths for perfectionis dynamically
- Loading branch information
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function getFile(path = process.cwd(), fileName) { | ||
if (!fileName) { | ||
throw new Error('No fileName provided') | ||
} | ||
if (path === '/' || path === '') { | ||
throw new Error(`No ${fileName} found`) | ||
} | ||
try { | ||
return require(`${path}/${fileName}`) | ||
} catch (e) { | ||
const parentPath = path.split('/').slice(0, -1).join('/') | ||
return getFile(parentPath, fileName) | ||
} | ||
} | ||
|
||
function getFilePath(path = process.cwd(), fileName) { | ||
if (!fileName) { | ||
throw new Error('No fileName provided') | ||
} | ||
if (path === '/' || path === '') { | ||
throw new Error(`No ${fileName} found`) | ||
} | ||
try { | ||
const filePath = `${path}/${fileName}` | ||
require(filePath) | ||
return filePath | ||
} catch (e) { | ||
const parentPath = path.split('/').slice(0, -1).join('/') | ||
return getFilePath(parentPath, fileName) | ||
} | ||
} | ||
|
||
module.exports = { | ||
getFile, | ||
getFilePath, | ||
} |