mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
add env var for setting file (#147)
Co-authored-by: Xu, Guoxu | Terry | CNTD <guoxu.xu@rakuten.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user