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
|
2025-11-07 16:59:47 +00:00
|
|
|
* @param projectName
|
2025-11-02 17:39:34 +00:00
|
|
|
* @param projectRules
|
|
|
|
|
* @returns ProjectRule | null
|
|
|
|
|
*/
|
2025-11-07 16:59:47 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2025-11-07 16:59:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
}
|
2025-11-07 16:59:47 +00:00
|
|
|
const projectMatcherUtil = ProjectMatcherUtil.getInstance();
|
|
|
|
|
export default projectMatcherUtil;
|