Modify the rule of output directory.

@param  {Object} rule The rule.
@param  {string} type The output directory type.
496371
function modifyOutRule(rule, type) {
	rule.test = new RegExp(
		'\\.(' + Config.out[type].extensions.join('|') + ')$'
	);
}
1222803
private function rebuildRule($type, $parameters)
    {
        // Rebuild rule
        $rule = $type;

        if (is_array($parameters) && count($parameters)) $rule .= ':' . implode(',', $parameters);
        else $rule .= ':' . $parameters;

        // Remove any trailing colons we have from rules without parameters
        return trim($rule, ':');
    }
404070
function (type) {
      var exec = [];

      switch (type || this.configs["publish"]) {
        case "EPUB":
          this.publishEPUB(exec);
          break;
        case "LATEX":
          this.publishLatex(exec);
          break;
        case "HTML":
          this.publishHTML(exec);
        default:
          break;
      }
      return exec;
    }
1034183
function setRule (rule, isDefault) {
    // clear id for existing rules
    this.id = undefined
    // if this is default rule then add to list
    if (isDefault) {
        this.defaultRules.push(_.cloneDeep(rule))
    }
    // capture original rule as string for error logging
    var origRule = rule.join(',')
    // require array
    assert.ok(Array.isArray(rule), 'rule array required')
    // get roles array
    var roles = rule
    // get rule string from last element in array
    rule = roles.pop()
    // require rule to be a string
    assert.ok(typeof rule === 'string', 'invalid rule '+origRule)
    // require at least one role
    assert.ok(roles.length, 'one or more roles required '+origRule)
    // split rule on colon to separate into clauses
    var ruleClauses = rule.split(':')
    // first clause must identify type of resource
    var resourceType = ruleClauses.shift()
    // get index of last element in rule
    var lastIdx = ruleClauses.length - 1
    // final element in rule must be 1 or 0 to indicate allow or deny
    var allow = parseInt(ruleClauses[lastIdx])
    // validate
    assert.ok(allow === 0 || allow === 1, 'allow must be 0 or 1 '+origRule)
    // set value to boolean
    ruleClauses[lastIdx] = allow
    // deny rule only allowed on all role
    if (allow === 0) {
        assert.ok(roles.length === 1 && roles[0] === 'all', 'deny can only be set for all role '+origRule)
    }
    // require valid resource type
    assert.ok(resourceTypes[resourceType], 'invalid resource type '+origRule)
    // create entry from resource type if it does not exist
    if (!this.rules[resourceType]) {
        this.rules[resourceType] = {}
    }
    // call type specific method to set rule
    resourceTypes[resourceType](roles, ruleClauses, this.rules[resourceType], origRule)
}
1204503
def on_rule_prototype(node, compiled_grammar)
      name = process(node.children[0], compiled_grammar)

      return if compiled_grammar.has_rule?(name)

      rule = Rule.new(name, node.source_line)

      compiled_grammar.add_rule(rule)
    end
708568
private void addRuleFiles(List<RuleSource> sources, File directory) throws MojoExecutionException {
        List<RuleSource> ruleSources = readRulesDirectory(directory);
        for (RuleSource ruleSource : ruleSources) {
            getLog().debug("Adding rules from file " + ruleSource);
            sources.add(ruleSource);
        }
    }
209743
function(rule, callback){
        var res = [];
        callback = callback || function(){};
        this.each(function(item){
            var pass = true;
            if(pass && rule.group != undefined){
                pass = rule.group == item.parent;
            }
            if(pass && rule.type != undefined){
                pass = rule.type == item.type;
            }
            if(item.type == 'ip'){
                if(pass && rule.ip != undefined){
                    pass = rule.ip == item.ip;
                }
                if(pass && rule.domain != undefined){
                    pass = rule.domain == item.domain;
                }
                if(pass && rule.enable != undefined){
                    pass = rule.enable == item.enable;
                }
                if(pass && rule.comment != undefined){
                    pass = rule.comment == item.comment;
                }
            }else if(item.type == 'text'){
                if(pass && rule.text != undefined){
                    pass = rule.text == item.text;
                }
            }
            if(pass){
                callback.call(item, item);
                res.push(item);
            }
        });
        return res;
    }
952461
def _addRule(self, isWhitelist, rule):
    """"""
    if isinstance(rule, six.string_types) or hasattr(rule, '__call__'):
      self.rules.append((isWhitelist, rule))
    else:
      raise TypeError('Graphite logging rules must be glob pattern or callable. Invalid: %r' % rule)
776564
function ImageLinter(ruleFilePath) {
    if (!ruleFilePath) logger.info("No rule file provided, using default rules");
    this.rules = loadRules(ruleFilePath);
    this.context = {
        rules: this.rules,
        validInstructionsRegex: helper.createValidCommandRegex(this.rules.general.valid_instructions),
        requiredInstructions: helper.createReqInstructionHash(this.rules),
        requiredNameVals: helper.createRequiredNameValDict(this.rules)
    };
    helper.initLineRulesRegexes(this.rules);
}
66628
function (env) {
        var css = [],      // The CSS output
            rules = [],    // node.Rule instances
           _rules = [],    //
            rulesets = [], // node.Ruleset instances
            selector,      // The fully rendered selector
            debugInfo,     // Line number debugging
            rule;

        // Compile rules and rulesets
        for (var i = 0; i < this.rules.length; i++) {
            rule = this.rules[i];

            if (rule.rules || (rule instanceof tree.Media)) {
                rulesets.push(rule.toCSS(env));
            } else if (rule instanceof tree.Directive) {
                var cssValue = rule.toCSS(env);
                // Output only the first @charset definition as such - convert the others
                // to comments in case debug is enabled
                if (rule.name === "@charset") {
                    // Only output the debug info together with subsequent @charset definitions
                    // a comment (or @media statement) before the actual @charset directive would
                    // be considered illegal css as it has to be on the first line
                    if (env.charset) {
                        if (rule.debugInfo) {
                            rulesets.push(tree.debugInfo(env, rule));
                            rulesets.push(new tree.Comment("/* "+cssValue.replace(/\n/g, "")+" */\n").toCSS(env));
                        }
                        continue;
                    }
                    env.charset = true;
                }
                rulesets.push(cssValue);
            } else if (rule instanceof tree.Comment) {
                if (!rule.silent) {
                    if (this.root) {
                        rulesets.push(rule.toCSS(env));
                    } else {
                        rules.push(rule.toCSS(env));
                    }
                }
            } else {
                if (rule.toCSS && !rule.variable) {
                    if (this.firstRoot && rule instanceof tree.Rule) {
                        throw { message: "properties must be inside selector blocks, they cannot be in the root.",
                            index: rule.index, filename: rule.currentFileInfo ? rule.currentFileInfo.filename : null};
                    }
                    rules.push(rule.toCSS(env));
                } else if (rule.value && !rule.variable) {
                    rules.push(rule.value.toString());
                }
            }
        } 

        // Remove last semicolon
        if (env.compress && rules.length) {
            rule = rules[rules.length - 1];
            if (rule.charAt(rule.length - 1) === ';') {
                rules[rules.length - 1] = rule.substring(0, rule.length - 1);
            }
        }

        rulesets = rulesets.join('');

        // If this is the root node, we don't render
        // a selector, or {}.
        // Otherwise, only output if this ruleset has rules.
        if (this.root) {
            css.push(rules.join(env.compress ? '' : '\n'));
        } else {
            if (rules.length > 0) {
                debugInfo = tree.debugInfo(env, this);
                selector = this.paths.map(function (p) {
                    return p.map(function (s) {
                        return s.toCSS(env);
                    }).join('').trim();
                }).join(env.compress ? ',' : ',\n');

                // Remove duplicates
                for (var i = rules.length - 1; i >= 0; i--) {
                    if (rules[i].slice(0, 2) === "/*" ||  _rules.indexOf(rules[i]) === -1) {
                        _rules.unshift(rules[i]);
                    }
                }
                rules = _rules;

                css.push(debugInfo + selector + 
                        (env.compress ? '{' : ' {\n  ') +
                        rules.join(env.compress ? '' : '\n  ') +
                        (env.compress ? '}' : '\n}\n'));
            }
        }
        css.push(rulesets);

        return css.join('')  + (env.compress ? '\n' : '');
    }
1110179
function WPPackage(directory, type) {
  if (!(this instanceof WPPackage)) {
    return new WPPackage(directory, type);
  }

  this.directory = null;
  this.domainPath = null;
  this.mainFile = null;
  this.potFile = null;
  this.type = 'wp-plugin';

  this.initialize(directory, type);
}
205161
function (id, rule) {
  if (!rules.hasOwnProperty(id)) {
    rules[id] = {
      id: id,

      nud: void 0, // Maybe< Fn(State, Token) >

      lbp: 0,
      led: void 0, // Maybe< Fn(State, Token, left: Tree) >

      sta: void 0, // Maybe< Fn(State) >

      type_nud: void 0, // Maybe< Fn(State, Token) >
      type_lbp: 0,
      type_led: void 0// Maybe< Fn(State, Token, left: Tree) >
    }
  }
  if (rule.nud) {
    rules[id].nud = rule.nud
  }
  if (rule.led && rule.lbp > 0) {
    rules[id].lbp = rule.lbp
    rules[id].led = rule.led
  }
  if (rule.sta) {
    rules[id].sta = rule.sta
  }
  if (rule.type_nud) {
    rules[id].type_nud = rule.type_nud
  }
  if (rule.type_led && rule.type_lbp > 0) {
    rules[id].type_lbp = rule.type_lbp
    rules[id].type_led = rule.type_led
  }
}
1193407
function createOutputFolder(next) {
    var defPath         = path.join(getConfig('output.folder'), 'definition-files'),
        defPathCustom   = path.join(getConfig('output.folder'), 'definition-files-custom');

    fs.remove(defPath, function (err) {
        if (err) { next(err); }
        fs.createFile(path.join(defPath, '_Dont_add_or_edit_any_files'), function (err) {
            if (err) { next(err); }
            fs.mkdirs(defPathCustom, function (err) {
                if (err) { next(err); }
                next(null);
            });
        });
    });
}
130532
function writeFile(input, output, type) {
    var json    = readFile(input),
        content = getContent(json, type);

    fs.writeFile(output, content, function (err) {
        if (err) {
            throw err;
        }

        console.log('The file "' + output + '" was written successfully!');
    });
}
578848
private void changeDirectoryPermissions(String dir, String mode, 
                                              boolean isRecursive) {
    int ret = 0;
    try {
      ret = FileUtil.chmod(dir, mode, isRecursive);
    } catch (Exception e) {
      LOG.warn("Exception in changing permissions for directory " + dir + 
                  ". Exception: " + e.getMessage());
    }
    if (ret != 0) {
      LOG.warn("Could not change permissions for directory " + dir);
    }
  }
1353019
function completeOutput(outputCSS = '') {


		if (OPTIONS.css_output !== '') {
			// console.log(outputCSS)


			//write output
			try {
				if (OPTIONS.format_4095_rules_legacy_limit) {
					// console.log(summary.stats.after.noRules)
					var noOutputFilesNeeded = Math.ceil(summary.stats.after.noRules / 4095);
					// console.log(noOutputFilesNeeded)
					

					if (noOutputFilesNeeded == 1) {

						outputCSS = trimCSS(outputCSS);
						outputCSS = restoreHacks(outputCSS);
						write(OPTIONS.css_output, outputCSS);
						filesizeKB = getFilesizeInKiloBytes(OPTIONS.css_output);
					} else { //group 4095 rules

						try {
							var ast = css.parse(outputCSS, { source: fileLocation });
						} catch(err) {
							console.log(error("CSS Parser2 Error: probably have something funny in your CSS, change it then please try again."));
							console.log('Reason: ' + err.reason);
							console.log('Line: ' + err.line);
							console.log('Column: ' + err.column);
							console.log('Filename: ' + err.filename);
							process.exit(1);
						}

						var rulesGroups = [];
						var rulesGroupsLen = 0;
						var rules = ast.stylesheet.rules;
						var ruleslen = rules.length;
						var ruleCount = 0;
						var groupCount = 0;

						for (i = 0; i < ruleslen; ++i) {

							if (rulesGroups[groupCount] === undefined) {
								rulesGroups[groupCount] = [];
							}
							rulesGroups[groupCount].push(rules[i]);
							ruleCount += 1;

							if (ruleCount == 4095) {
								groupCount += 1;
							}
						}
						rulesGroupsLen = rulesGroups.length;
						filesizeKB = 0;
						outputFilename = '';
						for (i = 0; i < rulesGroupsLen; i++) {

							outputAST = {
								type: 'stylesheet',
								stylesheet: {
									rules: rulesGroups[i]
								}
							};
							outputCSS = css.stringify(outputAST);

							outputCSS = trimCSS(outputCSS);
							outputCSS = restoreHacks(outputCSS);
							outputFilename = OPTIONS.css_output.substr(0, OPTIONS.css_output.length-4) + '_' + i + '.css';
							write(outputFilename, outputCSS);

							filesizeKB += getFilesizeInKiloBytes(outputFilename);
						}
					}
					
				} else {
					outputCSS = trimCSS(outputCSS);
					outputCSS = restoreHacks(outputCSS);
					if (OPTIONS.css_output === null || OPTIONS.css_output === undefined || OPTIONS.css_output == '') {
						var size = kiloByteLength(outputCSS);
						filesizeKB = size/1000;
					} else {
						write(OPTIONS.css_output, outputCSS);
						filesizeKB = getFilesizeInKiloBytes(OPTIONS.css_output);
					}
				}
				
			} catch(e) {
				console.log(error("Output file error: Something went wrong while writing the file, check your folder permissions, config_css.json and please try again."));
				console.log(e);
				process.exit(1);
			}

		} else {
			outputCSS = trimCSS(outputCSS);
			outputCSS = restoreHacks(outputCSS);
			filesizeKB = kiloByteLength(outputCSS);
		}

		summary.stats.after.totalFileSizeKB += filesizeKB;
		summary.stats.summary.savingsKB = roundTo(summary.stats.before.totalFileSizeKB - summary.stats.after.totalFileSizeKB, 4);
		summary.stats.summary.savingsPercentage = roundTo(summary.stats.summary.savingsKB / summary.stats.before.totalFileSizeKB * 100, 2);

		//write report
		if (OPTIONS.generate_report) {

			try {
				var cssdata = JSON.stringify(summary, null, '\t');
				write(REPORT_DUPLICATE_CSS, JSON.stringify(summary, null, '\t'));
			} catch(e) {
				console.log(error("Report output file error: Something went wrong while writing the file, check your folder permissions, config_css.json and please try again."));
				console.log(e);
				process.exit(1);
			}
		}

		if (OPTIONS.verbose) {

			console.log(cool('Before: ' + summary.stats.before.totalFileSizeKB + 'KB'));
			console.log(cool('After: ' + summary.stats.after.totalFileSizeKB + 'KB'));
			console.log(cool('Saved: ' + summary.stats.summary.savingsKB + 'KB (' + summary.stats.summary.savingsPercentage + '%)'));

			console.timeEnd(logoRed("Purged " + timeLabel + " in "));
		}

		if (OPTIONS.css_output === null || OPTIONS.css_output === undefined || OPTIONS.css_output == '') {
			return outputCSS;
		} else {

			// console.log(OPTIONS.css_output);
			
		}
	}
84454
protected function createDirectory($type)
    {
        if(is_array($directories = $this->getDirOption(true))) {
            $function = 'get' . ucfirst($type) . 'Directory';
            $directory_array = [];
            $directory_paths = [];
            if($directories) {
                foreach($directories as $directory) {
                    array_push($directory_array, $directory);
                    array_push($directory_paths, implode('/', $directory_array));
                    if($directory_paths) {
                        foreach($directory_paths as $directory_path) {
                            if( ! $this->files->isDirectory($this->{$function}() . $directory_path)) {
                                $this->files->makeDirectory($this->{$function}() . $directory_path);
                            }
                        }
                    }
                }
            }
        }
    }