chore: support config path being specified via command line argument
This commit is contained in:
		
							parent
							
								
									dabca46e88
								
							
						
					
					
						commit
						78d08599a5
					
				@ -1,13 +1,13 @@
 | 
				
			|||||||
// First, init config.
 | 
					// First, init config.
 | 
				
			||||||
import { config, loadConfig } from "@/src/services/configService";
 | 
					import { config, configPath, loadConfig } from "@/src/services/configService";
 | 
				
			||||||
import fs from "fs";
 | 
					import fs from "fs";
 | 
				
			||||||
try {
 | 
					try {
 | 
				
			||||||
    loadConfig();
 | 
					    loadConfig();
 | 
				
			||||||
} catch (e) {
 | 
					} catch (e) {
 | 
				
			||||||
    if (fs.existsSync("config.json")) {
 | 
					    if (fs.existsSync("config.json")) {
 | 
				
			||||||
        console.log("Failed to load config.json: " + (e as Error).message);
 | 
					        console.log("Failed to load " + configPath + ": " + (e as Error).message);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        console.log("Failed to load config.json. You can copy config.json.example to create your config.json.");
 | 
					        console.log("Failed to load " + configPath + ". You can copy config.json.example to create your config file.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    process.exit(1);
 | 
					    process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -72,7 +72,7 @@ export interface IConfig {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const configPath = path.join(repoDir, "config.json");
 | 
					export const configPath = path.join(repoDir, process.argv[2] ?? "config.json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const config: IConfig = {
 | 
					export const config: IConfig = {
 | 
				
			||||||
    mongodbUrl: "mongodb://127.0.0.1:27017/openWF",
 | 
					    mongodbUrl: "mongodb://127.0.0.1:27017/openWF",
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ fs.watchFile(configPath, () => {
 | 
				
			|||||||
    if (amnesia) {
 | 
					    if (amnesia) {
 | 
				
			||||||
        amnesia = false;
 | 
					        amnesia = false;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        logger.info("Detected a change to config.json, reloading its contents.");
 | 
					        logger.info("Detected a change to config file, reloading its contents.");
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            loadConfig();
 | 
					            loadConfig();
 | 
				
			||||||
        } catch (e) {
 | 
					        } catch (e) {
 | 
				
			||||||
@ -41,7 +41,7 @@ export const validateConfig = (): void => {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (modified) {
 | 
					    if (modified) {
 | 
				
			||||||
        logger.info(`Updating config.json to fix some issues with it.`);
 | 
					        logger.info(`Updating config file to fix some issues with it.`);
 | 
				
			||||||
        void saveConfig();
 | 
					        void saveConfig();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user