|
- import * as fs from 'fs/promises';
- import * as path from 'path';
-
- export const searchForConfigFile = async () => {
- const filePath: string = path.resolve(process.cwd(), 'amanuensis.config.json');
-
- async function searchInDir(dirPath: string): Promise<string | null> {
- const configFile: string = path.join(dirPath, 'amanuensis.config.json');
- try {
- await fs.access(configFile, fs.constants.F_OK);
- return dirPath;
- } catch (err) {
- if (dirPath === path.dirname(dirPath)) {
- // Reached the root directory, config file not found
- return null;
- }
- const parentDir: string = path.dirname(dirPath);
- return searchInDir(parentDir);
- }
- }
-
- return searchInDir(filePath);
- };
|