Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

24 lines
690 B

  1. import * as fs from 'fs/promises';
  2. import * as path from 'path';
  3. export const searchForConfigFile = async () => {
  4. const filePath: string = path.resolve(process.cwd(), 'amanuensis.config.json');
  5. async function searchInDir(dirPath: string): Promise<string | null> {
  6. const configFile: string = path.join(dirPath, 'amanuensis.config.json');
  7. try {
  8. await fs.access(configFile, fs.constants.F_OK);
  9. return dirPath;
  10. } catch (err) {
  11. if (dirPath === path.dirname(dirPath)) {
  12. // Reached the root directory, config file not found
  13. return null;
  14. }
  15. const parentDir: string = path.dirname(dirPath);
  16. return searchInDir(parentDir);
  17. }
  18. }
  19. return searchInDir(filePath);
  20. };