Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | 1x 1x 1x 1x 1x 125x 125x 125x 125x 125x 125x 125x 2x 1x 259x 1x 20x 7x 1x 8x 4x 4x 4x 4x 4x 4x 8x 1x 20x 20x 8x 20x 1x 259x 1x 11x 10x 8x 8x 8x 2x 1x 1x 2x 2x 2x 12x 12x 12x 4x 4x 2x 2x 2x 1x 1x | import { existsSync, readFileSync } from "fs";
import { extname } from "path";
import stripJsonComments = require("strip-json-comments");
import { Logger } from "./Logger";
/**
* Function for comparing version strings of since-tags
* to determine if the passed in tagged version is in range
* of the passed in latest version
*/
declare type VersionComparatorFunction = (taggedVersion: string, latestVersion: string) => boolean;
export class Configuration {
/**
* Indicates wether to skip since tag check or not
*/
public ignoreSinceTag: boolean;
/**
* Logs every item which is ignored by the since tag
*/
public logItemsSkippedBySince: boolean;
/**
* Ignores undocumented items
*/
public skipUndocumented: boolean;
private _ignoreScopes: string[];
private _latestVersion: string;
private _versionComparator: VersionComparatorFunction;
constructor(filePath?: string) {
this._ignoreScopes = [];
this._versionComparator = this.defaultVersionComparator;
this._latestVersion = "";
this.skipUndocumented = true;
this.ignoreSinceTag = false;
this.logItemsSkippedBySince = true;
if (filePath) {
this.loadFromFile(filePath);
}
}
/**
* Scopes to ignore
*/
public get ignoreScopes(): string[] {
return this._ignoreScopes;
}
public set ignoreScopes(val: string[]) {
this._ignoreScopes = val;
}
/**
* Latest version tag for the version comparator function
*/
public get latestVersion(): string {
return this._latestVersion;
}
public set latestVersion(value: string) {
this._latestVersion = value;
}
public set versionComparator(value: VersionComparatorFunction | string) {
// Its possible to pass the version comparator via the jsdoc config
// either as function string or as a file path to a js-file which
// the version comparator function
let newVersionComparator: VersionComparatorFunction;
if (typeof value === "string") {
const versionComparatorAsString: string = value;
Iif (versionComparatorAsString.indexOf("{") > 0) {
// Version comparator is a function string
newVersionComparator = this.parseVersionComparatorFromString(value);
} else Eif (existsSync(value)) {
// Version comparator is a file path
Eif (extname(value) === ".js") {
newVersionComparator = require(value);
} else {
throw new Error(`Invalud version comparator: ${value}. Version comparator must be a JavaScript file.`);
}
} else {
throw new Error(`Version comparator must contain a valid path or a valid function as string, got ${value}`);
}
} else {
newVersionComparator = value;
}
this._versionComparator = newVersionComparator;
}
/**
* Determines if the tagged version is in range of the latest version
* using the provided version comparator
* @param taggedVersion Current version tag
* @param latestVersion Latest version tag from config
*/
public compareVersions(taggedVersion: string, latestVersion: string, itemName: string): boolean {
const isItemInRange = this.ignoreSinceTag || this._versionComparator(taggedVersion, latestVersion);
if (!isItemInRange && this.logItemsSkippedBySince) {
Logger.log(`Skipping item ${itemName} because it's since tag (${taggedVersion}) is less then the latest tag (${latestVersion})`);
}
return isItemInRange;
}
public ignoreScope(scope: string): boolean {
return this.ignoreScopes.indexOf(scope) > -1;
}
/**
* Determines if the tagged version is in range of the latest version
* by using semver-tags
* @param taggedVersion Current version tag
* @param latestVersion Latest version tag from config
*/
private defaultVersionComparator(taggedVersion: string, latestVersion: string): boolean {
if (taggedVersion.match(/v?([0-9]+\.){2}[0-9]+/i)) {
if (typeof latestVersion === "string" && latestVersion.match(/v?([0-9]+\.){2}[0-9]+/i)) {
const compare = require("node-version-compare");
const result = compare(latestVersion, taggedVersion);
return result >= 0;
} else {
return true;
}
} else {
return false;
}
}
private loadFromFile(filePath: string) {
const jsonString = readFileSync(filePath, { encoding: "utf-8" });
const configObj = JSON.parse(stripJsonComments(jsonString));
// quick and dirty iterate over public config properties
const _config = new Configuration();
for (let property of Object.keys(_config)) {
// setters latestVersion and versionComparator not in Object.keys()
property = property.startsWith("_") ? property.slice(1) : property;
if (configObj.hasOwnProperty(property)) {
const privateProp = "_" + property;
if (property === "versionComparator") {
this.versionComparator = configObj[property];
} else Eif (this.hasOwnProperty(privateProp)) {
// @ts-ignore
this[privateProp] = configObj[property];
} else {
// @ts-ignore
this[property] = configObj[property];
}
}
}
}
private parseVersionComparatorFromString(versionComparatorAsString: string): VersionComparatorFunction {
let functionBody = versionComparatorAsString.substr(versionComparatorAsString.indexOf("{") + 1);
functionBody = functionBody.substr(0, functionBody.length - 1).trim();
// @ts-ignore
return new Function("param1", "param2", functionBody);
}
}
|