UNPKG

@appium/typedoc-plugin-appium

Version:

TypeDoc plugin for Appium & its extensions

127 lines 5.65 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _ExtensionReflection_alias, _ExtensionReflection_title; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtensionReflection = void 0; const lodash_1 = __importDefault(require("lodash")); const typedoc_1 = require("typedoc"); const converter_1 = require("../../converter"); const kind_1 = require("./kind"); const SCOPED_PACKAGE_NAME_REGEX = /^(@[^/]+)\/([^/]+)$/; /** * A reflection containing data about commands and/or execute methods. * * Methods may be invoked directly by Handlebars templates. */ class ExtensionReflection extends typedoc_1.DeclarationReflection { /** * * @param name Name of module containing commands * @param parent Module containing commands * @param moduleCommands Data containing commands and execute methods * @param title Title if provided in options * @todo Determine the kind by inspecting `package.json` or smth */ constructor(name, parent, moduleCommands, title) { const { routeMap, execMethodDataSet } = moduleCommands; const kind = (name.includes('driver') ? kind_1.AppiumPluginReflectionKind.Driver : name.includes('plugin') ? kind_1.AppiumPluginReflectionKind.Plugin : kind_1.AppiumPluginReflectionKind.Extension); super(name, kind, parent); this.hasOwnDocument = true; /** * Cached value of {@linkcode ExtensionReflection.getAlias} */ _ExtensionReflection_alias.set(this, void 0); _ExtensionReflection_title.set(this, void 0); this.parent = parent; this.routeMap = routeMap; this.execMethodDataSet = execMethodDataSet; __classPrivateFieldSet(this, _ExtensionReflection_title, title, "f"); } /** * This is called by `AppiumTheme`'s `getUrl` method, which causes a particular filename to be used. * * - The name of an `ExtensionReflection` is the name of the module containing commands * - If that name is a _scoped package name_, we strip the scope and delimiter * - Replaces any non-alphanumeric characters with `-` * @returns The "alias", whatever that means */ getAlias() { if (__classPrivateFieldGet(this, _ExtensionReflection_alias, "f")) { return __classPrivateFieldGet(this, _ExtensionReflection_alias, "f"); } let alias; const matches = this.name.match(SCOPED_PACKAGE_NAME_REGEX); alias = matches ? matches[2] : this.name; alias = alias.replace(/\W/, '-'); __classPrivateFieldSet(this, _ExtensionReflection_alias, alias, "f"); return alias; } /** * Returns the title for display. Used as the first-level header for rendered page. */ get extensionTitle() { if (__classPrivateFieldGet(this, _ExtensionReflection_title, "f")) { return __classPrivateFieldGet(this, _ExtensionReflection_title, "f"); } if (ExtensionReflection.isCompositeProject(this.project)) { return `${this.name} Commands`; } return 'Commands'; } /** * Returns number of execute methods in this data */ get execMethodCount() { return this.execMethodDataSet.size; } /** * Returns `true` if there are any "execute commands" in this set. * * Used by templates */ get hasExecuteMethod() { return Boolean(this.execMethodCount); } /** * Returns `true` if there are any "regular" commands in this set. * * Used by templates */ get hasRoute() { return Boolean(this.routeCount); } /** * Returns number of routes ("commands") in this in this data */ get routeCount() { return this.routeMap.size; } } _ExtensionReflection_alias = new WeakMap(), _ExtensionReflection_title = new WeakMap(); /** * Returns `true` if the project contains more than one `ExtensionReflection` that isn't built-in commands. * * Should **not** be called before the TypeDoc converter has emitted `EVENT_RESOLVE_END` */ ExtensionReflection.isCompositeProject = lodash_1.default.memoize((project) => project .getChildrenByKind(kind_1.AppiumPluginReflectionKind.Extension) ?.filter(({ name }) => name !== converter_1.NAME_BUILTIN_COMMAND_MODULE).length > 1); exports.ExtensionReflection = ExtensionReflection; //# sourceMappingURL=extension.js.map