UNPKG

maestro-cli-roku

Version:

command line tools for maestro-roku projects

134 lines (133 loc) 4.41 kB
"use strict"; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); function spliceString(str, index, add) { // We cannot pass negative indexes directly to the 2nd slicing operation. if (index < 0) { index = str.length + index; if (index < 0) { index = 0; } } return str.slice(0, index) + (add || '') + str.slice(index + (add || '').length); } exports.spliceString = spliceString; function getRegexMatchesValues(input, regex, groupIndex) { var values = []; var matches; regex.lastIndex = 0; while (matches = regex.exec(input)) { values.push(matches[groupIndex]); } return values; } exports.getRegexMatchesValues = getRegexMatchesValues; function getRegexMatchValue(input, regex, groupIndex) { var matches; while (matches = regex.exec(input)) { if (matches.length > groupIndex) { return matches[groupIndex]; } } return null; } exports.getRegexMatchValue = getRegexMatchValue; function addSetItems(setA, setB) { var e_1, _a; try { for (var setB_1 = __values(setB), setB_1_1 = setB_1.next(); !setB_1_1.done; setB_1_1 = setB_1.next()) { var elem = setB_1_1.value; setA.add(elem); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (setB_1_1 && !setB_1_1.done && (_a = setB_1.return)) _a.call(setB_1); } finally { if (e_1) throw e_1.error; } } } exports.addSetItems = addSetItems; function pad(pad, str, padLeft) { if (typeof str === 'undefined') { return pad; } if (padLeft) { return (pad + str).slice(-pad.length); } else { return (str + pad).substring(0, pad.length); } } exports.pad = pad; /** * Given an absollute path to a source file, and a target path, * compute the pkg path for the target relative to the source file's location * @param containingFilePathAbsolute * @param targetPath * * Note - lifted straight from Bronley Plumb's brightscript-language utisl : thanks Bron :) */ function getPkgPathFromTarget(containingFilePathAbsolute, targetPath) { var e_2, _a; //if the target starts with 'pkg:', it's an absolute path. Return as is if (targetPath.indexOf('pkg:/') === 0) { targetPath = targetPath.substring(5); if (targetPath === '') { return null; } else { return path.normalize(targetPath); } } if (targetPath === 'pkg:') { return null; } //remove the filename var containingFolder = path.normalize(path.dirname(containingFilePathAbsolute)); //start with the containing folder, split by slash var result = containingFolder.split(path.sep); //split on slash var targetParts = path.normalize(targetPath).split(path.sep); try { for (var targetParts_1 = __values(targetParts), targetParts_1_1 = targetParts_1.next(); !targetParts_1_1.done; targetParts_1_1 = targetParts_1.next()) { var part = targetParts_1_1.value; if (part === '' || part === '.') { //do nothing, it means current directory continue; } if (part === '..') { //go up one directory result.pop(); } else { result.push(part); } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (targetParts_1_1 && !targetParts_1_1.done && (_a = targetParts_1.return)) _a.call(targetParts_1); } finally { if (e_2) throw e_2.error; } } return result.join(path.sep); } exports.getPkgPathFromTarget = getPkgPathFromTarget; function escapeRegExp(text) { return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } exports.escapeRegExp = escapeRegExp;