refactor: simplify file checks

This commit is contained in:
Carlos Valente
2024-07-02 18:01:51 +02:00
committed by Carlos Valente
parent 751c3329f0
commit 367997fd16
4 changed files with 41 additions and 45 deletions
@@ -1,4 +1,4 @@
import { ProjectFile } from 'ontime-types';
import { MaybeString, ProjectFile } from 'ontime-types';
import { access, rename, stat } from 'fs/promises';
import { join } from 'path';
@@ -51,13 +51,13 @@ export async function getProjectFiles(): Promise<ProjectFile[]> {
* Checks whether a project of a given name exists
* @param name
*/
export async function doesProjectExist(name: string): Promise<boolean> {
export async function doesProjectExist(name: string): Promise<MaybeString> {
try {
const projectFilePath = join(resolveProjectsDirectory, name);
const projectFilePath = getPathToProject(name);
await access(projectFilePath);
return true;
return projectFilePath;
} catch (_) {
return false;
return null;
}
}