UNPKG

ern-api-gen

Version:

Electrode Native API generator

102 lines 3.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const DirectoryRule_1 = require("./rules/DirectoryRule"); const create_1 = __importDefault(require("./rules/create")); const File_1 = __importDefault(require("../java/File")); const LoggerFactory_1 = __importDefault(require("../java/LoggerFactory")); const Rule_1 = require("./rules/Rule"); const fs_1 = __importDefault(require("fs")); const { Operation } = Rule_1.Rule; class CodegenIgnoreProcessor { constructor(outputPath) { this.exclusionRules = []; this.inclusionRules = []; this.outputPath = outputPath; const directory = new File_1.default(outputPath); if (directory.exists() && directory.isDirectory()) { const codegenIgnore = new File_1.default(directory, CodegenIgnoreProcessor.IGNORE_FILE); if (codegenIgnore.exists() && codegenIgnore.isFile()) { try { this.loadCodegenRules(codegenIgnore.getAbsolutePath()); } catch (e) { Log.error('Could not process .swagger-codegen-ignore.', e.message); } } else { Log.info('No .swagger-codegen-ignore file found.'); } } } loadCodegenRules(codegenIgnore) { const lines = fs_1.default.readFileSync(codegenIgnore, 'utf8').split('\n'); for (const line of lines) { if (line.trim().length === 0) { continue; } const rule = create_1.default(line); if (rule != null) { if (rule.getNegated()) { this.inclusionRules.push(rule); } else { this.exclusionRules.push(rule); } } } } allowsFile(targetFile) { if (this.exclusionRules.length === 0 && this.inclusionRules.length === 0) { return true; } const file = new File_1.default(this.outputPath, targetFile).relativeTo(this.outputPath); let directoryExcluded = false; let exclude = false; EXCLUDE: for (const current of this.exclusionRules) { const op = current.evaluate(file.getPath()); switch (op) { case Operation.EXCLUDE: exclude = true; if (current != null && current instanceof DirectoryRule_1.DirectoryRule) { directoryExcluded = true; } break; case Operation.INCLUDE: break; case Operation.NOOP: break; case Operation.EXCLUDE_AND_TERMINATE: break EXCLUDE; } } if (exclude) { for (const current of this.inclusionRules) { const op = current.evaluate(file.getPath()); if (op === Rule_1.Rule.Operation.INCLUDE) { if (current != null && current instanceof DirectoryRule_1.DirectoryRule && directoryExcluded) { exclude = false; } else if (!directoryExcluded) { exclude = false; } } } } return !exclude; } getInclusionRules() { return this.inclusionRules.concat(); } getExclusionRules() { return this.exclusionRules.concat(); } } CodegenIgnoreProcessor.IGNORE_FILE = '.swagger-codegen-ignore'; exports.default = CodegenIgnoreProcessor; const Log = LoggerFactory_1.default.getLogger(CodegenIgnoreProcessor); //# sourceMappingURL=CodegenIgnoreProcessor.js.map