al0cam_AutoMover/Utils/ProjectMatcherUtil.ts

49 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2025-11-02 17:39:34 +00:00
import { ProjectRule } from "Models/ProjectRule";
class ProjectMatcherUtil {
private static instance: ProjectMatcherUtil;
private constructor() {}
public static getInstance(): ProjectMatcherUtil {
if (!ProjectMatcherUtil.instance) {
ProjectMatcherUtil.instance = new ProjectMatcherUtil();
}
return ProjectMatcherUtil.instance;
}
/**
* Returns the first project rule that matches the file
* If no rule matches, returns null
* @param projectName
2025-11-02 17:39:34 +00:00
* @param projectRules
* @returns ProjectRule | null
*/
public getMatchingProjectRule(projectName: string, projectRules: ProjectRule[]): ProjectRule | null {
for (const projectRule of projectRules) {
if (projectRule.projectName === projectName) {
return projectRule;
2025-11-02 17:39:34 +00:00
}
}
return null;
}
/**
* Prepends the project folder to the destination path
* and checks whether the project folder ends with a slash
*
* @param projectRule
* @param subPath
* @returns string
*/
public constructProjectDestinationPath(projectRule: ProjectRule, subPath: string): string {
let projectFolder = projectRule.folder;
if (!projectFolder.endsWith("/")) {
projectFolder += "/";
}
return projectFolder + subPath;
}
2025-11-02 17:39:34 +00:00
}
const projectMatcherUtil = ProjectMatcherUtil.getInstance();
export default projectMatcherUtil;