/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-standard-files"};ruleDef.prototype.getShortDescription=function(){return"Checks for the existence of standard informational files"};ruleDef.prototype.getDescription=function(){return"This rule ensures that standard files such as readmes are included"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){const componentMetadata=context.suppData.obj;if(componentMetadata){const fullName=Utils.getComponentFullName(componentMetadata);this._checkForStandardFiles(context,fullName,componentMetadata.version,componentMetadata.type)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkForStandardFiles(context,componentInfo.fullName,componentInfo.version,"composite")}};ruleDef.prototype._checkForStandardFiles=function(context,fullName,version,componentType){const componentFiles=context.utils.fsUtils.readDir(Utils.getDirectoryName(context.filepath));const checkForFiles=context.rulePack.getRuleCustomOption("files");checkForFiles.forEach(requiredFile=>{let exclusion=false;switch(requiredFile.toLowerCase()){case"changelog.md":case"changelog.txt":case"changes.txt":if(componentType&&componentType==="reference"){exclusion=true}else{if(version&&context.utils.semVerUtils.gt("1.0.1",version)){exclusion=true}}break}if(!exclusion){let hits=componentFiles.filter(compFile=>compFile.name===requiredFile&&compFile.isFile);if(hits.length===0){const issue=new context.Issue(`Required supporting file ${requiredFile} is not present for component ${fullName}`);context.reporter.addIssue(issue,context)}}})};module.exports=ruleDef;