Skip to content

Commit

Permalink
Support config directory detection
Browse files Browse the repository at this point in the history
  • Loading branch information
icodesign committed Aug 30, 2024
1 parent 17f954d commit a61078b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,39 @@ export type Config = z.infer<typeof BaseConfigSchema>;
export async function parseConfig(userConfigPath?: string): Promise<Config> {
var configPath = userConfigPath;
if (!configPath) {
// search dolphin.y[a]ml under root path
// check if the file exists
const searchFiles = ['dolphin.yml', 'dolphin.yaml'];
const rootPath = process.cwd();
throw new Error(
`Missing config file. You can either set using --config or put dolphin.y[a]ml under the root path of the project.`,
);
}
if (!path.isAbsolute(configPath)) {
configPath = path.join(process.cwd(), configPath);
}
// Check if configPath is a directory
const stats = await fs.promises.stat(configPath);
if (stats.isDirectory()) {
logger.info(
`No config file provided. Searching config file (dolphin.y[a]ml) under current directory(${rootPath})...`,
`No yaml config file provided. Searching config file (dolphin.y[a]ml) under the directory(${configPath})...`,
);
const searchFiles = ['dolphin.yml', 'dolphin.yaml'];
let found = false;
for (const file of searchFiles) {
const attemptConfigPath = path.join(rootPath, file);
const attemptConfigPath = path.join(configPath, file);
try {
await fs.promises.access(attemptConfigPath);
configPath = attemptConfigPath;
found = true;
break;
} catch (error) {
continue;
}
}
if (!found) {
throw new Error(
`No dolphin.y[a]ml found in the specified directory: ${configPath}`,
);
}
}
if (!configPath) {
throw new Error(
`Missing config file. You can either set using --config or put dolphin.y[a]ml under the root path of the project.`,
);
}
if (!path.isAbsolute(configPath)) {
configPath = path.join(process.cwd(), configPath);
}

logger.info(`Using config file at ${configPath}`);
let fileContent;
try {
Expand Down

0 comments on commit a61078b

Please sign in to comment.