ern-api-gen
Version:
Electrode Native API generator
50 lines • 2.45 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Rule_1 = require("./Rule");
const IgnoreToken_1 = __importDefault(require("./IgnoreToken"));
const Pattern_1 = __importDefault(require("../../java/Pattern"));
/**
* A special case rule which matches files only if they're located
* in the same directory as the .swagger-codegen-ignore file.
*/
class RootedFileRule extends Rule_1.Rule {
constructor(syntax, definition) {
super(syntax, definition);
this.definedFilename = null;
this.definedExtension = null;
const separatorIndex = definition.lastIndexOf('.');
this.definedFilename = this.getFilenamePart(definition, separatorIndex);
this.definedExtension = this.getExtensionPart(definition, separatorIndex);
}
getFilenamePart(input, stopIndex) {
return input.substring(input.charAt(0) === '/' ? 1 : 0, stopIndex > 0 ? stopIndex : input.length);
}
getExtensionPart(input, stopIndex) {
return input.substring(stopIndex > 0 ? stopIndex + 1 : input.length, input.length);
}
matches(relativePath) {
const isSingleFile = relativePath.lastIndexOf('/') <= 0;
if (isSingleFile) {
const separatorIndex = relativePath.lastIndexOf('.');
const filename = this.getFilenamePart(relativePath, separatorIndex);
const extension = this.getExtensionPart(relativePath, separatorIndex);
const extensionMatches = this.definedExtension === extension ||
this.definedExtension === IgnoreToken_1.default.MATCH_ANY.getPattern();
if (extensionMatches &&
this.definedFilename.indexOf(IgnoreToken_1.default.MATCH_ANY.getPattern()) !== -1) {
const regex = Pattern_1.default.compile(
/* replaceAll */ /* replaceAll */ this.definedFilename
.replace(new RegExp(Pattern_1.default.quote('.'), 'g'), '\\\\Q.\\\\E')
.replace(new RegExp(Pattern_1.default.quote('*'), 'g'), '.*?'));
return regex.matcher(filename).find();
}
return extensionMatches && this.definedFilename === filename;
}
return false;
}
}
exports.RootedFileRule = RootedFileRule;
//# sourceMappingURL=RootedFileRule.js.map