UNPKG

@rbnx/webdriverio

Version:

webdriverio plugin for nx

42 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readPropertyFromConfig = void 0; const typescript_1 = require("typescript"); function readPropertyFromConfig(tree, config, prop) { if (tree.exists(config)) { const source = (0, typescript_1.createSourceFile)(config, tree.read(config, 'utf-8'), typescript_1.ScriptTarget.Latest, true); const propNode = findNodes(source, typescript_1.SyntaxKind.PropertyAssignment) .filter((node) => node.getText().startsWith(prop)) .shift(); return findNodes(propNode, typescript_1.SyntaxKind.StringLiteral).map((node) => node.getText().replace(/['"]/g, '')); } } exports.readPropertyFromConfig = readPropertyFromConfig; function findNodes(node, kind, max = Infinity) { if (!node || max == 0) { return []; } const nodes = []; const match = Array.isArray(kind) ? kind.includes(node.kind) : node.kind === kind; if (match) { nodes.push(node); max--; } if (max > 0) { for (const child of node.getChildren()) { findNodes(child, kind, max).forEach((node) => { if (max > 0) { nodes.push(node); } max--; }); if (max <= 0) { break; } } } return nodes; } //# sourceMappingURL=config.js.map