* Load a file's content * * - Check if the file exists, if not found check * if the file exists with appending the extension * * Throws * - The provided file doesn't exit * - Any reading errors * * @param {String} filePath an absolute or a relative path * @param {String} extension *
(filePath, extension)
| 65 | * @return {String} |
| 66 | */ |
| 67 | function loadFile(filePath, extension) { |
| 68 | |
| 69 | var content = null; |
| 70 | |
| 71 | // Resolve the path into an absolute path |
| 72 | filePath = resolveFilePath(filePath, extension); |
| 73 | |
| 74 | // The file doesn't exist |
| 75 | if (!isFile(filePath)) { |
| 76 | throw new Error('The provided file doesn\'t exit'); |
| 77 | } |
| 78 | |
| 79 | // Read the file |
| 80 | try { |
| 81 | content = di.fs.readFileSync(filePath); |
| 82 | } catch (error) { |
| 83 | throw new Error(error); |
| 84 | } |
| 85 | |
| 86 | return content; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Check, load, and parse YAML files |
no test coverage detected