/*
 * 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 RULE=["/**","  * 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/","  */","","/*--------------------------------------------------------------------------------*/","/*   JAF Rule:  '%r'                                                              */","/*   Purpose :                                                                    */","/*--------------------------------------------------------------------------------*/","","","const RULENAME          = \"%s\";","const DESCRIPTION       = \"long description/help - can include HTML markup\";","const SHORT_DESCRIPTION = \"short description\";","","class Rule {","   getName()  {","       return RULENAME;","   }","","   getDescription()  {","       return DESCRIPTION;","   }","","   getShortDescription()  {","       return SHORT_DESCRIPTION;","   }","","   /**","     * Registration - declare listeners","     * @param {Object}   regCtx  the registration context","     */","   register( /*regCtx*/ )  {","       // register listener(s)","       // return { xxx : this._onXXX }","   }","","   /**","     *","     * @param {Object}   ruleCtx  the rule context","     */","   _onXXX(ruleCtx) {","       // implement rule listener(s)","   }","","}","","","","module.exports = Rule;"];const LOGO=["      __      ___","  __ / /___ _/ _/   Rule '"+"%r"+"'"," / // // _ `/ _/    Created successfully"," \\___/ \\_,_/_/\n"];const JS=".js";const PC_R="%r";const PC_S="%s";function genRule(dir,ruleName,nd,fsUtils){var np=nd.path;var ext=np.extname(ruleName);var rule,fp,text;if(ext===""){rule=ruleName}else if(ext.toLowerCase()!==JS){console.log("[error]: invalid rule file extension '"+ext+"'.  Do not specify a file extension!");return true}else{rule=ruleName.substring(0,ruleName.length-3)}ruleName=rule+JS;fp=np.join(dir,ruleName);try{if(fsUtils.fileExists(fp)){console.log("[Warning]: Rule '"+ruleName+"' already exists. ojaf will not overwrite it!");return true}text=_updateText(text,rule);nd.fs.writeFileSync(fp,text);_logo(rule);return true}catch(e){console.log("[Error]: "+e)}return false};function _updateText(text,rule){var i;text=RULE.join("\n").replace(PC_S,rule);i=text.indexOf(PC_R);text=text.replace(PC_R,"  ");return _insertText(text,i,rule)};function _insertText(text,i,rule){return text.substring(0,i)+rule+"'"+text.substring(i+1+rule.length)};function _logo(rule){console.log(LOGO.join("\n").replace("%r",rule))}module.exports.genRule=genRule;