* Returns a task's source file path after making sure it is either a valid JS * file or a valid dir. * @param {string} taskSourceFileName * @return {string}
(taskSourceFileName)
| 135 | * @return {string} |
| 136 | */ |
| 137 | function getTaskSourceFilePath(taskSourceFileName) { |
| 138 | const tasksDir = path.join(__dirname, '..', 'tasks'); |
| 139 | const taskSourceFilePath = path.join(tasksDir, taskSourceFileName); |
| 140 | const isValidSourceFilePath = |
| 141 | fs.pathExistsSync(`${taskSourceFilePath}.js`) || // Task lives in a JS file. |
| 142 | fs.pathExistsSync(taskSourceFilePath); // Task lives in a directory. |
| 143 | if (!isValidSourceFilePath) { |
| 144 | handleInvalidTaskError(taskSourceFileName); |
| 145 | } |
| 146 | return taskSourceFilePath; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns a task function after making sure it is valid. |
no test coverage detected