add env var for setting file (#147)

Co-authored-by: Xu, Guoxu | Terry | CNTD <guoxu.xu@rakuten.com>
This commit is contained in:
terrydash
2025-05-31 00:01:52 +09:00
committed by GitHub
parent 80c6aae116
commit 63c55875b5

View File

@@ -16,8 +16,9 @@ const rootDir = dirname(dirname(__dirname));
* @returns The path to the file
*/
export const getConfigFilePath = (filename: string, description = 'Configuration'): string => {
// Try to find the correct path to the file
const envPath = process.env.MCPHUB_SETTING_PATH;
const potentialPaths = [
...(envPath ? [envPath] : []),
// Prioritize process.cwd() as the first location to check
path.resolve(process.cwd(), filename),
// Use path relative to the root directory
@@ -25,13 +26,13 @@ export const getConfigFilePath = (filename: string, description = 'Configuration
// If installed with npx, may need to look one level up
path.join(dirname(rootDir), filename)
];
for (const filePath of potentialPaths) {
if (fs.existsSync(filePath)) {
return filePath;
}
}
// If all paths do not exist, use default path
// Using the default path is acceptable because it ensures the application can proceed
// even if the configuration file is missing. This fallback is particularly useful in